+import * as vscode from 'vscode';
+import * as lc from 'vscode-languageclient';
+
import { Ctx, Cmd } from '../ctx';
import { analyzerStatus } from './analyzer_status';
};
}
+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),
+ );
+ };
+}
+
export {
analyzerStatus,
expandMacro,
inlayHints,
collectGarbage,
run,
- runSingle
+ runSingle,
+ showReferences,
};
return async () => {
const editor = ctx.activeRustEditor;
- if (!editor) return
+ if (!editor) return;
const textDocument: lc.TextDocumentIdentifier = {
uri: editor.document.uri.toString(),
prevRunnable = item;
const task = createTask(item.runnable);
return await vscode.tasks.executeTask(task);
- }
+ };
}
export function runSingle(ctx: Ctx): Cmd {
return async (runnable: Runnable) => {
const editor = ctx.activeRustEditor;
- if (!editor) return
+ if (!editor) return;
const task = createTask(runnable);
task.group = vscode.TaskGroup.Build;
};
return vscode.tasks.executeTask(task);
- }
+ };
}
interface RunnablesParams {
export async function activate(context: vscode.ExtensionContext) {
ctx = new Ctx(context);
+
+ // Commands which invokes manually via command pallet, shortcut, etc.
ctx.registerCommand('analyzerStatus', commands.analyzerStatus);
ctx.registerCommand('collectGarbage', commands.collectGarbage);
ctx.registerCommand('matchingBrace', commands.matchingBrace);
ctx.registerCommand('syntaxTree', commands.syntaxTree);
ctx.registerCommand('expandMacro', commands.expandMacro);
ctx.registerCommand('run', commands.run);
- ctx.registerCommand('runSingle', commands.runSingle); // Internal action for lenses
+
+ // Internal commands which are invoked by the server.
+ ctx.registerCommand('runSingle', commands.runSingle);
+ ctx.registerCommand('showReferences', commands.showReferences);
function disposeOnDeactivation(disposable: vscode.Disposable) {
context.subscriptions.push(disposable);
}
- function registerCommand(name: string, f: any) {
- disposeOnDeactivation(vscode.commands.registerCommand(name, f));
- }
-
- registerCommand(
- 'rust-analyzer.showReferences',
- (uri: string, position: lc.Position, locations: lc.Location[]) => {
- vscode.commands.executeCommand(
- 'editor.action.showReferences',
- vscode.Uri.parse(uri),
- Server.client.protocol2CodeConverter.asPosition(position),
- locations.map(Server.client.protocol2CodeConverter.asLocation),
- );
- },
- );
-
if (Server.config.enableEnhancedTyping) {
ctx.overrideCommand('type', commands.onEnter);
}