Skip to content

Commit e9fb2ff

Browse files
committed
Add lsp command for rebuilding proc macros
1 parent d154ea8 commit e9fb2ff

File tree

7 files changed

+27
-1
lines changed

7 files changed

+27
-1
lines changed

crates/rust-analyzer/src/handlers.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ pub(crate) fn handle_workspace_reload(state: &mut GlobalState, _: ()) -> Result<
5252
Ok(())
5353
}
5454

55+
pub(crate) fn handle_proc_macros_reload(state: &mut GlobalState, _: ()) -> Result<()> {
56+
state.proc_macro_clients.clear();
57+
state.proc_macro_changed = false;
58+
59+
state.fetch_build_data_queue.request_op("reload proc macros request".to_string());
60+
Ok(())
61+
}
62+
5563
pub(crate) fn handle_cancel_flycheck(state: &mut GlobalState, _: ()) -> Result<()> {
5664
let _p = profile::span("handle_stop_flycheck");
5765
state.flycheck.iter().for_each(|flycheck| flycheck.cancel());

crates/rust-analyzer/src/lsp_ext.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ impl Request for ReloadWorkspace {
5151
const METHOD: &'static str = "rust-analyzer/reloadWorkspace";
5252
}
5353

54+
pub enum ReloadProcMacros {}
55+
56+
impl Request for ReloadProcMacros {
57+
type Params = ();
58+
type Result = ();
59+
const METHOD: &'static str = "rust-analyzer/reloadProcMacros";
60+
}
61+
5462
pub enum SyntaxTree {}
5563

5664
impl Request for SyntaxTree {

crates/rust-analyzer/src/main_loop.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ impl GlobalState {
633633

634634
dispatcher
635635
.on_sync_mut::<lsp_ext::ReloadWorkspace>(handlers::handle_workspace_reload)
636+
.on_sync_mut::<lsp_ext::ReloadProcMacros>(handlers::handle_proc_macros_reload)
636637
.on_sync_mut::<lsp_ext::MemoryUsage>(handlers::handle_memory_usage)
637638
.on_sync_mut::<lsp_ext::ShuffleCrateGraph>(handlers::handle_shuffle_crate_graph)
638639
.on_sync::<lsp_ext::JoinLines>(handlers::handle_join_lines)

editors/code/src/commands.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,10 @@ export function reloadWorkspace(ctx: CtxInit): Cmd {
749749
return async () => ctx.client.sendRequest(ra.reloadWorkspace);
750750
}
751751

752+
export function reloadProcMacros(ctx: CtxInit): Cmd {
753+
return async () => ctx.client.sendRequest(ra.reloadProcMacros);
754+
}
755+
752756
export function addProject(ctx: CtxInit): Cmd {
753757
return async () => {
754758
const discoverProjectCommand = ctx.config.discoverProjectCommand;

editors/code/src/ctx.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,13 @@ export class Ctx {
378378
if (statusBar.tooltip.value) {
379379
statusBar.tooltip.appendText("\n\n");
380380
}
381+
statusBar.tooltip.appendMarkdown("\n\n[Open logs](command:rust-analyzer.openLogs)");
381382
statusBar.tooltip.appendMarkdown(
382383
"\n\n[Reload Workspace](command:rust-analyzer.reloadWorkspace)"
383384
);
384-
statusBar.tooltip.appendMarkdown("\n\n[Open logs](command:rust-analyzer.openLogs)");
385+
statusBar.tooltip.appendMarkdown(
386+
"\n\n[Rebuild Proc Macros](command:rust-analyzer.reloadProcMacros)"
387+
);
385388
statusBar.tooltip.appendMarkdown("\n\n[Restart server](command:rust-analyzer.startServer)");
386389
statusBar.tooltip.appendMarkdown("\n\n[Stop server](command:rust-analyzer.stopServer)");
387390
if (!status.quiescent) icon = "$(sync~spin) ";

editors/code/src/lsp_ext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export const relatedTests = new lc.RequestType<lc.TextDocumentPositionParams, Te
4343
"rust-analyzer/relatedTests"
4444
);
4545
export const reloadWorkspace = new lc.RequestType0<null, void>("rust-analyzer/reloadWorkspace");
46+
export const reloadProcMacros = new lc.RequestType0<null, void>("rust-analyzer/reloadProcMacros");
4647

4748
export const runFlycheck = new lc.NotificationType<{
4849
textDocument: lc.TextDocumentIdentifier | null;

editors/code/src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ function createCommands(): Record<string, CommandFactory> {
153153
memoryUsage: { enabled: commands.memoryUsage },
154154
shuffleCrateGraph: { enabled: commands.shuffleCrateGraph },
155155
reloadWorkspace: { enabled: commands.reloadWorkspace },
156+
reloadProcMacros: { enabled: commands.reloadProcMacros },
156157
addProject: { enabled: commands.addProject },
157158
matchingBrace: { enabled: commands.matchingBrace },
158159
joinLines: { enabled: commands.joinLines },

0 commit comments

Comments
 (0)