From a04feb915a0e5ef348075a3537a95875cb1b1ffe Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 16 Dec 2022 22:43:14 +0100 Subject: Add command for manually running flychecks --- editors/code/src/commands.ts | 15 ++++++++++++--- editors/code/src/lsp_ext.ts | 4 ++++ editors/code/src/main.ts | 1 + 3 files changed, 17 insertions(+), 3 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts index 312087e4cff..e0b4bb63c31 100644 --- a/editors/code/src/commands.ts +++ b/editors/code/src/commands.ts @@ -788,8 +788,17 @@ export function openDocs(ctx: CtxInit): Cmd { export function cancelFlycheck(ctx: CtxInit): Cmd { return async () => { + await ctx.client.sendRequest(ra.cancelFlycheck); + }; +} + +export function runFlycheck(ctx: CtxInit): Cmd { + return async () => { + const editor = ctx.activeRustEditor; const client = ctx.client; - await client.sendRequest(ra.cancelFlycheck); + const params = editor ? { uri: editor.document.uri.toString() } : null; + + await client.sendNotification(ra.runFlycheck, { textDocument: params }); }; } @@ -797,12 +806,12 @@ export function resolveCodeAction(ctx: CtxInit): Cmd { return async (params: lc.CodeAction) => { const client = ctx.client; params.command = undefined; - const item = await client?.sendRequest(lc.CodeActionResolveRequest.type, params); + const item = await client.sendRequest(lc.CodeActionResolveRequest.type, params); if (!item?.edit) { return; } const itemEdit = item.edit; - const edit = await client?.protocol2CodeConverter.asWorkspaceEdit(itemEdit); + const edit = await client.protocol2CodeConverter.asWorkspaceEdit(itemEdit); // filter out all text edits and recreate the WorkspaceEdit without them so we can apply // snippet edits on our own const lcFileSystemEdit = { diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts index 875261c48a6..78da4e959c6 100644 --- a/editors/code/src/lsp_ext.ts +++ b/editors/code/src/lsp_ext.ts @@ -81,6 +81,10 @@ export const relatedTests = new lc.RequestType("rust-analyzer/cancelFlycheck"); +export const runFlycheck = new lc.NotificationType<{ + textDocument: lc.TextDocumentIdentifier | null; +}>("rust-analyzer/runFlycheck"); + // Experimental extensions export interface SsrParams { diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 01a1a2db7fd..c5fc44b4f9f 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -150,6 +150,7 @@ function createCommands(): Record { moveItemUp: { enabled: commands.moveItemUp }, moveItemDown: { enabled: commands.moveItemDown }, cancelFlycheck: { enabled: commands.cancelFlycheck }, + runFlycheck: { enabled: commands.runFlycheck }, ssr: { enabled: commands.ssr }, serverVersion: { enabled: commands.serverVersion }, // Internal commands which are invoked by the server. -- cgit 1.4.1-3-g733a5