From bd049c9044caed6cc791f6d4323d26490a4f1187 Mon Sep 17 00:00:00 2001 From: Heyward Fann Date: Sat, 6 May 2023 10:37:27 +0800 Subject: [PATCH] feat: add rust-analyzer.reloadProcMacros related #256 --- README.md | 1 + package.json | 5 +++++ src/commands.ts | 9 +++++++++ src/index.ts | 1 + src/lsp_ext.ts | 2 ++ 5 files changed, 18 insertions(+) diff --git a/README.md b/README.md index 781c33e8..2799778c 100644 --- a/README.md +++ b/README.md @@ -187,6 +187,7 @@ You can use these commands by `:CocCommand XYZ`. | rust-analyzer.runFlycheck | Run flycheck | | rust-analyzer.cancelFlycheck | Cancel running flychecks | | rust-analyzer.clearFlycheck | Clear flycheck diagnostics | +| rust-analyzer.rebuildProcMacros | Rebuild proc macros and build scripts | ## License diff --git a/package.json b/package.json index 3e0781a0..e96a3304 100644 --- a/package.json +++ b/package.json @@ -1290,6 +1290,11 @@ "title": "Clear flycheck diagnostics", "category": "rust-analyzer" }, + { + "command": "rust-analyzer.rebuildProcMacros", + "title": "Rebuild proc macros and build scripts", + "category": "rust-analyzer" + }, { "command": "rust-analyzer.explainError", "title": "Explain the currently hovered diagnostic", diff --git a/src/commands.ts b/src/commands.ts index 64b96fe7..ea538331 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -899,3 +899,12 @@ export function viewItemTree(ctx: Ctx): Cmd { await nvim.resumeNotification(true); }; } + +export function rebuildProcMacros(ctx: Ctx): Cmd { + return async () => { + const { document } = await workspace.getCurrentState(); + if (!isRustDocument(document)) return; + + await ctx.client.sendRequest(ra.rebuildProcMacros); + }; +} diff --git a/src/index.ts b/src/index.ts index c36db055..d4f3f16f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -73,6 +73,7 @@ export async function activate(context: ExtensionContext): Promise { ctx.registerCommand('clearFlycheck', cmds.clearFlycheck); ctx.registerCommand('analyzerStatus', cmds.analyzerStatus); ctx.registerCommand('viewCrateGraph', cmds.viewCrateGraph); + ctx.registerCommand('rebuildProcMacros', cmds.rebuildProcMacros); ctx.registerCommand('shuffleCrateGraph', cmds.shuffleCrateGraph); ctx.registerCommand('viewFullCrateGraph', cmds.viewFullCrateGraph); ctx.registerCommand('reloadWorkspace', cmds.reloadWorkspace); diff --git a/src/lsp_ext.ts b/src/lsp_ext.ts index 61f731eb..56bfd82e 100644 --- a/src/lsp_ext.ts +++ b/src/lsp_ext.ts @@ -43,6 +43,8 @@ export const relatedTests = new lc.RequestType('rust-analyzer/reloadWorkspace'); +export const rebuildProcMacros = new lc.RequestType0('rust-analyzer/rebuildProcMacros'); + export const runFlycheck = new lc.NotificationType<{ textDocument: lc.TextDocumentIdentifier | null; }>('rust-analyzer/runFlycheck');