Skip to content

Commit 099da0e

Browse files
authored
Use extension context for output window disposable (#671)
## Summary I noticed this in #585 that we would not be able to look at the error message when the server crashes because the output window got disposed. This is because the disposable is tied up with stopping the server. This PR updates that to include the disposable to the extension context so that it gets disposed only when the extension is deactivated. ## Test Plan Run the scenario from #585 to make sure that the "Ruff Language Server" window is not disposed in case the server crashed.
1 parent b6a7b2d commit 099da0e

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/common/server.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ async function createServer(
416416
let _disposables: Disposable[] = [];
417417

418418
export async function startServer(
419+
context: vscode.ExtensionContext,
419420
projectRoot: vscode.WorkspaceFolder,
420421
workspaceSettings: ISettings,
421422
serverId: string,
@@ -425,11 +426,13 @@ export async function startServer(
425426

426427
// Create output channels for the server and trace logs
427428
const outputChannel = vscode.window.createOutputChannel(`${serverName} Language Server`);
428-
_disposables.push(outputChannel);
429+
context.subscriptions.push(outputChannel);
429430
const traceOutputChannel = new LazyOutputChannel(`${serverName} Language Server Trace`);
430-
_disposables.push(traceOutputChannel);
431+
context.subscriptions.push(traceOutputChannel);
431432
// And, a command to show the server logs
432-
_disposables.push(registerCommand(`${serverId}.showServerLogs`, () => outputChannel.show()));
433+
context.subscriptions.push(
434+
registerCommand(`${serverId}.showServerLogs`, () => outputChannel.show()),
435+
);
433436

434437
const extensionSettings = await getExtensionSettings(serverId);
435438
const globalSettings = await getGlobalSettings(serverId);

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
127127
}
128128
}
129129

130-
lsClient = await startServer(projectRoot, workspaceSettings, serverId, serverName);
130+
lsClient = await startServer(context, projectRoot, workspaceSettings, serverId, serverName);
131131
} finally {
132132
// Ensure that we reset the flag in case of an error, early return, or success.
133133
restartInProgress = false;

0 commit comments

Comments
 (0)