2019-12-30 20:07:04 +01:00
|
|
|
import * as vscode from 'vscode';
|
|
|
|
|
import * as lc from 'vscode-languageclient';
|
|
|
|
|
|
2019-12-30 18:31:08 +01:00
|
|
|
import { Ctx, Cmd } from '../ctx';
|
2019-12-30 23:45:50 +01:00
|
|
|
import * as sourceChange from '../source_change';
|
2019-12-30 14:53:43 +01:00
|
|
|
|
2019-12-30 14:42:59 +01:00
|
|
|
import { analyzerStatus } from './analyzer_status';
|
2019-12-30 15:20:13 +01:00
|
|
|
import { matchingBrace } from './matching_brace';
|
2019-12-30 15:50:15 +01:00
|
|
|
import { joinLines } from './join_lines';
|
2019-12-30 16:43:34 +01:00
|
|
|
import { onEnter } from './on_enter';
|
2019-12-30 17:03:05 +01:00
|
|
|
import { parentModule } from './parent_module';
|
2019-12-30 19:05:41 +01:00
|
|
|
import { syntaxTree } from './syntax_tree';
|
2019-12-30 19:30:30 +01:00
|
|
|
import { expandMacro } from './expand_macro';
|
2019-12-30 19:58:44 +01:00
|
|
|
import { run, runSingle } from './runnables';
|
2018-10-08 20:18:55 +02:00
|
|
|
|
2019-12-30 14:53:43 +01:00
|
|
|
function collectGarbage(ctx: Ctx): Cmd {
|
2019-12-30 18:31:08 +01:00
|
|
|
return async () => {
|
2019-12-31 18:14:00 +01:00
|
|
|
ctx.client?.sendRequest<null>('rust-analyzer/collectGarbage', null);
|
2019-12-30 18:31:08 +01:00
|
|
|
};
|
2019-12-30 14:53:43 +01:00
|
|
|
}
|
|
|
|
|
|
2019-12-30 20:07:04 +01:00
|
|
|
function showReferences(ctx: Ctx): Cmd {
|
|
|
|
|
return (uri: string, position: lc.Position, locations: lc.Location[]) => {
|
2019-12-31 18:14:00 +01:00
|
|
|
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),
|
|
|
|
|
);
|
|
|
|
|
}
|
2019-12-30 20:07:04 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-30 23:45:50 +01:00
|
|
|
function applySourceChange(ctx: Ctx): Cmd {
|
2020-01-12 00:40:36 +02:00
|
|
|
return async (change: sourceChange.SourceChange) => {
|
|
|
|
|
sourceChange.applySourceChange(ctx, change);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function selectAndApplySourceChange(ctx: Ctx): Cmd {
|
|
|
|
|
return async (changes: sourceChange.SourceChange[]) => {
|
|
|
|
|
if (changes.length === 1) {
|
|
|
|
|
await sourceChange.applySourceChange(ctx, changes[0]);
|
|
|
|
|
} else if (changes.length > 0) {
|
|
|
|
|
const selectedChange = await vscode.window.showQuickPick(changes);
|
|
|
|
|
if (!selectedChange) return;
|
|
|
|
|
await sourceChange.applySourceChange(ctx, selectedChange);
|
|
|
|
|
}
|
2019-12-31 18:55:34 +01:00
|
|
|
};
|
2019-12-30 23:45:50 +01:00
|
|
|
}
|
|
|
|
|
|
2019-12-31 18:14:00 +01:00
|
|
|
function reload(ctx: Ctx): Cmd {
|
|
|
|
|
return async () => {
|
|
|
|
|
vscode.window.showInformationMessage('Reloading rust-analyzer...');
|
|
|
|
|
await ctx.restartServer();
|
2019-12-31 18:55:34 +01:00
|
|
|
};
|
2019-12-31 18:14:00 +01:00
|
|
|
}
|
|
|
|
|
|
2018-10-08 20:18:55 +02:00
|
|
|
export {
|
2019-01-23 00:15:03 +03:00
|
|
|
analyzerStatus,
|
2019-11-18 02:47:50 +08:00
|
|
|
expandMacro,
|
2018-10-08 20:18:55 +02:00
|
|
|
joinLines,
|
|
|
|
|
matchingBrace,
|
|
|
|
|
parentModule,
|
2018-10-09 16:00:20 +03:00
|
|
|
syntaxTree,
|
2019-07-23 16:38:21 +03:00
|
|
|
onEnter,
|
2019-12-30 18:31:08 +01:00
|
|
|
collectGarbage,
|
2019-12-30 19:58:44 +01:00
|
|
|
run,
|
2019-12-30 20:07:04 +01:00
|
|
|
runSingle,
|
|
|
|
|
showReferences,
|
2019-12-30 23:45:50 +01:00
|
|
|
applySourceChange,
|
2020-01-12 00:40:36 +02:00
|
|
|
selectAndApplySourceChange,
|
2019-12-31 18:14:00 +01:00
|
|
|
reload
|
2018-10-08 20:18:55 +02:00
|
|
|
};
|