Fork me on GitHub

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


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


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.


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?


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


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


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.


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.


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 🙂


Repro would be nice!


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


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.


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?


Thanks! I've chimed in some.

👍 4

Any Calva people want to chime in on this new shiny clj-kondo feature?


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


In that case I recommend reading it slower.


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


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


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.


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


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.


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

Same for configs:


And then clj-kondo knows where to grab this from


Yeah! That would be quite awesome.


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.


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?