Fork me on GitHub
#calva
<
2024-03-04
>
chromalchemy18:03:41

Is there a Calva command that can take a string to eval (in the current namespace at least)? Similar to the “Evaluate Selection” command, but instead of taking selection, is passed a string to evaluate? I know about Repl Snippets, but I’m thinking of something I could use with less ceremony (not having to name them, and also avoiding littering config with permutations of a command). Context: I use vscode commands programmatically from Talon Voice with a synax like this: evaluate selection: vscode("calva.evaluateSelection") The first part is the spoken phrase, then takes a vscode command id. There is a version that takes input parameters for vscode commands that take them. So in this case the vscode command would take the string to evaluate.

chromalchemy18:03:44

Ok that does seem to work!! I thought I had tried that before, (simply giving the command a string, and it didn’t work for me previously. maybe just had an incorrect call)

clojure-spin 1
chromalchemy18:03:17

I am using it via rpc like this. user.run_rpc_command("calva.runCustomREPLCommand", "(println \"hello-world\" )") This invokation takes args linearly. Any thing I’m missing compared to your example with named argument? what is "repl": "clj" ? Could I declare a namespace with this linear call? . Oh, I think I see.. the first argument can be a map?

chromalchemy19:03:41

What format is runCustomREPLCommand expecting arguments? Pass it json string?

chromalchemy20:03:38

I tried passing json string and got this error:

; Syntax error reading source at (REPL:1607:12).
; Invalid token: :

chromalchemy20:03:20

What is the best way to pass multiple argments (map) to vscode action, from a python context? python dict -> json string, or is there some kind of desctructured syntax the vscode command expects (for associative args)?

pez03:03:24

I’ve never used the rpc interface, so don’t know what to try.

pez03:03:48

The map argument is the same argument as when declaring custom repl commands.

chromalchemy13:03:44

So to confirm, calva.runCustomREPLCommand takes 1 argment?…If it is a string, evaluates it as a snippet in the current namespace. If it is a json map, it reads named arguments (outlined in custom repl commands)

pez13:03:51

Exactly.

pez13:03:26

Current namespace being defined as the namespace of the currently active editor.

pez13:03:05

Also, it will be evaluated in the current repl session of the currently active editor.

pez13:03:45

I’m thinking that the rpc call maybe supports using a python dict and take care of converting it to json. Have you tried that?

chromalchemy02:03:15

Thx for confirming. I tried the dict->json via dump() in Python. It didnt work and was throwing some kind of error, but maybe something else was off, will try again.