Skip to content

Commit

Permalink
support new commands for codeLens
Browse files Browse the repository at this point in the history
- vala.showBaseSymbol
- vala.showHiddenSymbol
  • Loading branch information
Prince781 committed May 30, 2021
1 parent 8f825e9 commit 953d240
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 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 @@ -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",
Expand Down
41 changes: 40 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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()
}

Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down

0 comments on commit 953d240

Please sign in to comment.