From d631410d5b6269f756ef2715c00696fe5818557a Mon Sep 17 00:00:00 2001 From: Jon Janzen Date: Mon, 22 Jun 2020 21:28:32 -0700 Subject: [PATCH] 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; }; /**