Skip to content

Commit

Permalink
Merge pull request #315 from BetterThanTomorrow/wip/sequence-port-file
Browse files Browse the repository at this point in the history
Wip/sequence port file
  • Loading branch information
PEZ authored Sep 14, 2019
2 parents 2833310 + 07eb900 commit 37c0fbe
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Changes to Calva. (We really will try to keep this updated now.)
- [Support for custom project/workflow commands](https://github.com/BetterThanTomorrow/calva/issues/281)

## [Unreleased]
- Nothing to see here
- [Support connecting to Leiningen and CLI project using shadow-cljs watcher](https://github.com/BetterThanTomorrow/calva/issues/314)

## [2.0.36] - 12.09.2019
- Fix [REPL Window namespace being reset to user](https://github.com/BetterThanTomorrow/calva/issues/302)
Expand Down
2 changes: 1 addition & 1 deletion calva/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ export async function connect(connectSequence: ReplConnectSequence, isAutoConnec
state.analytics().logEvent("REPL", "ConnectInitiated", isAutoConnect ? "auto" : "manual");
state.analytics().logEvent("REPL", "ConnnectInitiated", cljsTypeName).send();

const portFile = projectTypes.nreplPortFile(connectSequence.projectType);
const portFile = projectTypes.nreplPortFile(connectSequence);

state.extensionContext.workspaceState.update('selectedCljsTypeName', cljsTypeName);
state.extensionContext.workspaceState.update('selectedConnectSequence', connectSequence);
Expand Down
30 changes: 22 additions & 8 deletions calva/nrepl/connectSequence.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as vscode from "vscode";
import * as state from "../state";
import * as projectTypes from './project-types';
import * as path from 'path';
import * as utilities from '../utilities';

enum ProjectTypes {
Expand Down Expand Up @@ -45,6 +46,7 @@ interface ReplConnectSequence {
afterCLJReplJackInCode?: string,
cljsType?: CljsTypes | CljsTypeConfig,
menuSelections?: MenuSelecions,
nReplPortFile?: string[]
}

const leiningenDefaults: ReplConnectSequence[] =
Expand All @@ -53,14 +55,20 @@ const leiningenDefaults: ReplConnectSequence[] =
projectType: ProjectTypes.Leiningen
},
{
name: "Leiningen + Figwheel",
name: "Leiningen + Figwheel Main",
projectType: ProjectTypes.Leiningen,
cljsType: CljsTypes["lein-figwheel"]
cljsType: CljsTypes["Figwheel Main"]
},
{
name: "Leiningen + Figwheel Main",
name: "Leiningen + shadow-cljs",
projectType: ProjectTypes.Leiningen,
cljsType: CljsTypes["Figwheel Main"]
cljsType: CljsTypes["shadow-cljs"],
nReplPortFile: [".shadow-cljs", "nrepl.port"]
},
{
name: "Leiningen + Legacy Figwheel",
projectType: ProjectTypes.Leiningen,
cljsType: CljsTypes["lein-figwheel"]
},
{
name: "Leiningen + Nashorn",
Expand All @@ -74,14 +82,20 @@ const cljDefaults: ReplConnectSequence[] =
projectType: ProjectTypes["Clojure CLI"]
},
{
name: "Clojure CLI + Figwheel",
name: "Clojure CLI + Figwheel Main",
projectType: ProjectTypes["Clojure CLI"],
cljsType: CljsTypes["lein-figwheel"]
cljsType: CljsTypes["Figwheel Main"]
},
{
name: "Clojure CLI + Figwheel Main",
name: "Clojure CLI + shadow-cljs",
projectType: ProjectTypes["Clojure CLI"],
cljsType: CljsTypes["Figwheel Main"]
cljsType: CljsTypes["shadow-cljs"],
nReplPortFile: [".shadow-cljs", "nrepl.port"]
},
{
name: "Clojure CLI + Legacy Figwheel",
projectType: ProjectTypes["Clojure CLI"],
cljsType: CljsTypes["lein-figwheel"]
},
{
name: "Clojure CLI + Nashorn",
Expand Down
4 changes: 2 additions & 2 deletions calva/nrepl/jack-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const TASK_NAME = "Calva Jack-in";
async function executeJackInTask(projectType: projectTypes.ProjectType, projectTypeSelection: any, executable: string, args: any, cljTypes: string[], outputChannel: vscode.OutputChannel, connectSequence: ReplConnectSequence) {
state.cursor.set("launching", projectTypeSelection);
statusbar.update();
const nReplPortFile = projectTypes.nreplPortFile(projectType);
const nReplPortFile = projectTypes.nreplPortFile(connectSequence);
const env = { ...process.env, ...state.config().jackInEnv } as {
[key: string]: string;
};
Expand Down Expand Up @@ -78,7 +78,7 @@ export async function calvaJackIn() {
state.analytics().logEvent("REPL", "JackInInitiated").send();

const cljTypes = await projectTypes.detectProjectTypes();
const projectConnectSequence: ReplConnectSequence = await askForConnectSequence(cljTypes,'jack-in-type', "JackInInterrupted");
const projectConnectSequence: ReplConnectSequence = await askForConnectSequence(cljTypes, 'jack-in-type', "JackInInterrupted");

if (!projectConnectSequence) {
state.analytics().logEvent("REPL", "JackInInterrupted", "NoProjectTypeForBuildName").send();
Expand Down
18 changes: 12 additions & 6 deletions calva/nrepl/project-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ export type ProjectType = {
winCmd: string;
commandLine: (connectSequence: ReplConnectSequence, cljsType: CljsTypes) => any;
useWhenExists: string;
nReplPortFile: string;
nReplPortFile: string[];
};

export function nreplPortFile(projectType: ProjectType | string): string {
const subPath: string = typeof projectType == "string" ? getProjectTypeForName(projectType).nReplPortFile : projectType.nReplPortFile;
export function nreplPortFile(connectSequence: ReplConnectSequence): string {
let subPath: string = ".nrepl-port";
if (connectSequence.nReplPortFile) {
subPath = path.join(...connectSequence.nReplPortFile);
} else {
const projectType: ProjectType | string = connectSequence.projectType;
subPath = path.join(...getProjectTypeForName(projectType).nReplPortFile)
}
try {
return path.resolve(state.getProjectRoot(), subPath);
} catch (e) {
Expand Down Expand Up @@ -80,7 +86,7 @@ const projectTypes: { [id: string]: ProjectType } = {
cmd: "lein",
winCmd: "cmd.exe",
useWhenExists: "project.clj",
nReplPortFile: ".nrepl-port",
nReplPortFile: [".nrepl-port"],
/** Build the Commandline args for a lein-project.
* 1. Parsing the project.clj
* 2. Let the user choose a alias
Expand Down Expand Up @@ -217,7 +223,7 @@ const projectTypes: { [id: string]: ProjectType } = {
cmd: "clojure",
winCmd: "powershell.exe",
useWhenExists: "deps.edn",
nReplPortFile: ".nrepl-port",
nReplPortFile: [".nrepl-port"],
/** Build the Commandline args for a clj-project.
* 1. Read the deps.edn and parsed it
* 2. Present the user all found aliases
Expand Down Expand Up @@ -293,7 +299,7 @@ const projectTypes: { [id: string]: ProjectType } = {
cmd: "npx",
winCmd: "npx.cmd",
useWhenExists: "shadow-cljs.edn",
nReplPortFile: path.join(".shadow-cljs", "nrepl.port"),
nReplPortFile: [".shadow-cljs", "nrepl.port"],
/**
* Build the Commandline args for a shadow-project.
*/
Expand Down
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,13 @@
"shadow-cljs"
]
},
"nReplPortFile": {
"type": "array",
"description": "An array of path segments with the project root-releative path to the nREPL port file for this connect sequence. E.g. For shadow-cljs this would be [\".shadow-cljs\", \"nrepl.port\"]",
"items": {
"type": "string"
}
},
"afterCLJReplJackInCode": {
"type": "string",
"description": "Here you can give Calva some Clojure code to evaluate in the CLJ REPL, once it has been created.",
Expand Down

0 comments on commit 37c0fbe

Please sign in to comment.