From f526ecfc7ff9abe746002db7c1f27a27a2f5ec5b Mon Sep 17 00:00:00 2001 From: Casper Meijn Date: Sat, 13 May 2023 10:08:05 +0200 Subject: [PATCH] feat: Allow `${workspaceFolder}` in `vala.languageServerPath` configuration The predefined VSCode variables [1] are not automatically substituted for configuration options. The Vala extension must do the substitution to allow the Vala language server to be relative to the workspace folder. This patch is a simplified version of the substitution in the Rust extension [2]. [1]: https://code.visualstudio.com/docs/editor/variables-reference#_predefined-variables [2]: https://github.com/rust-lang/rust-analyzer/blob/884dd8c966e29d48bd9f8e5f22440cd238aa7cf1/editors/code/src/config.ts#L399 Signed-off-by: Casper Meijn Signed-off-by: Princeton Ferro --- CHANGELOG.md | 31 +++++++++++++++++-------------- package-lock.json | 4 ++-- package.json | 2 +- src/client.ts | 15 ++++++++++++++- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12ed2e5..c17df3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,14 +1,17 @@ -# Changelog - -## 1.0.4 -- Updated grammars - -## 1.0.3 -- Add option to start server in debug mode -- Add option for server to fail on critical messages - -## 1.0.2 -- Support latest GVLS - -## 1.0.0 -- Initial release +# Changelog + +## 1.1.0 +- Allow `${workspaceFolder}` in `vala.languageServerPath` configuration + +## 1.0.4 +- Updated grammars + +## 1.0.3 +- Add option to start server in debug mode +- Add option for server to fail on critical messages + +## 1.0.2 +- Support latest GVLS + +## 1.0.0 +- Initial release diff --git a/package-lock.json b/package-lock.json index e81250c..108f3b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vala", - "version": "1.0.8", + "version": "1.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "vala", - "version": "1.0.8", + "version": "1.1.0", "license": "MIT", "dependencies": { "vscode-languageclient": "8.0.0-next.14", diff --git a/package.json b/package.json index 57f6596..5163881 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.8", + "version": "1.1.0", "publisher": "prince781", "author": { "name": "Princeton Ferro", diff --git a/src/client.ts b/src/client.ts index 087571c..92ee7f7 100644 --- a/src/client.ts +++ b/src/client.ts @@ -24,6 +24,19 @@ import { import * as which from 'which' +const VarRegex = new RegExp(/\$\{(\w+)\}/g); +function substituteVSCodeVariableInString(val: string): string { + return val.replace(VarRegex, (substring: string, varName) => { + if (varName === "workspaceFolder") { + const folders = workspace.workspaceFolders ?? []; + if (folders.length >= 1) { + return folders[0].uri.fsPath; + } + } + return substring; + }); +} + export class ValaLanguageClient { config: WorkspaceConfiguration @@ -79,7 +92,7 @@ export class ValaLanguageClient { } get languageServerPath(): string | null { - return this.config.languageServerPath + return substituteVSCodeVariableInString(this.config.languageServerPath) || which.sync('vala-language-server', { nothrow: true }) || which.sync('org.gnome.gvls.stdio.Server', { nothrow: true }) || which.sync('gvls', { nothrow: true }) // for legacy GVLS