Skip to content

Commit

Permalink
Merge pull request #238 from pro-vision/feature/vscode-hbs-errors
Browse files Browse the repository at this point in the history
vscode hbs plugin, additional features
  • Loading branch information
friewerts authored Nov 26, 2024
2 parents f65d7b7 + 281d93a commit 4256ed6
Show file tree
Hide file tree
Showing 20 changed files with 3,363 additions and 1,384 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { commands, window, Location, Uri, Range, Position } from "vscode";
import { type Location as LSLocation } from "vscode-languageclient/node";

/**
* converts locations of type vscode-languageclient/node to `Location` from `vscode` (client) extension
*
* @param {LSLocation} locations - code locations
* @returns {Location}
*/
function castLocationsType({ uri, range }: LSLocation) {
return new Location(
Uri.file(uri),
new Range(new Position(range.start.line, range.start.character), new Position(range.end.line, range.end.character)),
);
}

// trigger vscode build-in command to navigate to the given code location(s)
export function goToLocation(location: LSLocation) {
commands.executeCommand(
"editor.action.goToLocations",
window.activeTextEditor.document.uri, // from
window.activeTextEditor.selection.active,
[castLocationsType(location)], // to
"peek", // for multiple options (if we use LSLocation[]), show the list and allow the user to choose
"",
);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as path from "path";
import type { ExtensionContext } from "vscode";
import { type ExtensionContext, commands } from "vscode";
import { LanguageClient, TransportKind } from "vscode-languageclient/node";
import type { LanguageClientOptions, ServerOptions } from "vscode-languageclient/node";
import { goToLocation } from "./commands";

let client: LanguageClient;

Expand All @@ -25,8 +26,11 @@ export function activate(context: ExtensionContext): void {

// Options to control the language client
const clientOptions: LanguageClientOptions = {
// Register the server for Handlebars documents
documentSelector: [{ scheme: "file", language: "handlebars" }],
// Register the server for Handlebars documents and Typescript
documentSelector: [
{ scheme: "file", language: "handlebars" },
{ scheme: "file", language: "typescript" },
],
};

// Create the language client and start the client.
Expand All @@ -39,6 +43,10 @@ export function activate(context: ExtensionContext): void {

// Start the client. This will also launch the server
client.start();

// running "editor.action.goToLocations" command directly in server code didn't work,
// custom command to get the arguments and execute command from the client code
commands.registerCommand("P!VHandlebarsLanguageServer.codelensAction", goToLocation);
}

export function deactivate(): Thenable<void> | undefined {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "es2019",
"lib": ["ES2019"],
"target": "ESNext",
"lib": ["ESNext"],
"module": "commonjs",
"moduleResolution": "node",
"outDir": "out",
Expand Down
Loading

0 comments on commit 4256ed6

Please sign in to comment.