Skip to content

Commit

Permalink
feat: add command erg.showReferences
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Feb 25, 2023
1 parent 573ac23 commit 20e6e21
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "vscode-erg",
"description": "Erg language support for Visual Studio Code",
"publisher": "erg-lang",
"version": "0.1.10",
"version": "0.1.11",
"engines": {
"vscode": "^1.70.0"
},
Expand Down
19 changes: 19 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// copied and modified from https://github.com/rust-lang/rust-analyzer/blob/27239fbb58a115915ffc1ce65ededc951eb00fd2/editors/code/src/commands.ts
import { LanguageClient, Location, Position } from 'vscode-languageclient/node';
import { Uri, commands } from 'vscode';

export async function showReferences(
client: LanguageClient | undefined,
uri: string,
position: Position,
locations: Location[]
) {
if (client) {
await commands.executeCommand(
"editor.action.showReferences",
Uri.parse(uri),
client.protocol2CodeConverter.asPosition(position),
locations.map(client.protocol2CodeConverter.asLocation)
);
}
}
10 changes: 7 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ServerOptions,
} from "vscode-languageclient/node";
import { spawn } from "child_process";
import { showReferences } from "./commands";

let client: LanguageClient | undefined;

Expand Down Expand Up @@ -85,9 +86,12 @@ async function restartLanguageClient() {

export async function activate(context: ExtensionContext) {
context.subscriptions.push(
commands.registerCommand("erg.restartLanguageServer", () =>
restartLanguageClient(),
),
commands.registerCommand("erg.restartLanguageServer", () => restartLanguageClient())
);
context.subscriptions.push(
commands.registerCommand("erg.showReferences", async (uri, position, locations) => {
await showReferences(client, uri, position, locations)
})
);
await startLanguageClient(context);
}
Expand Down

0 comments on commit 20e6e21

Please sign in to comment.