diff options
author | Andrii Nugged <nugged@gmail.com> | 2024-03-21 05:33:09 +0200 |
---|---|---|
committer | Andrii Nugged <nugged@gmail.com> | 2024-03-22 05:50:46 +0200 |
commit | d439d93c34778a15ea1255da469f937363006a87 (patch) | |
tree | f5ef644f69e4fbfc5cf5bb0382135d75d99865f9 | |
parent | 9637df5a2d8a8d4d64912ee79d695340cee3def2 (diff) | |
download | PerlNavigator-d439d93c34778a15ea1255da469f937363006a87.zip |
Add support for expanding leading tildas in paths
This commit introduces functionality to expand leading tildas (~) in paths. The tilde is a common shorthand for the home directory in Unix-like operating systems, and this change allows our application to interpret and handle these paths correctly.
Previously, if a user entered a path with a leading tilde, the application would not recognize it as a valid path. With this update, the application will now expand any leading tilde to the current user's home directory, allowing for more flexible and intuitive path input.
This change improves the user experience by accepting a wider range of valid inputs and aligns the application's path handling behavior with established conventions in Unix-like operating systems.
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | server/src/server.ts | 34 |
2 files changed, 38 insertions, 0 deletions
@@ -88,11 +88,15 @@ Sublime Text requires the following minimum settings under LSP settings (modify "selector": "source.perl", }, "settings": { + // "perlnavigator.perltidyProfile": "~/.perltidyrc", + // "perlnavigator.perlcriticProfile": "~/.perlcriticrc", // "perlnavigator.perlEnvAdd": false, // default: true // "perlnavigator.perlEnv": { // "KOHA_CONF": "/home/user/git/KohaCommunity/t/data/koha-conf.xml", // }, + // "perlnavigator.perlPath": "~/perl5/perlbrew/perls/perl-5.38.2/bin", // "perlnavigator.perlcriticSeverity": 1, + // "perlnavigator.includePaths": [ "~/git/KohaCommunity", "~/git/KohaCommunity/lib" ], // "perlnavigator.perlcriticEnabled": true, // "perlnavigator.enableWarnings": true, }, diff --git a/server/src/server.ts b/server/src/server.ts index 5803b81..5d99ca3 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"; @@ -192,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; @@ -204,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; } |