Skip to content

Commit 1723e54

Browse files
committed
fixup! Use extension context for output window disposable (#671)
1 parent 099da0e commit 1723e54

2 files changed

Lines changed: 23 additions & 16 deletions

File tree

src/common/server.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
FIND_RUFF_BINARY_SCRIPT_PATH,
1919
RUFF_BINARY_NAME,
2020
} from "./constants";
21-
import { LazyOutputChannel, logger } from "./logger";
21+
import { logger } from "./logger";
2222
import { getDebuggerPath } from "./python";
2323
import {
2424
getExtensionSettings,
@@ -39,7 +39,6 @@ import { updateServerKind, updateStatus } from "./status";
3939
import { getDocumentSelector } from "./utilities";
4040
import { execFile } from "child_process";
4141
import which = require("which");
42-
import { registerCommand } from "./vscodeapi";
4342

4443
export type IInitializationOptions = {
4544
settings: ISettings[];
@@ -416,24 +415,15 @@ async function createServer(
416415
let _disposables: Disposable[] = [];
417416

418417
export async function startServer(
419-
context: vscode.ExtensionContext,
420418
projectRoot: vscode.WorkspaceFolder,
421419
workspaceSettings: ISettings,
422420
serverId: string,
423421
serverName: string,
422+
outputChannel: OutputChannel,
423+
traceOutputChannel: OutputChannel,
424424
): Promise<LanguageClient | undefined> {
425425
updateStatus(undefined, LanguageStatusSeverity.Information, true);
426426

427-
// Create output channels for the server and trace logs
428-
const outputChannel = vscode.window.createOutputChannel(`${serverName} Language Server`);
429-
context.subscriptions.push(outputChannel);
430-
const traceOutputChannel = new LazyOutputChannel(`${serverName} Language Server Trace`);
431-
context.subscriptions.push(traceOutputChannel);
432-
// And, a command to show the server logs
433-
context.subscriptions.push(
434-
registerCommand(`${serverId}.showServerLogs`, () => outputChannel.show()),
435-
);
436-
437427
const extensionSettings = await getExtensionSettings(serverId);
438428
const globalSettings = await getGlobalSettings(serverId);
439429

src/extension.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from "vscode";
22
import { ExecuteCommandRequest, LanguageClient } from "vscode-languageclient/node";
3-
import { logger } from "./common/logger";
3+
import { LazyOutputChannel, logger } from "./common/logger";
44
import {
55
checkVersion,
66
initializePython,
@@ -42,6 +42,13 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
4242
logger.info(`Module: ${serverInfo.module}`);
4343
logger.debug(`Full Server Info: ${JSON.stringify(serverInfo)}`);
4444

45+
// Create output channels for the server and trace logs
46+
const outputChannel = vscode.window.createOutputChannel(`${serverName} Language Server`);
47+
const traceOutputChannel = new LazyOutputChannel(`${serverName} Language Server Trace`);
48+
49+
// Make sure that these channels are disposed when the extension is deactivated.
50+
context.subscriptions.push(outputChannel);
51+
context.subscriptions.push(traceOutputChannel);
4552
context.subscriptions.push(logger.channel);
4653

4754
context.subscriptions.push(
@@ -127,7 +134,14 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
127134
}
128135
}
129136

130-
lsClient = await startServer(context, projectRoot, workspaceSettings, serverId, serverName);
137+
lsClient = await startServer(
138+
projectRoot,
139+
workspaceSettings,
140+
serverId,
141+
serverName,
142+
outputChannel,
143+
traceOutputChannel,
144+
);
131145
} finally {
132146
// Ensure that we reset the flag in case of an error, early return, or success.
133147
restartInProgress = false;
@@ -150,9 +164,12 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
150164
onDidGrantWorkspaceTrust(async () => {
151165
await runServer();
152166
}),
153-
registerCommand(`${serverId}.showLogs`, async () => {
167+
registerCommand(`${serverId}.showLogs`, () => {
154168
logger.channel.show();
155169
}),
170+
registerCommand(`${serverId}.showServerLogs`, () => {
171+
outputChannel.show();
172+
}),
156173
registerCommand(`${serverId}.restart`, async () => {
157174
await runServer();
158175
}),

0 commit comments

Comments
 (0)