joyride

2022-05-17T09:55:14.790309Z

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}}

borkdude 2022-05-17T09:56:33.697649Z

@i Which location did you use for the home config? This is a common mistake. The location should be:

~/.config/clj-kondo/config.edn

2022-05-17T09:57:16.360349Z

Exactly the same.

borkdude 2022-05-17T09:58:27.867339Z

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

2022-05-17T10:02:55.815929Z

2022-05-17T10:03:10.631959Z

Run with

clojure -Sdeps '{:deps {clj-kondo/clj-kondo  {:mvn/version "2022.04.25"}}}'  -M -m clj-kondo.main   --lint .

borkdude 2022-05-17T10:03:32.633109Z

can you do

cat ~/.config/clj-kondo/config.edn
?

2022-05-17T10:36:36.995759Z

https://bpa.st/27BA

borkdude 2022-05-17T10:37:57.111829Z

Ah I see:

promesa.core/plet        clojure.core/let
should be:
promesa.core/let clojure.core/let

2022-05-17T10:40:10.638739Z

There is one? https://bpa.st/27BA#1L20

borkdude 2022-05-17T10:40:43.861419Z

oh right

borkdude 2022-05-17T10:41:19.769369Z

Does anything else from your home config work?

borkdude 2022-05-17T10:42:02.055219Z

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

2022-05-17T10:45:24.277319Z

2022-05-17T10:45:32.100989Z

It indeed throws error.

2022-05-17T10:45:44.799669Z

Let me check if the functionality of home config is effective.

2022-05-17T10:48:39.358219Z

The reason is my home config is malformed: https://bpa.st/27BA#1L29. The #app.logging part.

2022-05-17T10:49:40.119669Z

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?

borkdude 2022-05-17T10:50:42.818029Z

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

2022-05-17T10:53:06.514169Z

> 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.

borkdude 2022-05-17T10:53:31.762229Z

.clj-kondo does not create it but probably clojure-lsp or calva do this

1
2022-05-17T11:53:46.150869Z

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})

borkdude 2022-05-17T11:56:13.494989Z

@i You could also just insert two #_ #_ (just like that, without anything in between)

pez 2022-05-22T12:23:35.381529Z

Cool. This PR fixes this: https://github.com/BetterThanTomorrow/calva/pull/1734 Thanks for making me aware of the issue, @i!

2022-05-22T12:28:11.771039Z

Thanks for the great work, always!

🙏 1
2022-05-17T11:57:17.219209Z

The removal becomes a little bit hard.

2022-05-17T11:57:51.721699Z

Regarding my question, it seems (vscode/commands.executeCommand "paredit.slurpSexpForward") is not run (or is not effective)

pez 2022-05-17T12:05:49.766389Z

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.

pez 2022-05-17T12:07:59.039669Z

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.

1
2022-05-17T12:15:43.616749Z

When I run manually the command is fine, but when with joyride it does not work though.

pez 2022-05-17T12:22:48.773049Z

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.

2022-05-17T12:25:49.685169Z

Before and After

2022-05-17T12:29:16.008809Z

2022-05-17T12:29:58.800579Z

Basically the cursor always stay right before :b.

pez 2022-05-17T12:33:08.740679Z

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.

pez 2022-05-17T12:34:32.266919Z

Slurp should work from that position. What happens if you evaluate just that one in the REPL?

2022-05-17T12:40:14.169099Z

> Slurp should work from that position. What happens if you evaluate just that one in the REPL? Work as expected.

pez 2022-05-17T12:44:51.990569Z

Hmm, maybe wrapAroundParens is not awaiting...

pez 2022-05-17T12:45:45.806759Z

Yes... I think this is the reason:

{
    command: 'paredit.wrapAroundParens',
    handler: (doc: EditableDocument) => {
      void paredit.wrapSexpr(doc, '(', ')');
    },
  },

pez 2022-05-17T12:46:14.614599Z

We should fix that in Calva.

2022-05-17T12:50:09.171289Z

Off-topic, I have other commands like (vscode/commands.executeCommand "vscode-neovim.send") That might be async. How to await them in joyride?

pez 2022-05-17T12:50:17.111559Z

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.

pez 2022-05-17T12:52:07.122249Z

If the commands are implemented so that they await, unlike the paredit command there, then promese.core/do! should work, I think.

2022-05-17T12:52:37.874139Z

> For now, probably easiest to to put two ignore markers there. Manually?

2022-05-17T13:08:38.531159Z

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)

pez 2022-05-17T13:15:46.086099Z

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.

2022-05-17T13:16:56.954249Z

I am now going with the two #_ approach. Actually it gives more control. I like it very much.

pez 2022-05-17T13:18:25.992219Z

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.

✊ 1
pez 2022-05-21T22:33:55.026019Z

Is this the correct behaviour, @i?

alpox 2022-05-21T22:35:42.632839Z

@pez unrelated: I believe the body of p/let runs an implicit p/do!

pez 2022-05-21T22:36:38.107829Z

You mean that we wouldn't need the one in the body here?

alpox 2022-05-21T22:37:59.178759Z

Yes, I believe it shouldnt be necessary

pez 2022-05-21T22:39:52.361899Z

I'll experiment a a bit with that. Would be nice to drop those!

😎 1
alpox 2022-05-21T22:40:23.682119Z

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

pez 2022-05-21T22:40:53.810919Z

Yes, that looks very much like a do! 😃

2022-05-21T23:59:43.886479Z

@pez Yes. That’s it.