Skip to content

Commit 348aaa4

Browse files
authored
Merge pull request #2565 from BetterThanTomorrow/2556-proper-refresh-commands
Make refresh commands return their promises and accept args
2 parents 2209b00 + f6899a4 commit 348aaa4

File tree

6 files changed

+82
-20
lines changed

6 files changed

+82
-20
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Changes to Calva.
44

55
## [Unreleased]
66

7+
[Extend "Refresh Changed Namespaces" to accept optional parameters exposed by cider-nrepl](https://github.com/BetterThanTomorrow/calva/issues/2556)
8+
79
## [2.0.454] - 2024-06-03
810

911
- Fix: [HTML->Hiccup fails on style attribute strings where the entries do not have whitespace](https://github.com/BetterThanTomorrow/calva/issues/2561)

docs/site/commands.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: Calva Commands
3+
description: A list of all (well, not by far yet) Calva commands. A part of Calva's API.
4+
---
5+
6+
# Calva Commands
7+
8+
!!! Note "This list is totally incomplete"
9+
If you want to help the Calva project, one way to do so is to help making this list of commands complete.
10+
11+
Calva's commands are part of the [Calva API](api.md). They often accept arguments of some type, which you can use from keybindings and from [Joyride](https://github.com/BetterThanTomorrow/joyride) (or another VS Code extension). Well behaved commands return a Promise, if it is async. You can utilize this with Joyride too, or with keybindings involving [`runCommands`](https://blog.agical.se/en/posts/vs-code-runcommands-for-multi-commands-keyboard-shortcuts/).
12+
13+
## Example shortcut bindings
14+
15+
To illustrate how to provide arguments to the Calva commands, here's a keyboard shortcut binding for `calva.refresh`:
16+
17+
```json
18+
{
19+
"key": "ctrl+alt+c f1",
20+
"command": "calva.refresh",
21+
"args": {
22+
"after": "component.repl/reset"
23+
}
24+
},
25+
```
26+
27+
It sends along the `:after` argument for the `cider-nrepl/refresh` op. (The actual argument only makes sense with [Component](https://github.com/stuartsierra/component))
28+
29+
Here's another way to achieve something similar.
30+
31+
```json
32+
{
33+
"key": "ctrl+alt+c f1",
34+
"command": "runCommands",
35+
"args": {
36+
"commands": [
37+
"calva.refresh",
38+
{
39+
"command": "calva.runCustomREPLCommand",
40+
"args": "(component.repl/reset)"
41+
}
42+
]
43+
}
44+
}
45+
```
46+
47+
## REPL commands
48+
49+
Commands that establishes or needs a REPL connection.
50+
51+
| Command | Title | Arguments | Notes |
52+
| :------ | :---- | :-------- | :---- |
53+
| `calva.refresh` | Refreshes changed namespaces | A JSON object with stuff from [cider-nrepl ops/refresh](https://github.com/clojure-emacs/cider-nrepl/blob/master/doc/modules/ROOT/pages/nrepl-api/ops.adoc#refresh) | Mostly meant for sending `:dirs`, `:after`, and `:before`. The print options may or may not work.
54+
| `calva.refreshAll` | Refreshes changed namespaces | A JSON object with stuff from [cider-nrepl ops/refresh-aa](https://github.com/clojure-emacs/cider-nrepl/blob/master/doc/modules/ROOT/pages/nrepl-api/ops.adoc#refresh-all) | Mostly meant for sending `:dirs`, `:after`, and `:before`. The print options may or may not work.
55+
56+
57+
## Wait, where are all the commands?
58+
59+
Told you the list is incomplete... Please consider helping with making this a complete list! 🙏

mkdocs.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ nav:
103103
- quirks.md
104104
- async-out.md
105105
- clj-java-decompiler.md
106-
- api.md
106+
- API:
107+
- api.md
108+
- commands.md
107109
- In Depth:
108110
- jack-in-guide.md
109111
- Guides:

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { CalvaSignatureHelpProvider } from './providers/signature';
1717
import testRunner from './testRunner';
1818
import annotations from './providers/annotations';
1919
import eval from './evaluate';
20-
import refresh from './refresh';
20+
import * as refresh from './refresh';
2121
import * as greetings from './greet';
2222
import Analytics from './analytics';
2323
import * as open from 'open';

src/nrepl/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ export class NReplSession {
763763
});
764764
}
765765

766-
private _refresh(cmd, opts: { dirs?: string[]; before?: string[]; after?: string[] } = {}) {
766+
private _refresh(cmd, opts = {}) {
767767
return new Promise<any>((resolve, reject) => {
768768
const id = this.client.nextId;
769769
const msg = {
@@ -793,6 +793,9 @@ export class NReplSession {
793793
if (msg.err) {
794794
err += msg.err;
795795
}
796+
if (msg.out) {
797+
output.appendOtherOut(msg.out);
798+
}
796799
if (hasStatus(msg, 'done')) {
797800
const res = { reloaded, status } as any;
798801
if (error) {
@@ -816,11 +819,11 @@ export class NReplSession {
816819
});
817820
}
818821

819-
refresh(opts: { dirs?: string[]; before?: string[]; after?: string[] } = {}) {
822+
refresh(opts = {}) {
820823
return this._refresh('refresh', opts);
821824
}
822825

823-
refreshAll(opts: { dirs?: string[]; before?: string[]; after?: string[] } = {}) {
826+
refreshAll(opts = {}) {
824827
return this._refresh('refresh-all', opts);
825828
}
826829

src/refresh.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,33 @@ function report(res) {
1919
}
2020
output.appendLineEvalOut(':error 😿');
2121
}
22+
return res;
2223
}
2324

24-
function refresh(document = {}) {
25-
const doc = util.tryToGetDocument(document),
25+
export function refresh(opts?: Record<string, unknown>) {
26+
const doc = util.tryToGetDocument({}),
2627
client: NReplSession = replSession.getSession(util.getFileType(doc));
2728

2829
if (client != undefined) {
2930
output.appendLineEvalOut('Reloading...');
30-
void client.refresh().then((res) => {
31-
report(res);
31+
return client.refresh(opts).then((res) => {
32+
return report(res);
3233
});
3334
} else {
34-
void vscode.window.showErrorMessage('Not connected to a REPL.');
35+
return vscode.window.showErrorMessage('Not connected to a REPL.');
3536
}
3637
}
3738

38-
function refreshAll(document = {}) {
39-
const doc = util.tryToGetDocument(document),
39+
export function refreshAll(opts?: Record<string, unknown>) {
40+
const doc = util.tryToGetDocument({}),
4041
client: NReplSession = replSession.getSession(util.getFileType(doc));
4142

4243
if (client != undefined) {
4344
output.appendLineEvalOut('Reloading all the things...');
44-
void client.refreshAll().then((res) => {
45-
report(res);
45+
return client.refreshAll(opts).then((res) => {
46+
return report(res);
4647
});
4748
} else {
48-
void vscode.window.showErrorMessage('Not connected to a REPL.');
49+
return vscode.window.showErrorMessage('Not connected to a REPL.');
4950
}
5051
}
51-
52-
export default {
53-
refresh,
54-
refreshAll,
55-
};

0 commit comments

Comments
 (0)