Fork me on GitHub
Samuel McHugh11:11:31

Hello, both Emacs and Cursive have some options to automatically add require declarations to your namespace with just a function name. For example imaging I type out json/to-json in my file and I have cheshire as a dependency in my deps.edn. It would be cool to be able to do a keyboard shortcut with my cursor over json/to-json and for Calva to automatically add [cheshire :as json] under my existing (:require ). Here it is in Emacs I’m wondering if it could be done in Calva using clojure.repl/apropos . Does that jump out as not possible for any reason? I’m not able to follow along how it’s done at

👍 3

Agree. Is this something that #lsp can help with, @UKFSJSM38?


This already exists on clojure-lsp and even use to work better than clj-refactor :p Is just code actions, check:


Awesome! Can you file an issue on the Calva repo to implement this, please, @U0151JJA3FT?


Though we already support code actions. Is there something special for this one, @UKFSJSM38?


Oh, we actually already support it. 😃 Though in my work project I get a huge list for something like (s/def …)


So huge it is not really helpful 😃 I don’t thing def is defined in all those. Are there attempts made to filter the list?

Samuel McHugh18:11:04

oh wow I had no idea

Samuel McHugh18:11:16

But yes, the analysis must just look at the alias you put and the namespaces on the class-path and does some kind of fuzzy match. It doesn't actually check that there is a function defined in those namespaces which matches what you're looking for. For example if I put str/trim and run the code action it gives me the correct option for clojure.string but it will also give me as an option. So if you use a really short alias like s which can fit many many namespaces it isn't too clever.

Samuel McHugh18:11:36

Still, I actually didn't even know to check the lightbulb for this kinda stuff so it's already really useful in 90% of circumstances

Samuel McHugh18:11:03

But theoretically if you combined this fuzzy searching with the clojure.repl/apropos you could narrow in on the only reasonable option in many cases. For example if I do (clojure.repl/apropos 'trim) I get

So I could filter out from my list of suggestions since it doesn't appear here.


Code actions don't work on calva ATM


You can trigger code actions with Ctrl + .

Samuel McHugh18:11:53

Erm maybe I don't know what a code action is but the little lightbulb works for me, but maybe my Calva is out of date or something. Also there is a command calva.refactor.addMissingLibspec


This is a code action:

Samuel McHugh18:11:27

calva.refactor.addMissingLibspec will randomly not work for me for some declarations though 🤷


calling refactors manually are not recommended, the code actions are though


but like the issue I mentioned, it seems they are not working for calva yet c/c @U9A1RLFNV

👍 1
Samuel McHugh18:11:36

Okay, I do see the issue that most of the ctrl +`.` options don't do anything when selected (like toggling function privacy) but the libspec insert is one example that does work for me. So maybe it's using something else under the hood.


Not really, all code actions are commands under the hood, but adding that to the issue may help understand the root cause

Samuel McHugh19:11:33 Put a little gif on your issue. I can maybe have a look tomorrow to see what the difference may be and if there are any other working code actions.

👍 1