From 20e6e2154b045ab56fedbc8769d03633acfd12e0 Mon Sep 17 00:00:00 2001 From: Shunsuke Shibayama Date: Sat, 25 Feb 2023 23:58:06 +0900 Subject: [PATCH] feat: add command `erg.showReferences` --- package-lock.json | 4 ++-- package.json | 2 +- src/commands.ts | 19 +++++++++++++++++++ src/extension.ts | 10 +++++++--- 4 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 src/commands.ts diff --git a/package-lock.json b/package-lock.json index 9a98e7f..50545b5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vscode-erg", - "version": "0.1.9", + "version": "0.1.11", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "vscode-erg", - "version": "0.1.9", + "version": "0.1.11", "dependencies": { "vscode-languageclient": "^8.0.2" }, diff --git a/package.json b/package.json index 1a57b05..7ff9adc 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/src/commands.ts b/src/commands.ts new file mode 100644 index 0000000..efc7194 --- /dev/null +++ b/src/commands.ts @@ -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) + ); + } +} diff --git a/src/extension.ts b/src/extension.ts index 33293a1..3c0e2a3 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -5,6 +5,7 @@ import { ServerOptions, } from "vscode-languageclient/node"; import { spawn } from "child_process"; +import { showReferences } from "./commands"; let client: LanguageClient | undefined; @@ -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); }