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

Include cwd in jack-in command line #2150

Merged
merged 5 commits into from
Apr 10, 2023
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion docs/site/connect.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/extension-test/integration/suite/jack-in-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
18 changes: 8 additions & 10 deletions src/nrepl/jack-in-terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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'
);
Expand Down Expand Up @@ -69,8 +67,8 @@ export class JackInTerminal implements vscode.Pseudoterminal {

private async startClojureProgram(): Promise<child.ChildProcess> {
return new Promise<child.ChildProcess>(() => {
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');
Expand Down
6 changes: 3 additions & 3 deletions src/nrepl/jack-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ export async function copyJackInCommandToClipboard(): Promise<void> {
}
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) {
Expand Down