Refactor server lifecycle

This commit is contained in:
Aleksey Kladov 2019-12-31 18:14:00 +01:00
parent 0849f7001c
commit 087af54069
12 changed files with 216 additions and 199 deletions

View file

@ -15,18 +15,21 @@ import { run, runSingle } from './runnables';
function collectGarbage(ctx: Ctx): Cmd {
return async () => {
ctx.client.sendRequest<null>('rust-analyzer/collectGarbage', null);
ctx.client?.sendRequest<null>('rust-analyzer/collectGarbage', null);
};
}
function showReferences(ctx: Ctx): Cmd {
return (uri: string, position: lc.Position, locations: lc.Location[]) => {
vscode.commands.executeCommand(
'editor.action.showReferences',
vscode.Uri.parse(uri),
ctx.client.protocol2CodeConverter.asPosition(position),
locations.map(ctx.client.protocol2CodeConverter.asLocation),
);
let client = ctx.client;
if (client) {
vscode.commands.executeCommand(
'editor.action.showReferences',
vscode.Uri.parse(uri),
client.protocol2CodeConverter.asPosition(position),
locations.map(client.protocol2CodeConverter.asLocation),
);
}
};
}
@ -36,6 +39,13 @@ function applySourceChange(ctx: Ctx): Cmd {
}
}
function reload(ctx: Ctx): Cmd {
return async () => {
vscode.window.showInformationMessage('Reloading rust-analyzer...');
await ctx.restartServer();
}
}
export {
analyzerStatus,
expandMacro,
@ -49,4 +59,5 @@ export {
runSingle,
showReferences,
applySourceChange,
reload
};