Skip to content

Commit

Permalink
Auto merge of rust-lang#12477 - hasali19:auto-reload, r=Veykril
Browse files Browse the repository at this point in the history
Restart server automatically on settings changes

Closes rust-lang#12476

I think this works quite well, but if you think it would be better to put it behind a setting I can do that.
  • Loading branch information
bors committed Jun 10, 2022
2 parents 0bbead9 + 213fe57 commit 745230c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
5 changes: 5 additions & 0 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,11 @@
"Search in current workspace and dependencies."
]
},
"rust-analyzer.restartServerOnConfigChange": {
"markdownDescription": "Whether to restart the server automatically when certain settings that require a restart are changed.",
"default": false,
"type": "boolean"
},
"$generated-end": {}
}
},
Expand Down
20 changes: 14 additions & 6 deletions editors/code/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,17 @@ export class Config {

if (!requiresReloadOpt) return;

const userResponse = await vscode.window.showInformationMessage(
`Changing "${requiresReloadOpt}" requires a reload`,
"Reload now"
);

if (userResponse === "Reload now") {
if (this.restartServerOnConfigChange) {
await vscode.commands.executeCommand("rust-analyzer.reload");
} else {
const userResponse = await vscode.window.showInformationMessage(
`Changing "${requiresReloadOpt}" requires a reload`,
"Reload now"
);

if (userResponse === "Reload now") {
await vscode.commands.executeCommand("rust-analyzer.reload");
}
}
}

Expand Down Expand Up @@ -119,6 +123,10 @@ export class Config {
return this.get<RunnableEnvCfg>("runnableEnv");
}

get restartServerOnConfigChange() {
return this.get<boolean>("restartServerOnConfigChange");
}

get debug() {
let sourceFileMap = this.get<Record<string, string> | "auto">("debug.sourceFileMap");
if (sourceFileMap !== "auto") {
Expand Down

0 comments on commit 745230c

Please sign in to comment.