Fork me on GitHub
#calva
<
2020-06-01
>
levitanong05:06:15

Hallo! Is there a way to go to visit a cljs lib’s function’s definition and modify things like in emacs cider?

pez06:06:50

How do you mean modify things? Redefine things? I think you can use the repl window for that.

levitanong16:06:41

Yeah, to redefine things. I keep trying, but it says “no definition found for xxx”. I think the problem lies in the fact that I’m using a clj repl to run a cljs process. Somehow no matter what I do, it gets evaluated in clj land. Not sure how to force it to realize it’s cljs.

pez18:06:49

Maybe you haven’t gotten the cljs repl server connected properly. Calva will default to the clj repl in that case. Can you describe how you connect the cljs repl?

levitanong05:06:11

I start the cljs repl via shadow.server/start! and (shadow/watch build-id) then connect to it via (shadow/nrepl-select build-id)

pez06:06:37

Might be that nrepl isn’t on the dependencies. Try with Calva Jack-in and see if that helps.

levitanong14:06:56

But have been using calva jack-in 😅 I also have the cljAliases set to run the necessary aliases I’ve set up to include nrepl and cider. I also have a .nrepl.edn file that includes the nrepl cider and shadow middleware. I initially guessed that I have to jack in with "cljsType": "shadow-cljs" but that doesn’t suit my usecase since I use shadow-cljs as an alias that’s run from clojure cli. (The reason for this is I want to be able to split up dev and release extra-deps like binaryage/devtools. AFAIK, currently if you run shadow-cljs on its own, and you use deps to manage your… deps, you cannot conditionally run aliases.) I tried making a custom cljsType, but I couldn’t get it to work well.

pez15:06:40

I can look at it together with you over zoom. It could be something Calva needs to support, that it doesn’t currently. Or it could be something we are just overlooking.

levitanong18:06:15

I simplified my dev setup such that I just have to jack-in a normal shadow-cljs repl. It appears the issue remains. If I have an invocation for a function provided by a third party library, calva seems unable to find it. I appreciate the offer for the call, but recognize that our timezones might not match. As this is not particularly urgent or critical for me, I hesitate to take up your time. I’ll make a minimal repro for you, and post an issue in the github 🙂

pez19:06:29

Repro would be nice!

pez19:06:27

You wouldn't be taking up my time, btw. I think I would benefit from understanding your use case.

levitanong06:06:15

I figured out the issue while making the repro 😅 If i’m on a CLJC file, I have to make sure it’s in cljs mode before load current file and dependencies, and only then will Go to Definition work. So at this point the question is, is it possible for calva to guess that it should be treating cljc files as cljs files? Or perhaps simply the error message could also suggest the user to check the file mode if it detects that the current file is CLJC.

pez06:06:47

Ah, that's good information. Not sure how Calva could guess that, but the error message could very well suggest you check which REPL is backing your file. Can you file an issue about this?

pez07:06:29

Thanks! I've chimed in some.

👍 4
borkdude14:06:43

Any Calva people want to chime in on this new shiny clj-kondo feature? https://clojureverse.org/t/feedback-wanted-on-new-clj-kondo-macroexpansion-feature/6043

pez15:06:27

It is a bit unclear to me what I need to do as a user of clj-kondo in order to get my macro invocations checked. (I only read it very quickly.)

borkdude15:06:21

In that case I recommend reading it slower.

borkdude15:06:00

You have to provide some code that translates the sexpr into another sexpr that clj-kondo understands.

borkdude15:06:31

Effectively a macro expansion, but a simplification compared to the real macro, just to teach clj-kondo

sergey.shvets20:06:10

I would love to solve this problem, but not a big fan of writing extra code. That code isn't trivial and can contain mistakes of its own. As an idea, can spec solve this? While it doesn't make much sense to spec :ret value of macro for code, it has tons of sense for clj-kondo. https://clojure.org/guides/spec#_macros

borkdude20:06:14

spec is nice for validating macros, but it doesn't help linting that much

pez18:06:22

Can the “expansion” code somehow be provided with the macro, as meta-data? I agree that it does not look trivial for end users, but the macro author is a different matter.

borkdude20:06:08

Maybe macro writers can expose their expansion code in their source directory:

src/clj-kondo/macroexpand/mylibrary/namespace/weird_macro.clj
Same for configs:
src/clj-kondo/config.edn
?

borkdude20:06:02

And then clj-kondo knows where to grab this from

pez21:06:06

Yeah! That would be quite awesome.

pez21:06:38

Also, maybe a concept of config repositories. Like, if you use a library where the author hasn't provided configs and expansions, you write it and publish it for others to use too.

levitanong16:06:00

I’ve noticed some really weird spacing issues with destructuring maps from within let bindings. It’s spacing it out as if the part that’s destructured is all in one line. I’m aware that this is in the works, and to get around this I set :align-associative? false but every now and then I hit ctrl+alt+l out of habit, and that seems immune to this setting. Is there a way to blacklist certain forms for associative alignment?