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 setting #580

Closed
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 @@ -2,6 +2,7 @@
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
- Fix so that Paredit treats symbols containing the quote character correctly.
Expand Down
1 change: 1 addition & 0 deletions docs/readthedocs/source/connect-sequences.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "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": {
"type": "object",
"description": "Pre-selected menu options. If a slection is made here. Calva won't prompt for it.",
Expand Down
5 changes: 3 additions & 2 deletions src/nrepl/connectSequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ interface MenuSelections {
leinAlias?: string,
cljAliases?: string[],
cljsLaunchBuilds?: string[],
cljsDefaultBuild?: string
cljsDefaultBuild?: string,
}

interface ReplConnectSequence {
name: string,
projectType: ProjectTypes,
afterCLJReplJackInCode?: string,
projectRootDir?: string,
cljsType: CljsTypes | CljsTypeConfig,
menuSelections?: MenuSelections,
nReplPortFile?: string[]
Expand Down Expand Up @@ -242,4 +243,4 @@ export {
CljsTypes,
ReplConnectSequence,
CljsTypeConfig
}
}
10 changes: 8 additions & 2 deletions src/nrepl/jack-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -36,11 +36,17 @@ 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);
}

utilities.setLaunchingState(projectTypeSelection);
statusbar.update();
const nReplPortFile = projectTypes.nreplPortFile(connectSequence);
Expand Down
6 changes: 5 additions & 1 deletion src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ export function getProjectRoot(useCache = true): string {
}
}

export function setProjectRoot(rootPath: string) {
PEZ marked this conversation as resolved.
Show resolved Hide resolved
cursor.set(PROJECT_DIR_KEY, rootPath);
}

export function getProjectWsFolder(): vscode.WorkspaceFolder {
const doc = util.getDocument({});
return doc ? vscode.workspace.getWorkspaceFolder(doc.uri) : null;
Expand Down Expand Up @@ -223,7 +227,7 @@ export async function initProjectDir(): Promise<void> {
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;
}
}
Expand Down