summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrii Nugged <nugged@gmail.com>2024-03-21 05:33:09 +0200
committerAndrii Nugged <nugged@gmail.com>2024-03-22 05:50:46 +0200
commitd439d93c34778a15ea1255da469f937363006a87 (patch)
treef5ef644f69e4fbfc5cf5bb0382135d75d99865f9
parent9637df5a2d8a8d4d64912ee79d695340cee3def2 (diff)
downloadPerlNavigator-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.md4
-rw-r--r--server/src/server.ts34
2 files changed, 38 insertions, 0 deletions
diff --git a/README.md b/README.md
index d2b9009..ec09cd5 100644
--- a/README.md
+++ b/README.md
@@ -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;
}