Skip to content

Commit dee2076

Browse files
committed
Avoid re-registering visualize command after restart
1 parent f09d94c commit dee2076

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/Visualize.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class Visualize implements Disposable, TextDocumentContentProvider {
1717
this.languageClient = languageClient;
1818
this.outputChannel = outputChannel;
1919
this.disposables = [
20-
commands.registerCommand("syntaxTree.visualize", this.visualize),
2120
workspace.registerTextDocumentContentProvider("syntaxTree.visualize", this)
2221
];
2322
}
@@ -40,7 +39,7 @@ class Visualize implements Disposable, TextDocumentContentProvider {
4039
const doc = await workspace.openTextDocument(uri);
4140
languages.setTextDocumentLanguage(doc, "plaintext");
4241

43-
await window.showTextDocument(doc, ViewColumn.Beside, true);
42+
await window.showTextDocument(doc, ViewColumn.Beside, true);
4443
}
4544
}
4645
}

src/extension.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ import Visualize from "./Visualize";
1111
const promiseExec = promisify(exec);
1212

1313
export function activate(context: ExtensionContext) {
14-
let languageClient: LanguageClient | null = null;
1514
const outputChannel = window.createOutputChannel("Syntax Tree");
15+
let languageClient: LanguageClient | null = null;
16+
let visualizer: Visualize | null = null;
1617

1718
context.subscriptions.push(
1819
commands.registerCommand("syntaxTree.start", startLanguageServer),
1920
commands.registerCommand("syntaxTree.stop", stopLanguageServer),
2021
commands.registerCommand("syntaxTree.restart", restartLanguageServer),
22+
commands.registerCommand("syntaxTree.visualize", () => visualizer?.visualize()),
2123
commands.registerCommand("syntaxTree.showOutputChannel", () => outputChannel.show()),
2224
outputChannel
2325
);
@@ -35,7 +37,7 @@ export function activate(context: ExtensionContext) {
3537
await promiseExec("bundle show syntax_tree", { cwd });
3638
run = { command: "bundle", args: ["exec", "stree", "lsp"], options: { cwd } };
3739
} catch {
38-
outputChannel.appendLine("No bundled syntax_tree, running global stree.");
40+
outputChannel.appendLine("No bundled syntax_tree, running global stree.");
3941
}
4042
}
4143

@@ -49,9 +51,10 @@ export function activate(context: ExtensionContext) {
4951
context.subscriptions.push(languageClient.start());
5052
await languageClient.onReady();
5153

54+
visualizer = new Visualize(languageClient, outputChannel);
5255
context.subscriptions.push(
5356
new InlayHints(languageClient, outputChannel),
54-
new Visualize(languageClient, outputChannel)
57+
visualizer
5558
);
5659
}
5760

0 commit comments

Comments
 (0)