diff --git a/package-lock.json b/package-lock.json index c7e2a30..12d672f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "name": "vscode-ddp", "version": "0.0.6", "dependencies": { + "lookpath": "^1.2.2", "vscode-languageclient": "^7.0.0" }, "devDependencies": { @@ -1592,6 +1593,17 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/lookpath": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/lookpath/-/lookpath-1.2.2.tgz", + "integrity": "sha512-k2Gmn8iV6qdME3ztZC2spubmQISimFOPLuQKiPaLcVdRz0IpdxrNClVepMlyTJlhodm/zG/VfbkWERm3kUIh+Q==", + "bin": { + "lookpath": "bin/lookpath.js" + }, + "engines": { + "npm": ">=6.13.4" + } + }, "node_modules/lru-cache": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", @@ -3665,6 +3677,11 @@ "is-unicode-supported": "^0.1.0" } }, + "lookpath": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/lookpath/-/lookpath-1.2.2.tgz", + "integrity": "sha512-k2Gmn8iV6qdME3ztZC2spubmQISimFOPLuQKiPaLcVdRz0IpdxrNClVepMlyTJlhodm/zG/VfbkWERm3kUIh+Q==" + }, "lru-cache": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", diff --git a/package.json b/package.json index de357cf..f60d27d 100644 --- a/package.json +++ b/package.json @@ -88,6 +88,11 @@ "default": "", "description": "if present this DDPLS binary is used instead of the one shipped with the extension or the global one" }, + "ddp.DDPLS.useSystemwideInstall": { + "type": "boolean", + "default": false, + "description": "if true the system-wide installed DDPLS is used instead of the one shipped with the extension" + }, "ddp.DDPLS.flags": { "type": "array", "default": [], @@ -106,6 +111,7 @@ } }, "dependencies": { + "lookpath": "^1.2.2", "vscode-languageclient": "^7.0.0" }, "scripts": { @@ -128,4 +134,4 @@ "mocha": "^10.0.0", "typescript": "^4.7.2" } -} \ No newline at end of file +} diff --git a/src/extension.ts b/src/extension.ts index a783e34..c41b241 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -5,10 +5,11 @@ import * as langsrv from 'vscode-languageclient/node'; import * as path from 'path'; import * as os from 'os'; import * as fs from 'fs'; +import { lookpath } from 'lookpath'; let DDPPATH = process.env.DDPPATH; -export function activate(ctx: vscode.ExtensionContext) { +export async function activate(ctx: vscode.ExtensionContext) { console.log('ddp extension activated'); let out = vscode.window.createOutputChannel("vscode-ddp", "ddp"); @@ -20,29 +21,39 @@ export function activate(ctx: vscode.ExtensionContext) { let config = vscode.workspace.getConfiguration('ddp'); - let commandName = "DDPLS"; + let ddplsCommand = os.platform() === 'win32' ? 'DDPLS.exe' : 'DDPLS'; { - let ddplsPath = ctx.asAbsolutePath(path.join('bin', os.platform() === 'win32' ? 'DDPLS.exe' : 'DDPLS')); - out.appendLine("bundled ddplsPath: " + ddplsPath); + let ddplsPath = ctx.asAbsolutePath(path.join('bin', ddplsCommand)); if (fs.existsSync(ddplsPath)) { - out.appendLine("using bundled DDPLS"); - out.appendLine(ddplsPath); - commandName = ddplsPath; + out.appendLine("found bundled DDPLS: " + ddplsPath); + ddplsCommand = ddplsPath; + } + } + { + let useSystemLs = config.get("DDPLS.useSystemwideInstall"); + if (useSystemLs === true) { + let ddplsPath = await lookpath('DDPLS'); + if (ddplsPath !== undefined) { + out.appendLine("using system-wide DDPLS: " + ddplsPath); + ddplsCommand = ddplsPath; + } else { + out.appendLine("no system-wide DDPLS found, falling back to bundled DDPLS"); + } } } { let ddplsPath = config.get("DDPLS.path"); if (ddplsPath !== "" && ddplsPath !== undefined) { - out.appendLine("using custom DDPLS path"); - commandName = ddplsPath; + out.appendLine("using custom DDPLS path: " + ddplsPath); + ddplsCommand = ddplsPath; } } let lsArgs = config.get("DDPLS.flags"); // DDPLS must be installed and in the PATH let serverOptions: langsrv.ServerOptions = { - run: { command: commandName, args: lsArgs }, - debug: { command: commandName, args: lsArgs } + run: { command: ddplsCommand, args: lsArgs }, + debug: { command: ddplsCommand, args: lsArgs } }; let clientOptions: langsrv.LanguageClientOptions = {