diff --git a/CHANGELOG.md b/CHANGELOG.md index 860aeb2a0..2ad11a47e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ Changes to Calva. ## [Unreleased] +- [Include a change directory command with the jack-in command line](https://github.com/BetterThanTomorrow/calva/issues/2147) + ## [2.0.349] - 2023-04-09 - Fix: [Indenter and formatter do not agree on some simple forms (and the formatter is right)](https://github.com/BetterThanTomorrow/calva/issues/2148) diff --git a/docs/site/connect.md b/docs/site/connect.md index 619f128a8..50c61d595 100644 --- a/docs/site/connect.md +++ b/docs/site/connect.md @@ -100,7 +100,7 @@ Even better: Copying that command line gives you the command to start the REPL w All this said, I still recommend you challenge the conclusion that you can't use Jack-in. !!! Note - There is a Calva command for copying the Jack-in command line to the clipboard. + There is a Calva command for copying the Jack-in command line to the clipboard. It will copy the command line including commands to change to the current REPL project root, avoiding hard-to-detect errors when starting the REPL in the wrong directory. ### Customizing Connect diff --git a/src/extension-test/integration/suite/jack-in-test.ts b/src/extension-test/integration/suite/jack-in-test.ts index 513b67312..4be0ca9cb 100644 --- a/src/extension-test/integration/suite/jack-in-test.ts +++ b/src/extension-test/integration/suite/jack-in-test.ts @@ -85,7 +85,7 @@ suite('Jack-in suite', () => { const cmdLine = await vscode.env.clipboard.readText(); testUtil.log(suite, 'cmdLine', cmdLine); - assert.ok(cmdLine.startsWith('clojure')); + assert.ok(cmdLine.includes('clojure')); await vscode.commands.executeCommand('workbench.action.closeActiveEditor'); testUtil.log(suite, 'test.clj closed'); diff --git a/src/nrepl/jack-in-terminal.ts b/src/nrepl/jack-in-terminal.ts index 009793d17..dbb3e297e 100644 --- a/src/nrepl/jack-in-terminal.ts +++ b/src/nrepl/jack-in-terminal.ts @@ -13,8 +13,11 @@ export interface JackInTerminalOptions extends vscode.TerminalOptions { useShell: boolean; } -export function createCommandLine(executable: string, args: string[]) { - return `${executable} ${args.join(' ')}`; +export function createCommandLine(options: JackInTerminalOptions): string { + const commandSeparator = options.isWin ? '&' : ';'; + return `pushd ${options.cwd} ${commandSeparator} ${options.executable} ${options.args.join( + ' ' + )} ${commandSeparator} popd`; } export class JackInTerminal implements vscode.Pseudoterminal { @@ -32,12 +35,7 @@ export class JackInTerminal implements vscode.Pseudoterminal { ) {} open(initialDimensions: vscode.TerminalDimensions | undefined): void { - outputWindow.appendLine( - `; Starting Jack-in Terminal: ${createCommandLine( - this.options.executable, - this.options.args - )}` - ); + outputWindow.appendLine(`; Starting Jack-in Terminal: ${createCommandLine(this.options)}`); this.writeEmitter.fire( 'This is a pseudo terminal, only used for hosting the Jack-in REPL process. It takes no input.\r\nPressing ctrl+c with this terminal focused, killing this terminal, or closing/reloading the VS Code window will all stop/kill the Jack-in REPL process.\r\n\r\n' ); @@ -69,8 +67,8 @@ export class JackInTerminal implements vscode.Pseudoterminal { private async startClojureProgram(): Promise { return new Promise(() => { - const data = `${createCommandLine(this.options.executable, this.options.args)}\r\n`; - this.writeEmitter.fire('⚡️Starting the REPL ⚡️ using the below command line:\r\n'); + const data = `${createCommandLine(this.options)}\r\n`; + this.writeEmitter.fire('⚡️ Starting the REPL ⚡️ using the below command line:\r\n'); this.writeEmitter.fire(data); if (this.process && !this.process.killed) { console.log('Restarting Jack-in process'); diff --git a/src/nrepl/jack-in.ts b/src/nrepl/jack-in.ts index f91e5b69d..c1db4cae4 100644 --- a/src/nrepl/jack-in.ts +++ b/src/nrepl/jack-in.ts @@ -154,9 +154,9 @@ export async function copyJackInCommandToClipboard(): Promise { } if (projectConnectSequence) { try { - const { executable, args } = await getJackInTerminalOptions(projectConnectSequence); - if (executable && args) { - void vscode.env.clipboard.writeText(createCommandLine(executable, args)); + const options = await getJackInTerminalOptions(projectConnectSequence); + if (options) { + void vscode.env.clipboard.writeText(createCommandLine(options)); void vscode.window.showInformationMessage('Jack-in command line copied to the clipboard.'); } } catch (e) {