Not sure if this is a joyride problem or clj-kondo problem. When I edit a joyride script, I get all the lint issues as in the picture. However, I have added the lint-as section in my home clj-kondo config. The content is
{:lint-as {promesa.core/-> clojure.core/->
promesa.core/->> clojure.core/->>
promesa.core/as-> clojure.core/as->
promesa.core/let clojure.core/let
promesa.core/plet clojure.core/let
promesa.core/loop clojure.core/loop
promesa.core/recur clojure.core/recur
promesa.core/with-redefs clojure.core/with-redefs}}@i Which location did you use for the home config? This is a common mistake. The location should be:
~/.config/clj-kondo/config.edn
Exactly the same.
Can you try to lint your file on the command line with clj-kondo? If you don't get these issues, then it's probably an issue with clojure-lsp
Run with
clojure -Sdeps '{:deps {clj-kondo/clj-kondo {:mvn/version "2022.04.25"}}}' -M -m clj-kondo.main --lint .can you do
cat ~/.config/clj-kondo/config.edn
?Ah I see:
promesa.core/plet clojure.core/let
should be:
promesa.core/let clojure.core/letThere is one? https://bpa.st/27BA#1L20
oh right
Does anything else from your home config work?
Can you make a syntax error in the home configuration, e.g. put a random x somewhere which messes it up. Then try linting again on the command line. You should get an error about that
It indeed throws error.
Let me check if the functionality of home config is effective.
The reason is my home config is malformed: https://bpa.st/27BA#1L29. The #app.logging part.
One question on this, since the promesa package already have this: https://github.com/funcool/promesa/blob/master/resources/clj-kondo.exports/funcool/promesa/config.edn. Why should I define the lint-as in my home config?
That's a good question. The config from promesa will only be imported under the following conditions: • your deps.edn has the promesa dependency • there is a .clj-kondo directory in your project
> there is a .clj-kondo directory in your project Even if the directory is missing, kondo will create one on its own. So this condition (second) shall always meet.
.clj-kondo does not create it but probably clojure-lsp or calva do this
My purpose is to comment map items. For example, given
{:a :b
:c :d}
And the cursor is on :c, then it will comment with
{:a :b
#_(:c :d)}
However. the following function gives this output
{:a :b
#_(:c) :d}
(defn comment-map-item []
(p/let [editor ^js vscode/window.activeTextEditor
original-selection (util/current-selection)
insert-pos (.-active (util/current-selection))]
#_(aset editor "selection" original-selection)
(p/do! (util/insert-text "#_" editor insert-pos)
(vscode/commands.executeCommand "paredit.wrapAroundParens")
(vscode/commands.executeCommand "paredit.slurpSexpForward"))))
(comment
{:a :foobar
:b :fff})@i You could also just insert two #_ #_ (just like that, without anything in between)
Cool. This PR fixes this: https://github.com/BetterThanTomorrow/calva/pull/1734 Thanks for making me aware of the issue, @i!
Thanks for the great work, always!
The removal becomes a little bit hard.
Regarding my question, it seems (vscode/commands.executeCommand "paredit.slurpSexpForward") is not run (or is not effective)
I think the cursor is outside the (:c) form when you do the slurp. So then the slurp will apply to the closing }, which can't be moved forward, and nothing happens. If you go downList first, it should work.
I'm not sure about this, but it looks like so at the quick glance I can afford to give it right now. What I do when contructing high level edits with paredit, is that I do the operations in the editor and ”record” them, either in memory or in some file or on paper.
When I run manually the command is fine, but when with joyride it does not work though.
It could get tricky since you are inserting somewhere else than where you have the cursor. ... So I am not sure where that leaves your cursor after the wrapAroundParens... Try without the slurp and see where the cursor is when the script has been run.
Before and After
Basically the cursor always stay right before :b.
You could also try, while developing to define the editor to be some other editor than where you are REPL-ing your script. E.g. use the command Joyride: Run Clojure Code... to run something like this:
(in-ns 'your-script-ns) (def editor vscode/window.activeTextEditor)
Then use the REPL in your script to execute snippets from your code. I haven't tried this, but it might work.Slurp should work from that position. What happens if you evaluate just that one in the REPL?
> Slurp should work from that position. What happens if you evaluate just that one in the REPL? Work as expected.
Hmm, maybe wrapAroundParens is not awaiting...
Yes... I think this is the reason:
{
command: 'paredit.wrapAroundParens',
handler: (doc: EditableDocument) => {
void paredit.wrapSexpr(doc, '(', ')');
},
},We should fix that in Calva.
Off-topic, I have other commands like
(vscode/commands.executeCommand "vscode-neovim.send") That might be async. How to await them in joyride?
Those commands where never intended for promise composition at that level. For now, probably easiest to to put two ignore markers there. Or select both forms before doing wrap around.
If the commands are implemented so that they await, unlike the paredit command there, then promese.core/do! should work, I think.
> For now, probably easiest to to put two ignore markers there.
Manually?
One question, what’s the command that goes to the beginning of a keyword (or symbol, string) in paredit? (It is possible the cursor is already at the beginning; in that case, it shouldn’t move)
It's backwardSexpr (or something like that). It will move if it is already at the beginning of a sexpr/form, though. I don't know of a way to deal with that. It is tricky even inside Calva, where we have more context.
I am now going with the two #_ approach. Actually it gives more control. I like it very much.
It's quite exciting that you are exploring this, I must say. We need some usage in order to figure out the API Calva should have to better support scripting.
Is this the correct behaviour, @i?
@pez unrelated: I believe the body of p/let runs an implicit p/do!
You mean that we wouldn't need the one in the body here?
Yes, I believe it shouldnt be necessary
I'll experiment a a bit with that. Would be nice to drop those!
I don't believe its documented but I was scanning the promesa code for a bit lately and ran into it: https://github.com/funcool/promesa/blob/master/src/promesa/core.cljc#L454
Yes, that looks very much like a do! 😃
@pez Yes. That’s it.