about summary refs log tree commit diff
path: root/editors/code/src
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2022-12-16 22:43:14 +0100
committerLukas Wirth <lukastw97@gmail.com>2022-12-16 22:47:19 +0100
commita04feb915a0e5ef348075a3537a95875cb1b1ffe (patch)
tree5a111d1533c02a36a047eeece486422ea91317fc /editors/code/src
parentba3e3282da0a6500a2a8945a664631fbd9463c64 (diff)
downloadrust-a04feb915a0e5ef348075a3537a95875cb1b1ffe.tar.gz
rust-a04feb915a0e5ef348075a3537a95875cb1b1ffe.zip
Add command for manually running flychecks
Diffstat (limited to 'editors/code/src')
-rw-r--r--editors/code/src/commands.ts15
-rw-r--r--editors/code/src/lsp_ext.ts4
-rw-r--r--editors/code/src/main.ts1
3 files changed, 17 insertions, 3 deletions
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<lc.TextDocumentPositionParams, Te
 
 export const cancelFlycheck = new lc.RequestType0<void, void>("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<string, CommandFactory> {
         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.