Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to R Console will be documented in this file.

## [0.4.2] - 2026-07-15

### Added

- Added a dedicated `R Console Language Server` output channel that reports server starts, stops, errors and the R executable location, without showing language-server protocol traffic.

## [0.4.1] - 2026-07-11

### Added
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vsc-r-console",
"displayName": "R Console for VS Code",
"description": "A lightweight R console for VS Code",
"version": "0.4.1",
"version": "0.4.2",
"publisher": "RConsole",
"license": "SEE LICENSE IN LICENSE",
"icon": "images/Rlogo.png",
Expand Down
69 changes: 66 additions & 3 deletions src/Language/consoleLspClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ import {
import type { CompletionProvider } from "./completion";

const CONSOLE_LSP_HOST = "127.0.0.1";
const lifecycleOutputChannel = vscode.window.createOutputChannel(
"R Console Language Server"
);

function formatLogTimestamp(date = new Date()): string {
const pad = (value: number): string => String(value).padStart(2, "0");
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ` +
`${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
}

export function disposeConsoleLspOutputChannel(): void {
lifecycleOutputChannel.dispose();
}

type ConsoleLspClientOptions = {
consoleId: string;
Expand Down Expand Up @@ -112,6 +125,9 @@ export class ConsoleLspClient implements CompletionProvider {
await this.startInternal();
})()
.catch(async (error) => {
if (!this.disposed) {
this.logServerError(error, this.spawnedServer);
}
const failedClient = this.client;
this.client = undefined;
this.closePendingSocketServer();
Expand Down Expand Up @@ -317,8 +333,18 @@ export class ConsoleLspClient implements CompletionProvider {
outputChannel: this.outputChannel,
revealOutputChannelOn: RevealOutputChannelOn.Never,
errorHandler: {
error: () => ({ action: ErrorAction.Continue, handled: true }),
closed: () => ({ action: CloseAction.DoNotRestart, handled: true }),
error: (error) => {
if (this.client) {
this.logServerError(error, this.spawnedServer);
}
return { action: ErrorAction.Continue, handled: true };
},
closed: () => {
if (this.client) {
this.logServerError("connection closed unexpectedly", this.spawnedServer);
}
return { action: CloseAction.DoNotRestart, handled: true };
},
},
};

Expand Down Expand Up @@ -357,6 +383,7 @@ export class ConsoleLspClient implements CompletionProvider {
this.outputChannel.appendLine(data.toString());
});
child.once("spawn", () => {
this.logServerStarted(child);
if (settled) {
return;
}
Expand All @@ -369,12 +396,16 @@ export class ConsoleLspClient implements CompletionProvider {
resolve({ reader: child.stdout, writer: child.stdin });
});
child.once("error", (error) => {
if (settled) {
this.logServerError(error, child);
}
if (!settled) {
settled = true;
reject(error);
}
});
child.once("exit", (code, signal) => {
this.logServerStopped(child);
if (code === 10) {
void vscode.window.showWarningMessage(
"R package {languageserver} is required for console autocompletion."
Expand Down Expand Up @@ -408,7 +439,7 @@ export class ConsoleLspClient implements CompletionProvider {
this.pendingSocketServer = undefined;
}
socket.on("error", (error) => {
this.outputChannel.appendLine(`LSP socket error: ${error.message}`);
this.logServerError(error);
});
server.close();
resolve({ reader: socket, writer: socket });
Expand Down Expand Up @@ -466,10 +497,17 @@ export class ConsoleLspClient implements CompletionProvider {
child.stderr?.on("data", (data: Buffer | string) => {
this.outputChannel.appendLine(data.toString());
});
child.once("spawn", () => {
this.logServerStarted(child);
});
child.once("error", (error) => {
if (settled) {
this.logServerError(error, child);
}
rejectOnce(error);
});
child.once("exit", (code, signal) => {
this.logServerStopped(child);
if (code === 10) {
void vscode.window.showWarningMessage(
"R package {languageserver} is required for console autocompletion."
Expand Down Expand Up @@ -583,6 +621,31 @@ export class ConsoleLspClient implements CompletionProvider {
}
}

private logServerStarted(child: ChildProcess): void {
const timestamp = formatLogTimestamp();
lifecycleOutputChannel.appendLine(
`[Info - ${timestamp}] R Console Language Server (${child.pid ?? "unknown"}) started`
);
lifecycleOutputChannel.appendLine(
`[Info - ${timestamp}] R executable: "${this.options.rPath}"`
);
}

private logServerError(error: unknown, child: ChildProcess | undefined = this.spawnedServer): void {
const message = error instanceof Error ? error.message : String(error);
lifecycleOutputChannel.appendLine(
`[Error - ${formatLogTimestamp()}] ` +
`R Console Language Server (${child?.pid ?? "unknown"}) error: ${message}`
);
}

private logServerStopped(child: ChildProcess): void {
lifecycleOutputChannel.appendLine(
`[Info - ${formatLogTimestamp()}] ` +
`R Console Language Server (${child.pid ?? "unknown"}) stopped`
);
}

private terminateSpawnedServer(): Promise<boolean> {
if (this.terminationPromise) {
return this.terminationPromise;
Expand Down
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as vscode from "vscode";
import * as fs from "fs";
import * as path from "path";
import { disposeConsoleLspOutputChannel } from "./Language/consoleLspClient";
import {
RTerminal,
type PersistedRTerminalState,
Expand Down Expand Up @@ -1359,6 +1360,7 @@ export async function deactivate(): Promise<void> {
pidToRecord.clear();
editorTabToRecord.clear();
await Promise.allSettled([...pendingTerminalCleanups]);
disposeConsoleLspOutputChannel();
}

function startPersistentSessionRegistry(context: vscode.ExtensionContext): void {
Expand Down
Loading