Skip to content
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

LS: expose view analyzed crates command #6266

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions vscode-cairo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@
"command": "cairo.expandMacro",
"title": "Recursively expand macros for item at caret",
"category": "Cairo"
},
{
"command": "cairo.viewAnalyzedCrates",
"title": "View crates currently analyzed by LS",
"category": "Cairo"
}
],
"configuration": [
Expand Down Expand Up @@ -130,6 +135,7 @@
}
],
"configurationDefaults": {
"explorer.fileNesting.enabled": true,
"[cairo]": {
"editor.tabSize": 4,
"editor.insertSpaces": true,
Expand Down
7 changes: 6 additions & 1 deletion vscode-cairo/src/cairols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { Context } from "./context";
import { Scarb } from "./scarb";
import { isScarbProject } from "./scarbProject";
import { StandaloneLS } from "./standalonels";
import { registerMacroExpandProvider, registerVfsProvider } from "./textDocumentProviders";
import {
registerMacroExpandProvider,
registerVfsProvider,
registerViewAnalyzedCratesProvider,
} from "./textDocumentProviders";
import { NotificationType } from "vscode-jsonrpc/lib/common/messages";
import * as cp from "node:child_process";

Expand Down Expand Up @@ -64,6 +68,7 @@ export async function setupLanguageServer(ctx: Context): Promise<lc.LanguageClie

registerVfsProvider(client, ctx);
registerMacroExpandProvider(client, ctx);
registerViewAnalyzedCratesProvider(client, ctx);

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

Expand Down
5 changes: 5 additions & 0 deletions vscode-cairo/src/lspRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ export const vfsProvide = new lc.RequestType<
ProvideVirtualFileResponse,
void
>("vfs/provide");

export type viewAnalyzedCratesResponse = string;
export const viewAnalyzedCrates = new lc.RequestType0<viewAnalyzedCratesResponse, void>(
"cairo/viewAnalyzedCrates",
);
42 changes: 41 additions & 1 deletion vscode-cairo/src/textDocumentProviders.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as lc from "vscode-languageclient/node";
import * as vscode from "vscode";
import { Context } from "./context";
import { expandMacro, vfsProvide } from "./lspRequests";
import { expandMacro, vfsProvide, viewAnalyzedCrates } from "./lspRequests";

export const registerVfsProvider = (client: lc.LanguageClient, ctx: Context) => {
const eventEmitter = new vscode.EventEmitter<vscode.Uri>();
Expand Down Expand Up @@ -61,3 +61,43 @@ export const registerMacroExpandProvider = (client: lc.LanguageClient, ctx: Cont
}),
);
};

export const registerViewAnalyzedCratesProvider = (client: lc.LanguageClient, ctx: Context) => {
const uri = vscode.Uri.parse(
"cairo-view-analyzed-crates://viewAnalyzedCrates/[ANALYZED_CRATES].txt",
);
const eventEmitter = new vscode.EventEmitter<vscode.Uri>();

const tdcp: vscode.TextDocumentContentProvider = {
provideTextDocumentContent: () => client.sendRequest(viewAnalyzedCrates),
onDidChange: eventEmitter.event,
};

ctx.extension.subscriptions.push(
vscode.workspace.registerTextDocumentContentProvider("cairo-view-analyzed-crates", tdcp),
);

ctx.extension.subscriptions.push(
vscode.commands.registerCommand("cairo.viewAnalyzedCrates", async () => {
const document = await vscode.workspace.openTextDocument(uri);

eventEmitter.fire(uri);

return vscode.window.showTextDocument(document, vscode.ViewColumn.Two, true);
}),
);

ctx.extension.subscriptions.push(
vscode.workspace.onDidChangeTextDocument((e) => {
const path = e.document.uri.path;
const relevant_suffixes = [".cairo", "Scarb.toml", "Scarb.lock", "cairo_project.toml"];

for (const suffix of relevant_suffixes) {
if (path.endsWith(suffix)) {
eventEmitter.fire(uri);
break;
}
}
}),
);
};
Loading