Skip to content

Commit

Permalink
Register viewSyntaxTree conditionally depending of server capability
Browse files Browse the repository at this point in the history
  • Loading branch information
piotmag769 committed Feb 7, 2025
1 parent dcf8fc2 commit 7382e50
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@
"category": "Cairo"
}
],
"menus": {
"commandPalette": [
{
"command": "cairo.viewSyntaxTree",
"when": "cairo1.viewSyntaxTreeCommandAvailable && editorLangId == cairo"
}
]
},
"configuration": [
{
"title": "Cairo",
Expand Down
19 changes: 17 additions & 2 deletions src/cairols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import { Context } from "./context";
import { Scarb } from "./scarb";
import {
registerMacroExpandProvider,
registerViewSyntaxTreeProvider,
registerVfsProvider,
registerViewAnalyzedCratesProvider,
registerViewSyntaxTreeProvider,
} from "./textDocumentProviders";

import { executablesEqual, getLSExecutables, LSExecutable } from "./lsExecutable";
import assert from "node:assert";
import { projectConfigParsingFailed } from "./lspRequests";
import * as lsp from "vscode-languageserver-protocol";

function notifyScarbMissing(ctx: Context) {
const errorMessage =
Expand Down Expand Up @@ -72,7 +73,6 @@ export async function setupLanguageServer(ctx: Context): Promise<SetupResult | u
registerVfsProvider(client, ctx);
registerMacroExpandProvider(client, ctx);
registerViewAnalyzedCratesProvider(client, ctx);
registerViewSyntaxTreeProvider(client, ctx);

client.onNotification("scarb/could-not-find-scarb-executable", () => notifyScarbMissing(ctx));

Expand Down Expand Up @@ -183,6 +183,21 @@ export async function setupLanguageServer(ctx: Context): Promise<SetupResult | u
}
});

ctx.extension.subscriptions.push(
client.onRequest(lsp.RegistrationRequest.type, ({ registrations }) => {
for (const reg of registrations) {
if (reg.method === "custom/ViewSyntaxTree") {
vscode.commands.executeCommand(
"setContext",
"cairo1.viewSyntaxTreeCommandAvailable",
true,
);
registerViewSyntaxTreeProvider(client, ctx);
}
}
}),
);

await client.start();

return { client, executable: executables[0] };
Expand Down
1 change: 1 addition & 0 deletions src/extensionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class CairoExtensionManager implements vscode.Disposable {
return false;
}
const { client, executable } = setupResult;

this.client = client;
this.runningExecutable = executable;
return true;
Expand Down

0 comments on commit 7382e50

Please sign in to comment.