Fork me on GitHub
#calva
<
2023-04-03
>
sashton14:04:53

Are there bindable commands for changing collection types? I haven’t been able to find anything. It’s available in LSP as change-collection , but not listed in the Command Palette nor here: https://calva.io/refactoring/. Alternatively, if Calva doesn’t have an LSP command mapped, is there a way to pass a command through to LSP for this or any other new LSP commands?

ericdallo14:04:53

AFAIK not possible in Calva/vscode unless coding it in Calva(or joyride?)

ericdallo14:04:24

But would be nice to have a way to send generic commands (like Emacs) as LSP create a new code/action command regularly :)

pez14:04:09

Calva has commands for rewrapping collections. Search for rewrap in the command palette. It can’t convert to or from sets though. We can probably make some mechanism for calling arbitrary clojure-lsp code/action commands.

👍 2
Lukas Domagala18:04:05

If it’s available as a clojure-lsp command it should also be easy to add. Maybe that’s your first PR @U08TWB99B? 🙂

metal 1
pez19:04:25

I think that what we should add is a command for calling clojure-lsp commands. Then users can bind keyboard shortcuts to that command with the clojure-lsp command-name as arguments.

sashton19:04:42

I have discovered that I can in fact bind a change-collection command. I only looked in the Command Palette, but forgot (or realized?) that some commands don’t show up there, but are still available in the Keybindings UI. In this case, the command is clojureLsp.refactor.cycleColl. (I know, I originally said change-collection but I then found cycle-coll, which I liked better.)

pez19:04:02

Awesome. Does the change-collection command take arguments maybe?

sashton19:04:35

it looks like it in the lsp docs [file-uri,row,col,"map"/"list"/"set"/"vector"]

pez19:04:23

Not something that is easily passed from a keyboard shortcut… Also, the command that is registered is change-coll, not change-collection.

pez19:04:33

I think we still need a Calva wrapper command for this. It can pass the first three args, which seem universal for all commands. Then tuck on any args passed with the keyboard shortcut.

pez19:04:50

As it is now, I think a user only can bind the commands that take no further args.

pez21:04:33

@UKFSJSM38 I’m trying to send the change-collection command, but I get no results:

[Trace - 11:41:30 PM] Sending request 'workspace/executeCommand - (94)'.
Params: {
    "command": "change-collection",
    "arguments": [
        "file:///Users/pez/Projects/calva/test-data/projects/pirate-lang/test/pez/pirate_lang_test.clj",
        6,
        33,
        "vector"
    ]
}


[Trace - 11:41:30 PM] Received response 'workspace/executeCommand - (94)' in 2ms.
No result returned.
Am I holding it wrong? If I send, say, introduce-let instead, I get results and the action is performed.

ericdallo21:04:54

I think the docs are worng, the correct name is change-coll

ericdallo21:04:09

we should probably return an error for unknown commands as well :)

ericdallo21:04:26

Docs fixed (Ci deploying)

pez21:04:19

Awesome. Yes, that works. Interestingly enough Calva had it configured as change-coll already. But no way to provide the argument, so not super useful. 😃

👍 1
pez22:04:10

> We strongly suggest that client authors and users use these shortcuts keys when choosing to map these commands to key chords or menus Calva can’t adhere to this advice. Things like sc is not a valid keybinding in VS Code.

pez22:04:39

Adding the generic clojure-lsp.command here. https://github.com/BetterThanTomorrow/calva/pull/2140 It can be used from Joyride or via keyboard shortcuts. A shortcut can look like so:

{
        "key": "ctrl+alt+r s",
        "command": "clojure-lsp.command",
        "args": ["change-coll", ["set"]]
    },
(Even though, since earlier today, Calva has a built in command for this particular feature, but anyway, it’s an example.)

👍 4
Lukas Domagala18:04:27

Do we have any way of adding middleware to a replConnectSequences ?

pez20:04:40

Not unless you can do it dynamically via the code you can run after connect.

pez20:04:18

Should be reasonably easy to add this facility, though.

Lukas Domagala20:04:35

Would be interesting now that we need the portal Middleware for fully featured notebooks. That reminds me that I need to update the docs:sweat_smile: