diff options
author | bscan <10503608+bscan@users.noreply.github.com> | 2024-04-05 21:06:41 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-05 21:06:41 -0400 |
commit | ddc803bc72bd7e996519899167718be758205f83 (patch) | |
tree | 1211c6c5c517f3f16385283e3bfdcff6ba36db27 /server | |
parent | 3c58ec27222fcde34874bfac7ba3c5fa77188020 (diff) | |
parent | d439d93c34778a15ea1255da469f937363006a87 (diff) | |
download | PerlNavigator-ddc803bc72bd7e996519899167718be758205f83.zip |
Merge pull request #119 from nugged/env_vars_and_tilda_in_paths
Two commits (can be cherrypicked): Custom Env vars for Perl in settings, and convert tilda to home in paths
Diffstat (limited to 'server')
-rw-r--r-- | server/src/diagnostics.ts | 24 | ||||
-rw-r--r-- | server/src/server.ts | 36 | ||||
-rw-r--r-- | server/src/types.ts | 2 |
3 files changed, 57 insertions, 5 deletions
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 4790ed0..7c5f873 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -17,6 +17,7 @@ import { TextEdit, } from "vscode-languageserver/node"; import { basename } from "path"; +import { homedir } from "os"; import { TextDocument } from "vscode-languageserver-textdocument"; import { PublishDiagnosticsParams } from "vscode-languageserver-protocol"; @@ -115,6 +116,8 @@ const defaultSettings: NavigatorSettings = { perlimportsTidyEnabled: false, perltidyEnabled: true, perlCompileEnabled: true, + perlEnv: undefined, + perlEnvAdd: true, severity5: "warning", severity4: "info", severity3: "hint", @@ -190,6 +193,19 @@ async function getWorkspaceFoldersSafe(): Promise<WorkspaceFolder[]> { } } +function expandTildePaths(paths: string, settings: NavigatorSettings): string { + const path = paths; + // Consider that this not a Windows feature, + // so, Windows "%USERPROFILE%" currently is ignored (and rarely used). + if (path.startsWith("~/")) { + const newPath = homedir() + path.slice(1); + nLog("Expanding tilde path '" + path + "' to '" + newPath + "'", settings); + return newPath; + } else { + return path; + } +} + async function getDocumentSettings(resource: string): Promise<NavigatorSettings> { if (!hasConfigurationCapability) { return globalSettings; @@ -202,6 +218,26 @@ async function getDocumentSettings(resource: string): Promise<NavigatorSettings> }); if (!result) return globalSettings; const resolvedSettings = { ...globalSettings, ...result }; + + if(resolvedSettings.includePaths) { + resolvedSettings.includePaths = resolvedSettings.includePaths.map((path: string) => expandTildePaths(path, resolvedSettings)); + } + if(resolvedSettings.perlPath) { + resolvedSettings.perlPath = expandTildePaths(resolvedSettings.perlPath, resolvedSettings); + } + if(resolvedSettings.perlimportsProfile) { + resolvedSettings.perlimportsProfile = expandTildePaths(resolvedSettings.perlimportsProfile, resolvedSettings); + } + if(resolvedSettings.perltidyProfile) { + resolvedSettings.perltidyProfile = expandTildePaths(resolvedSettings.perltidyProfile, resolvedSettings); + } + if(resolvedSettings.perlcriticProfile) { + resolvedSettings.perlcriticProfile = expandTildePaths(resolvedSettings.perlcriticProfile, resolvedSettings); + } + if(resolvedSettings.perlEnv) { + resolvedSettings.perlEnv = Object.fromEntries(Object.entries(resolvedSettings.perlEnv).map(([key, value]) => [key, expandTildePaths(value, resolvedSettings)])); + } + documentSettings.set(resource, resolvedSettings); return resolvedSettings; } 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; |