From 953d24089d5ceeeba5df4447a4cc3bd8dcacade0 Mon Sep 17 00:00:00 2001 From: Princeton Ferro Date: Sun, 30 May 2021 17:53:22 -0400 Subject: [PATCH] support new commands for codeLens - vala.showBaseSymbol - vala.showHiddenSymbol --- package-lock.json | 4 ++-- package.json | 2 +- src/client.ts | 41 ++++++++++++++++++++++++++++++++++++++++- src/main.ts | 2 +- 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 660f9ed..56a7a39 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vala", - "version": "1.0.4", + "version": "1.0.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "vala", - "version": "1.0.4", + "version": "1.0.5", "license": "MIT", "dependencies": { "vscode-languageclient": "^5.2.1", diff --git a/package.json b/package.json index 2b33869..d40fd9e 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vala", "displayName": "Vala", "description": "Syntax highlighting and language support for the Vala / Genie languages", - "version": "1.0.4", + "version": "1.0.5", "publisher": "prince781", "author": { "name": "Princeton Ferro", diff --git a/src/client.ts b/src/client.ts index 1b713eb..9fda4b0 100644 --- a/src/client.ts +++ b/src/client.ts @@ -3,13 +3,23 @@ import { LanguageClientOptions, ServerOptions, TransportKind, - RevealOutputChannelOn + RevealOutputChannelOn, } from 'vscode-languageclient'; +// import LSP types +import * as lsp from 'vscode-languageclient'; + import { ExtensionContext, workspace, window, + commands, + TextEditor, + TextEditorEdit, + Uri, + Location, + Position, + Range } from 'vscode' import * as which from 'which' @@ -67,6 +77,9 @@ export class ValaLanguageClient { this.ls = new LanguageClient('Vala Language Server', serverOptions, clientOptions) + commands.registerTextEditorCommand('vala.showBaseSymbol', this.peekSymbol); + commands.registerTextEditorCommand('vala.showHiddenSymbol', this.peekSymbol); + this.ls.start() } @@ -83,6 +96,32 @@ export class ValaLanguageClient { || which.sync('gvls', { nothrow: true }) // for legacy GVLS } + peekSymbol(editor: TextEditor, edit: TextEditorEdit, lspCurrentLocation: lsp.Location, lspTargetLocation: lsp.Location): void { + let currentLocation = new Location( + Uri.parse(lspCurrentLocation.uri), + new Range( + new Position(lspCurrentLocation.range.start.line, lspCurrentLocation.range.start.character), + new Position(lspCurrentLocation.range.end.line, lspCurrentLocation.range.end.character) + ) + ); + let targetLocation = new Location( + Uri.parse(lspTargetLocation.uri), + new Range( + new Position(lspTargetLocation.range.start.line, lspTargetLocation.range.start.character), + new Position(lspTargetLocation.range.end.line, lspTargetLocation.range.end.character) + ) + ); + + commands.executeCommand( + 'editor.action.peekLocations', + currentLocation.uri, // anchor uri and position + currentLocation.range.end, + [targetLocation], // results (vscode.Location[]) + 'peek', // mode ('peek' | 'gotoAndPeek' | 'goto') + 'Nothing found' // <- message + ); + } + dispose() { if (this.ls) { this.ls!.stop() diff --git a/src/main.ts b/src/main.ts index b98e8a2..b92eb6e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,7 +1,7 @@ import * as path from 'path' import { spawn } from 'child_process' -import { ExtensionContext, languages, IndentAction } from 'vscode' +import { ExtensionContext, languages, IndentAction, commands } from 'vscode' import { ValaLanguageClient } from './client'