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