Auto merge of #12477 - hasali19:auto-reload, r=Veykril

Restart server automatically on settings changes

Closes #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.
This commit is contained in:
bors 2022-06-10 20:11:48 +00:00
commit 745230c669
2 changed files with 19 additions and 6 deletions

View file

@ -1115,6 +1115,11 @@
"Search in current workspace and dependencies." "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": {} "$generated-end": {}
} }
}, },

View file

@ -60,6 +60,9 @@ export class Config {
if (!requiresReloadOpt) return; if (!requiresReloadOpt) return;
if (this.restartServerOnConfigChange) {
await vscode.commands.executeCommand("rust-analyzer.reload");
} else {
const userResponse = await vscode.window.showInformationMessage( const userResponse = await vscode.window.showInformationMessage(
`Changing "${requiresReloadOpt}" requires a reload`, `Changing "${requiresReloadOpt}" requires a reload`,
"Reload now" "Reload now"
@ -69,6 +72,7 @@ export class Config {
await vscode.commands.executeCommand("rust-analyzer.reload"); await vscode.commands.executeCommand("rust-analyzer.reload");
} }
} }
}
// We don't do runtime config validation here for simplicity. More on stackoverflow: // We don't do runtime config validation here for simplicity. More on stackoverflow:
// https://stackoverflow.com/questions/60135780/what-is-the-best-way-to-type-check-the-configuration-for-vscode-extension // https://stackoverflow.com/questions/60135780/what-is-the-best-way-to-type-check-the-configuration-for-vscode-extension
@ -119,6 +123,10 @@ export class Config {
return this.get<RunnableEnvCfg>("runnableEnv"); return this.get<RunnableEnvCfg>("runnableEnv");
} }
get restartServerOnConfigChange() {
return this.get<boolean>("restartServerOnConfigChange");
}
get debug() { get debug() {
let sourceFileMap = this.get<Record<string, string> | "auto">("debug.sourceFileMap"); let sourceFileMap = this.get<Record<string, string> | "auto">("debug.sourceFileMap");
if (sourceFileMap !== "auto") { if (sourceFileMap !== "auto") {