From 91521cd895a1ce14def4c8d63fbf6ad2c8ac6b39 Mon Sep 17 00:00:00 2001 From: stefan toubia Date: Fri, 6 Mar 2020 21:23:32 -0800 Subject: [PATCH 1/4] 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 eb08f6851..b1949f968 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Changes to Calva. ## [Unreleased] ## [2.0.80] - 2020-03-07 +- Add replConnectSequences.menuSelections.projectRootDir for manually specifying the root directory in order to support jack-in for monorepo projects. - Fix so that Paredit treats symbols containing the quote character correctly. - [Fix: Parameter hints popup should be off by default](https://github.com/BetterThanTomorrow/calva/issues/574) - [Fix: `nil` followed by comma not highlighted correctly](https://github.com/BetterThanTomorrow/calva/issues/577) diff --git a/package.json b/package.json index 9ec29eb4a..2070ce2d0 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; } } From 3a3367e46ae5f1e80d5203f2d0a5fbc64e662563 Mon Sep 17 00:00:00 2001 From: stefan toubia Date: Sat, 7 Mar 2020 14:38:49 -0800 Subject: [PATCH 2/4] Update docs --- docs/readthedocs/source/connect-sequences.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/readthedocs/source/connect-sequences.md b/docs/readthedocs/source/connect-sequences.md index 515260bf8..7943f328d 100644 --- a/docs/readthedocs/source/connect-sequences.md +++ b/docs/readthedocs/source/connect-sequences.md @@ -33,6 +33,7 @@ A connect sequence configures the following: * `cljAliases`: At Jack-in to a Clojure CLI project, use these aliases to launch the repl. * `cljsLaunchBuilds`: The cljs builds to start/watch at Jack-in/connect. * `cljsDefaultBuild`: Which cljs build to attach to at the initial connect. + * `projectRootDir`: The root directory to execute the Jack-in command from. This will override the default behavior for determining the root directory relative to the current open file. This is useful for working in monorepos. The [Calva built-in sequences](https://github.com/BetterThanTomorrow/calva/blob/master/calva/nrepl/connectSequence.ts) also uses this format, check them out to get a clearer picture of how these settings work. From 22188102a6ef8d1c3cde7c798a4a61ce2c961b93 Mon Sep 17 00:00:00 2001 From: stefan toubia Date: Sun, 8 Mar 2020 19:29:04 -0700 Subject: [PATCH 3/4] Move rootProjectDir to root of replConnectSequences --- docs/readthedocs/source/connect-sequences.md | 2 +- package.json | 9 +++++---- src/nrepl/connectSequence.ts | 2 +- src/nrepl/jack-in.ts | 2 +- src/state.ts | 1 + 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/readthedocs/source/connect-sequences.md b/docs/readthedocs/source/connect-sequences.md index 7943f328d..e02af2fe8 100644 --- a/docs/readthedocs/source/connect-sequences.md +++ b/docs/readthedocs/source/connect-sequences.md @@ -16,6 +16,7 @@ A connect sequence configures the following: * `projectType`: (required) This is either "Leiningen”, ”Clojure-CLI”, or ”shadow-cljs”. * `nReplPortFile`: An array of path segments with the project root-relative path to the nREPL port file for this connect sequence. E.g. For shadow-cljs this would be `[".shadow-cljs", "nrepl.port"]`. * `afterCLJReplJackInCode`: Here you can give Calva some Clojure code to evaluate in the CLJ REPL, once it has been created. +* `projectRootDir`: The root directory to execute the Jack-in command from. This will override the default behavior for determining the root directory relative to the current open file. This is useful for working in monorepos. * `cljsType`: This can be either "Figwheel Main", "lein-figwheel", "shadow-cljs", "Nashorn", or a dictionary configuring a custom type. If omitted, Calva will skip connecting a ClojureScript repl. A custom type has the following fields: * `dependsOn`: (required) Calva will use this to determine which dependencies it will add when starting the project (Jacking in). This can be either "Figwheel Main", "lein-figwheel", "shadow-cljs", "Nashorn", or ”User provided”. If it is "User provided", then you need to provide the dependencies in the project, or launch with an alias (deps.edn), profile (Leiningen), or build (shadow-cljs) that provides the dependencies needed. * `isStarted`: Boolean. For CLJS REPLs that Calva does not need to start, set this to true. (If you base your custom cljs repl on a shadow-cljs workflow, for instance.) @@ -33,7 +34,6 @@ A connect sequence configures the following: * `cljAliases`: At Jack-in to a Clojure CLI project, use these aliases to launch the repl. * `cljsLaunchBuilds`: The cljs builds to start/watch at Jack-in/connect. * `cljsDefaultBuild`: Which cljs build to attach to at the initial connect. - * `projectRootDir`: The root directory to execute the Jack-in command from. This will override the default behavior for determining the root directory relative to the current open file. This is useful for working in monorepos. The [Calva built-in sequences](https://github.com/BetterThanTomorrow/calva/blob/master/calva/nrepl/connectSequence.ts) also uses this format, check them out to get a clearer picture of how these settings work. diff --git a/package.json b/package.json index 2070ce2d0..ec955d924 100644 --- a/package.json +++ b/package.json @@ -375,6 +375,11 @@ "description": "Here you can give Calva some Clojure code to evaluate in the CLJ REPL, once it has been created.", "required": false }, + "projectRootDir": { + "type": "string", + "descripion": "Defines the project root directory. Useful for working with monorepos.", + "required": false + }, "menuSelections": { "type": "object", "description": "Pre-selected menu options. If a slection is made here. Calva won't prompt for it.", @@ -414,10 +419,6 @@ "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 1b5b058ef..5bfa81643 100644 --- a/src/nrepl/connectSequence.ts +++ b/src/nrepl/connectSequence.ts @@ -39,13 +39,13 @@ interface MenuSelections { cljAliases?: string[], cljsLaunchBuilds?: string[], cljsDefaultBuild?: string, - projectRootDir?: string, } interface ReplConnectSequence { name: string, projectType: ProjectTypes, afterCLJReplJackInCode?: string, + projectRootDir?: string, cljsType: CljsTypes | CljsTypeConfig, menuSelections?: MenuSelections, nReplPortFile?: string[] diff --git a/src/nrepl/jack-in.ts b/src/nrepl/jack-in.ts index 37019c95a..c740be710 100644 --- a/src/nrepl/jack-in.ts +++ b/src/nrepl/jack-in.ts @@ -42,7 +42,7 @@ 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; + const projectRootDir = connectSequence?.projectRootDir; if(projectRootDir) state.setProjectRoot(projectRootDir); utilities.setLaunchingState(projectTypeSelection); diff --git a/src/state.ts b/src/state.ts index e4ef100e7..04d3af8bb 100644 --- a/src/state.ts +++ b/src/state.ts @@ -177,6 +177,7 @@ 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 { From abcf4736eb1257702e36cee24c9ad1881710a9b3 Mon Sep 17 00:00:00 2001 From: stefan toubia Date: Tue, 10 Mar 2020 19:14:06 -0700 Subject: [PATCH 4/4] PR fixes --- CHANGELOG.md | 2 +- package.json | 2 +- src/nrepl/jack-in.ts | 8 +++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1949f968..a3e68f4a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,9 @@ Changes to Calva. ## [Unreleased] +- [Add option to manually specify project root directory](https://github.com/BetterThanTomorrow/calva/issues/579) ## [2.0.80] - 2020-03-07 -- Add replConnectSequences.menuSelections.projectRootDir for manually specifying the root directory in order to support jack-in for monorepo projects. - Fix so that Paredit treats symbols containing the quote character correctly. - [Fix: Parameter hints popup should be off by default](https://github.com/BetterThanTomorrow/calva/issues/574) - [Fix: `nil` followed by comma not highlighted correctly](https://github.com/BetterThanTomorrow/calva/issues/577) diff --git a/package.json b/package.json index ec955d924..f71c9c149 100644 --- a/package.json +++ b/package.json @@ -377,7 +377,7 @@ }, "projectRootDir": { "type": "string", - "descripion": "Defines the project root directory. Useful for working with monorepos.", + "descripion": "The root directory to execute the Jack-in command from. This will override the default behavior for determining the root directory relative to the current open file. This is useful for working in monorepos.", "required": false }, "menuSelections": { diff --git a/src/nrepl/jack-in.ts b/src/nrepl/jack-in.ts index c740be710..1ca445bfe 100644 --- a/src/nrepl/jack-in.ts +++ b/src/nrepl/jack-in.ts @@ -26,7 +26,7 @@ vscode.tasks.onDidEndTask(((e) => { if(e.execution.task.name == TASK_NAME) { JackinExecution = undefined; connector.default.disconnect(); - // make sure everything is set back + // make sure everything is set back // even if the task failed to connect // to the repl server. utilities.setLaunchingState(null); @@ -36,14 +36,16 @@ vscode.tasks.onDidEndTask(((e) => { function cancelJackInTask() { setTimeout(() => { - calvaJackout(); + calvaJackout(); }, 1000); } 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?.projectRootDir; - if(projectRootDir) state.setProjectRoot(projectRootDir); + if(projectRootDir) { + state.setProjectRoot(projectRootDir); + } utilities.setLaunchingState(projectTypeSelection); statusbar.update();