From 92a81df8105a34a89c6c4fe30dfb0bc55575238e Mon Sep 17 00:00:00 2001 From: Ruben Hesselink Date: Wed, 12 Jun 2024 13:33:00 +0200 Subject: [PATCH] Add djlspPath setting for vscode extension --- vscode/README.md | 1 + vscode/client/src/extension.ts | 19 ++++++++++++------- vscode/package.json | 5 +++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/vscode/README.md b/vscode/README.md index 86e9a26..cbfc9d1 100644 --- a/vscode/README.md +++ b/vscode/README.md @@ -16,6 +16,7 @@ Then, install the `djlsp` extension from the Visual Studio Code marketplace. ## Settings Within the `settings.json` file, you can configure the following settings: +- `djangoTemplateLsp.djlspPath`: Path to the `djlsp` executable. Default: `~/.local/bin/djlsp` - `djangoTemplateLsp.dockerComposeFile`: Docker Compose file name. Default: `docker-compose.yml` - `djangoTemplateLsp.dockerServiceName`: Docker service name. Default: `django` - `djangoTemplateLsp.djangoSettingsModule`: Django settings module. Default: `` diff --git a/vscode/client/src/extension.ts b/vscode/client/src/extension.ts index fd3f3ca..6d8761f 100644 --- a/vscode/client/src/extension.ts +++ b/vscode/client/src/extension.ts @@ -18,11 +18,18 @@ export function activate(context: ExtensionContext) { return home ? filePath.replace('~', home) : filePath; }; - // Check if djlsp is installed - const djlspPaths = [ - '~/.local/bin/djlsp', - '~/.local/pipx/venvs/django-template-lsp/bin/djlsp', - ].map(expandHomeDir); + const configuration = workspace.getConfiguration('djangoTemplateLsp'); + + const djlspPaths = []; + + const djlspPathConfig = configuration.get('djlspPath', false); + + if (djlspPathConfig) { + djlspPaths.push(expandHomeDir(djlspPathConfig)); + } else { + djlspPaths.push(expandHomeDir('~/.local/bin/djlsp')); + djlspPaths.push(expandHomeDir('~/.local/pipx/venvs/django-template-lsp/bin/djlsp')); + } const djlspPath = djlspPaths.find(fs.existsSync); @@ -31,8 +38,6 @@ export function activate(context: ExtensionContext) { throw new Error('djlsp is not installed'); } - const configuration = workspace.getConfiguration('djangoTemplateLsp'); - const djlspArgs = []; if (configuration.get("enableLogging", false)) { diff --git a/vscode/package.json b/vscode/package.json index cb16f3e..8c562be 100644 --- a/vscode/package.json +++ b/vscode/package.json @@ -30,6 +30,11 @@ "type": "object", "title": "Django Template LSP", "properties": { + "djangoTemplateLsp.djlspPath": { + "type": "string", + "default": "", + "description": "The path to the djlsp executable, by default it will search for djlsp in your .local directory" + }, "djangoTemplateLsp.dockerComposeFile": { "type": "string", "default": "docker-compose.yml",