Skip to content

Avoid re-registering visualize command after restart #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2022
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
3 changes: 1 addition & 2 deletions src/Visualize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class Visualize implements Disposable, TextDocumentContentProvider {
this.languageClient = languageClient;
this.outputChannel = outputChannel;
this.disposables = [
commands.registerCommand("syntaxTree.visualize", this.visualize),
workspace.registerTextDocumentContentProvider("syntaxTree.visualize", this)
];
}
Expand All @@ -40,7 +39,7 @@ class Visualize implements Disposable, TextDocumentContentProvider {
const doc = await workspace.openTextDocument(uri);
languages.setTextDocumentLanguage(doc, "plaintext");

await window.showTextDocument(doc, ViewColumn.Beside, true);
await window.showTextDocument(doc, ViewColumn.Beside, true);
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import Visualize from "./Visualize";
const promiseExec = promisify(exec);

export function activate(context: ExtensionContext) {
let languageClient: LanguageClient | null = null;
const outputChannel = window.createOutputChannel("Syntax Tree");
let languageClient: LanguageClient | null = null;
let visualizer: Visualize | null = null;

context.subscriptions.push(
commands.registerCommand("syntaxTree.start", startLanguageServer),
commands.registerCommand("syntaxTree.stop", stopLanguageServer),
commands.registerCommand("syntaxTree.restart", restartLanguageServer),
commands.registerCommand("syntaxTree.visualize", () => visualizer?.visualize()),
commands.registerCommand("syntaxTree.showOutputChannel", () => outputChannel.show()),
outputChannel
);
Expand All @@ -35,7 +37,7 @@ export function activate(context: ExtensionContext) {
await promiseExec("bundle show syntax_tree", { cwd });
run = { command: "bundle", args: ["exec", "stree", "lsp"], options: { cwd } };
} catch {
outputChannel.appendLine("No bundled syntax_tree, running global stree.");
outputChannel.appendLine("No bundled syntax_tree, running global stree.");
}
}

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

visualizer = new Visualize(languageClient, outputChannel);
context.subscriptions.push(
new InlayHints(languageClient, outputChannel),
new Visualize(languageClient, outputChannel)
visualizer
);
}

Expand Down