Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add projectRootDir for monorepo connection sequences #1100

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Changes to Calva.

## [Unreleased]
- [Add option to specify project root directory](https://github.com/BetterThanTomorrow/calva/issues/579)

## [2.0.184] - 2021-04-02
- Fix: [Calva not detecting tests with aliased clojure.test namespace](https://github.com/BetterThanTomorrow/calva/issues/1086)
Expand Down
1 change: 1 addition & 0 deletions docs/site/connect-sequences.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ A connect sequence configures the following:
* `projectType`: (required) This is either "Leiningen”, ”deps.edn”, ”shadow-cljs”, ”lein-shadow”, or ”generic".
* `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. Accepts absolute paths or paths relative to the workspace root.
* `cljsType`: This can be either "Figwheel Main", "lein-figwheel", "shadow-cljs", "Nashorn", "none", or a dictionary configuring a custom type. If set to "none", 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.)
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Calva: Clojure & ClojureScript Interactive Programming",
"description": "Integrated REPL, formatter, Paredit, and more. Powered by cider-nrepl and clojure-lsp.",
"icon": "assets/calva.png",
"version": "2.0.185",
"version": "2.0.185-monorepo-proj-root-dir",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"version": "2.0.185-monorepo-proj-root-dir",
"version": "2.0.185",

(I usually pick up the VSIX from CircleCI instead. Maybe we should make a script that build a local VSIX...)

"publisher": "betterthantomorrow",
"author": {
"name": "Better Than Tomorrow",
Expand Down Expand Up @@ -373,6 +373,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": "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.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI (and this should go to the dev docs): I've started to use markdownDescription to boost the schema help a bit.

"required": false
},
"menuSelections": {
"type": "object",
"description": "Pre-selected menu options. If a selection is made here. Calva won't prompt for it.",
Expand Down
6 changes: 5 additions & 1 deletion src/nrepl/connectSequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ interface ReplConnectSequence {
name: string,
projectType: ProjectTypes,
afterCLJReplJackInCode?: string,
projectRootDir?: string,
cljsType: CljsTypes | CljsTypeConfig,
menuSelections?: MenuSelections,
nReplPortFile?: string[]
Expand Down Expand Up @@ -208,7 +209,10 @@ function getConnectSequences(projectTypes: string[]): ReplConnectSequence[] {
const customSequences = getCustomConnectSequences();
const defSequences = projectTypes.reduce((seqs, projectType) => seqs.concat(defaultSequences[projectType]), []);
const defSequenceProjectTypes = [...new Set(defSequences.map(s => s.projectType))];
const sequences = customSequences.filter(customSequence => defSequenceProjectTypes.includes(customSequence.projectType)).concat(defSequences);
const sequences = customSequences.filter(customSequence =>
!!customSequence.projectRootDir
|| defSequenceProjectTypes.includes(customSequence.projectType)
).concat(defSequences);
Comment on lines +212 to +215
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite remember where the result from this function is used. Can you explain why you filter away sequences with the setting? (I'm sure it is the right thing to do, just want to understand why. 😄 )

return sequences;
}

Expand Down
18 changes: 12 additions & 6 deletions src/nrepl/jack-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,22 @@ export async function jackIn(connectSequence: ReplConnectSequence, cb?: Function
return;
}
}
if (projectConnectSequence) {
const terminalJackInOptions = await getJackInTerminalOptions(projectConnectSequence);
if (terminalJackInOptions) {
await executeJackInTask(terminalJackInOptions, projectConnectSequence, cb);
}
} else {

if (!projectConnectSequence) {
vscode.window.showInformationMessage('No supported project types detected. Maybe try starting your project manually and use the Connect command?');
return;
}

if (projectConnectSequence.projectRootDir) {
const rootDirPath = state.resolvePath(projectConnectSequence.projectRootDir);
await state.initProjectDir(vscode.Uri.parse(rootDirPath))
}

const terminalJackInOptions = await getJackInTerminalOptions(projectConnectSequence);
if (terminalJackInOptions) {
await executeJackInTask(terminalJackInOptions, projectConnectSequence, cb);
}

liveShareSupport.didJackIn();
}

Expand Down