diff options
author | Andrii Nugged <nugged@gmail.com> | 2024-03-22 05:05:58 +0200 |
---|---|---|
committer | Andrii Nugged <nugged@gmail.com> | 2024-03-22 05:07:16 +0200 |
commit | 9637df5a2d8a8d4d64912ee79d695340cee3def2 (patch) | |
tree | 16ec8ab69464704f08594b7df1a3927eb178cda7 | |
parent | 1f3e38e74277f1f95b6a4a10012a71eb9826b109 (diff) | |
download | PerlNavigator-9637df5a2d8a8d4d64912ee79d695340cee3def2.zip |
Add support for custom Perl environment variables
Introduced two new environment variables: perlEnv and perlEnvAdd.
- perlEnv: Hash. Pass environment variables to the perl executable. Skipped if undefined.
- perlEnvAdd: Boolean. Add environment variables to current environment, or totally replace (perlEnv related). Default is true.
-rw-r--r-- | README.md | 9 | ||||
-rw-r--r-- | package.json | 12 | ||||
-rw-r--r-- | server/src/diagnostics.ts | 24 | ||||
-rw-r--r-- | server/src/server.ts | 2 | ||||
-rw-r--r-- | server/src/types.ts | 2 |
5 files changed, 44 insertions, 5 deletions
@@ -87,6 +87,15 @@ Sublime Text requires the following minimum settings under LSP settings (modify "command": ["node", "C:\\temp\\PerlNavigator\\server\\out\\server.js","--stdio"], "selector": "source.perl", }, + "settings": { + // "perlnavigator.perlEnvAdd": false, // default: true + // "perlnavigator.perlEnv": { + // "KOHA_CONF": "/home/user/git/KohaCommunity/t/data/koha-conf.xml", + // }, + // "perlnavigator.perlcriticSeverity": 1, + // "perlnavigator.perlcriticEnabled": true, + // "perlnavigator.enableWarnings": true, + }, } } ``` diff --git a/package.json b/package.json index 58b4946..7429b64 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,18 @@ "default": [], "description": "Pass miscellaneous command line arguments to pass to the perl executable" }, + "perlnavigator.perlEnv": { + "scope": "resource", + "type": "object", + "default": {}, + "description": "Pass environment variables to the perl executable. Skipped if undefined." + }, + "perlnavigator.perlEnvAdd": { + "scope": "resource", + "type": "boolean", + "default": true, + "description": "Add environment variables to current environment, or totally replace (perlEnv related)." + }, "perlnavigator.enableWarnings": { "scope": "resource", "type": "boolean", diff --git a/server/src/diagnostics.ts b/server/src/diagnostics.ts index 64eec17..94618b9 100644 --- a/server/src/diagnostics.ts +++ b/server/src/diagnostics.ts @@ -19,6 +19,8 @@ export async function perlcompile(textDocument: TextDocument, workspaceFolders: return { diags: [], perlDoc: parsedDoc }; } let perlParams: string[] = [...settings.perlParams, "-c"]; + let perlEnv = settings.perlEnv; + let perlEnvAdd = settings.perlEnvAdd; const filePath = Uri.parse(textDocument.uri).fsPath; if (settings.enableWarnings) perlParams = perlParams.concat(["-Mwarnings", "-M-warnings=redefine"]); // Force enable some warnings. @@ -33,14 +35,26 @@ export async function perlcompile(textDocument: TextDocument, workspaceFolders: const diagnostics: Diagnostic[] = []; const code = getAdjustedPerlCode(textDocument, filePath); try { - const process = async_execFile(settings.perlPath, perlParams, { timeout: 10000, maxBuffer: 20 * 1024 * 1024 }); - process?.child?.stdin?.on("error", (error: any) => { + let options: { + timeout: number; + maxBuffer: number; + env?: { [key: string]: string | undefined }; + } = { timeout: 10000, maxBuffer: 20 * 1024 * 1024 }; + if (perlEnv) { + if (perlEnvAdd) { + options.env = { ...process.env, ...perlEnv }; + } else { + options.env = perlEnv; + } + } + const perlProcess = async_execFile(settings.perlPath, perlParams, options); + perlProcess?.child?.stdin?.on("error", (error: any) => { nLog("Perl Compilation Error Caught: ", settings); nLog(error, settings); }); - process?.child?.stdin?.write(code); - process?.child?.stdin?.end(); - const out = await process; + perlProcess?.child?.stdin?.write(code); + perlProcess?.child?.stdin?.end(); + const out = await perlProcess; output = out.stderr; stdout = out.stdout; diff --git a/server/src/server.ts b/server/src/server.ts index 2c33819..5803b81 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -115,6 +115,8 @@ const defaultSettings: NavigatorSettings = { perlimportsTidyEnabled: false, perltidyEnabled: true, perlCompileEnabled: true, + perlEnv: undefined, + perlEnvAdd: true, severity5: "warning", severity4: "info", severity3: "hint", diff --git a/server/src/types.ts b/server/src/types.ts index bf4394f..01ac28a 100644 --- a/server/src/types.ts +++ b/server/src/types.ts @@ -20,6 +20,8 @@ export interface NavigatorSettings { perltidyEnabled: boolean; perltidyProfile: string; perlCompileEnabled: boolean; + perlEnv: undefined | { [key: string]: string }; + perlEnvAdd: boolean; severity5: string; severity4: string; severity3: string; |