From d631410d5b6269f756ef2715c00696fe5818557a Mon Sep 17 00:00:00 2001 From: Jon Janzen Date: Mon, 22 Jun 2020 21:28:32 -0700 Subject: [PATCH 1/2] Support hack root in an arbitrary subdirectory --- package.json | 7 ++++++- src/Config.ts | 1 + src/Utils.ts | 9 ++++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index c410438..c20a1a1 100755 --- a/package.json +++ b/package.json @@ -196,6 +196,11 @@ "default": "hh_client", "description": "Absolute path to the hh_client executable. This can be left empty if hh_client is already in your environment $PATH." }, + "hack.rootPath": { + "type": "string", + "default": "", + "description": "Relative path to the directory containing .hhconfig" + }, "hack.workspaceRootPath": { "type": "string", "default": null, @@ -311,7 +316,7 @@ ] }, "activationEvents": [ - "workspaceContains:.hhconfig", + "workspaceContains:**/.hhconfig", "onDebug" ], "scripts": { diff --git a/src/Config.ts b/src/Config.ts index b074db8..8f206db 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -10,6 +10,7 @@ const hackConfig = vscode.workspace.getConfiguration("hack"); // tslint:disable-next-line:no-non-null-assertion export const localWorkspacePath = vscode.workspace.workspaceFolders![0].uri .fsPath; +export const workspaceRelativeRootPath = hackConfig.get("rootPath") || ""; export let clientPath = hackConfig.get("clientPath") || "hh_client"; clientPath = clientPath.replace("${workspaceFolder}", localWorkspacePath); diff --git a/src/Utils.ts b/src/Utils.ts index 75d4633..54a6cfe 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -12,12 +12,11 @@ import * as config from "./Config"; * @param includeScheme Whether to include the file:// scheme in the response or not */ export const mapFromWorkspaceUri = (file: vscode.Uri): string => { - if (!config.remoteEnabled || !config.remoteWorkspacePath) { - return file.toString(); + let workspaceRoot = file.toString() + if (config.remoteEnabled && config.remoteWorkspacePath) { + workspaceRoot = workspaceRoot.replace(config.localWorkspacePath, config.remoteWorkspacePath); } - return file - .toString() - .replace(config.localWorkspacePath, config.remoteWorkspacePath); + return workspaceRoot + "/" + config.workspaceRelativeRootPath; }; /** From c4da7035979a70763484157cd869526932525381 Mon Sep 17 00:00:00 2001 From: Jon Janzen Date: Sun, 28 Mar 2021 19:40:39 -0700 Subject: [PATCH 2/2] Switch to hhconfigPath config option --- package.json | 6 +++--- src/Config.ts | 2 +- src/Utils.ts | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index c20a1a1..9fb8d25 100755 --- a/package.json +++ b/package.json @@ -196,10 +196,10 @@ "default": "hh_client", "description": "Absolute path to the hh_client executable. This can be left empty if hh_client is already in your environment $PATH." }, - "hack.rootPath": { + "hack.hhconfigPath": { "type": "string", - "default": "", - "description": "Relative path to the directory containing .hhconfig" + "default": ".hhconfig", + "description": "Workspace-relative path to .hhconfig file, the containing directory becomes the Hack Langauge Server root" }, "hack.workspaceRootPath": { "type": "string", diff --git a/src/Config.ts b/src/Config.ts index 8f206db..4f1e8a5 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -10,7 +10,7 @@ const hackConfig = vscode.workspace.getConfiguration("hack"); // tslint:disable-next-line:no-non-null-assertion export const localWorkspacePath = vscode.workspace.workspaceFolders![0].uri .fsPath; -export const workspaceRelativeRootPath = hackConfig.get("rootPath") || ""; +export const hhconfigPath = hackConfig.get("hhconfigPath") || ".hhconfig"; export let clientPath = hackConfig.get("clientPath") || "hh_client"; clientPath = clientPath.replace("${workspaceFolder}", localWorkspacePath); diff --git a/src/Utils.ts b/src/Utils.ts index 54a6cfe..014015e 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -16,7 +16,8 @@ export const mapFromWorkspaceUri = (file: vscode.Uri): string => { if (config.remoteEnabled && config.remoteWorkspacePath) { workspaceRoot = workspaceRoot.replace(config.localWorkspacePath, config.remoteWorkspacePath); } - return workspaceRoot + "/" + config.workspaceRelativeRootPath; + const workspaceRelativeRoot = config.hhconfigPath.replace(/\.hhconfig$/, "") + return workspaceRoot + "/" + workspaceRelativeRoot.replace(".hhconfig", ""); }; /**