From 8b4cfcf32739f481500a3ff7429d634c374d9610 Mon Sep 17 00:00:00 2001 From: stefan toubia Date: Fri, 6 Mar 2020 21:23:32 -0800 Subject: [PATCH] Add projectRootDir setting --- CHANGELOG.md | 1 + package.json | 4 ++++ src/nrepl/connectSequence.ts | 5 +++-- src/nrepl/jack-in.ts | 4 ++++ src/state.ts | 7 +++++-- 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cfacc640..63485740d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Changes to Calva. ## [Unreleased] +- Add replConnectSequences.menuSelections.projectRootDir for manually specifying the root directory in order to support jack-in for monorepo projects. - Fix so that Calva treats symbol containing the quote character correctly. - [Fix: Parameter hints popup should be off by default](https://github.com/BetterThanTomorrow/calva/issues/574) diff --git a/package.json b/package.json index eed81a3a7..848773641 100644 --- a/package.json +++ b/package.json @@ -414,6 +414,10 @@ "cljsDefaultBuild": { "type": "string", "description": "Which cljs build to attach to at the initial connect." + }, + "projectRootDir": { + "type": "string", + "descripion": "Defines the project root directory. Useful for working with monorepos." } } }, diff --git a/src/nrepl/connectSequence.ts b/src/nrepl/connectSequence.ts index 7acec0e09..1b5b058ef 100644 --- a/src/nrepl/connectSequence.ts +++ b/src/nrepl/connectSequence.ts @@ -38,7 +38,8 @@ interface MenuSelections { leinAlias?: string, cljAliases?: string[], cljsLaunchBuilds?: string[], - cljsDefaultBuild?: string + cljsDefaultBuild?: string, + projectRootDir?: string, } interface ReplConnectSequence { @@ -242,4 +243,4 @@ export { CljsTypes, ReplConnectSequence, CljsTypeConfig -} \ No newline at end of file +} diff --git a/src/nrepl/jack-in.ts b/src/nrepl/jack-in.ts index 089f1f9a8..37019c95a 100644 --- a/src/nrepl/jack-in.ts +++ b/src/nrepl/jack-in.ts @@ -41,6 +41,10 @@ function cancelJackInTask() { } async function executeJackInTask(projectType: projectTypes.ProjectType, projectTypeSelection: any, executable: string, args: any, cljTypes: string[], outputChannel: vscode.OutputChannel, connectSequence: ReplConnectSequence) { + // If the connection sequence specifies a project root dir, override the existing project dir + const projectRootDir = connectSequence?.menuSelections?.projectRootDir; + if(projectRootDir) state.setProjectRoot(projectRootDir); + utilities.setLaunchingState(projectTypeSelection); statusbar.update(); const nReplPortFile = projectTypes.nreplPortFile(connectSequence); diff --git a/src/state.ts b/src/state.ts index 949baf3ea..e4ef100e7 100644 --- a/src/state.ts +++ b/src/state.ts @@ -156,6 +156,10 @@ export function getProjectRoot(useCache = true): string { } } +export function setProjectRoot(rootPath: string) { + cursor.set(PROJECT_DIR_KEY, rootPath); +} + export function getProjectWsFolder(): vscode.WorkspaceFolder { const doc = util.getDocument({}); return doc ? vscode.workspace.getWorkspaceFolder(doc.uri) : null; @@ -173,7 +177,6 @@ export function getProjectWsFolder(): vscode.WorkspaceFolder { * by looking for project files from the file's directory and up to * the window root (for plain folder windows) or the file's * workspace folder root (for workspaces) to find the project root. - * * If there is no project file found, throw an exception. */ export async function initProjectDir(): Promise { @@ -223,7 +226,7 @@ export async function initProjectDir(): Promise { for (let projectFile in projectFileNames) { const p = path.resolve(rootPath, projectFileNames[projectFile]); if (fs.existsSync(p)) { - cursor.set(PROJECT_DIR_KEY, rootPath); + setProjectRoot(rootPath); return; } }