mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
Refactor server lifecycle
This commit is contained in:
parent
0849f7001c
commit
087af54069
12 changed files with 216 additions and 199 deletions
|
@ -49,9 +49,10 @@ class TextDocumentContentProvider
|
|||
_uri: vscode.Uri,
|
||||
): vscode.ProviderResult<string> {
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
if (editor == null) return '';
|
||||
const client = this.ctx.client
|
||||
if (!editor || !client) return '';
|
||||
|
||||
return this.ctx.client.sendRequest<string>(
|
||||
return client.sendRequest<string>(
|
||||
'rust-analyzer/analyzerStatus',
|
||||
null,
|
||||
);
|
||||
|
|
|
@ -52,14 +52,15 @@ class TextDocumentContentProvider
|
|||
|
||||
async provideTextDocumentContent(_uri: vscode.Uri): Promise<string> {
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
if (editor == null) return '';
|
||||
const client = this.ctx.client
|
||||
if (!editor || !client) return '';
|
||||
|
||||
const position = editor.selection.active;
|
||||
const request: lc.TextDocumentPositionParams = {
|
||||
textDocument: { uri: editor.document.uri.toString() },
|
||||
position,
|
||||
};
|
||||
const expanded = await this.ctx.client.sendRequest<ExpandedMacro>(
|
||||
const expanded = await client.sendRequest<ExpandedMacro>(
|
||||
'rust-analyzer/expandMacro',
|
||||
request,
|
||||
);
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
|
|
@ -6,13 +6,14 @@ import { applySourceChange, SourceChange } from '../source_change';
|
|||
export function joinLines(ctx: Ctx): Cmd {
|
||||
return async () => {
|
||||
const editor = ctx.activeRustEditor;
|
||||
if (!editor) return;
|
||||
const client = ctx.client;
|
||||
if (!editor || !client) return;
|
||||
|
||||
const request: JoinLinesParams = {
|
||||
range: ctx.client.code2ProtocolConverter.asRange(editor.selection),
|
||||
range: client.code2ProtocolConverter.asRange(editor.selection),
|
||||
textDocument: { uri: editor.document.uri.toString() },
|
||||
};
|
||||
const change = await ctx.client.sendRequest<SourceChange>(
|
||||
const change = await client.sendRequest<SourceChange>(
|
||||
'rust-analyzer/joinLines',
|
||||
request,
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue