Skip to content

Commit 9cbc5de

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

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/Visualize.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ class Visualize implements Disposable, TextDocumentContentProvider {
1616
constructor(languageClient: LanguageClient, outputChannel: OutputChannel) {
1717
this.languageClient = languageClient;
1818
this.outputChannel = outputChannel;
19-
this.disposables = [
20-
commands.registerCommand("syntaxTree.visualize", this.visualize),
21-
workspace.registerTextDocumentContentProvider("syntaxTree.visualize", this)
22-
];
19+
this.disposables = [];
2320
}
2421

2522
dispose() {
@@ -40,7 +37,7 @@ class Visualize implements Disposable, TextDocumentContentProvider {
4037
const doc = await workspace.openTextDocument(uri);
4138
languages.setTextDocumentLanguage(doc, "plaintext");
4239

43-
await window.showTextDocument(doc, ViewColumn.Beside, true);
40+
await window.showTextDocument(doc, ViewColumn.Beside, true);
4441
}
4542
}
4643
}

src/extension.ts

Lines changed: 4 additions & 2 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

0 commit comments

Comments
 (0)