This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-24
Channels
- # announcements (4)
- # asami (5)
- # babashka (20)
- # beginners (94)
- # bristol-clojurians (1)
- # calva (23)
- # cider (2)
- # clj-commons (3)
- # clj-kondo (43)
- # cljfx (2)
- # cljs-dev (13)
- # clojure (112)
- # clojure-dev (44)
- # clojure-europe (17)
- # clojure-nl (5)
- # clojure-poland (12)
- # clojure-spec (2)
- # clojure-uk (3)
- # clojurebridge (1)
- # clojurescript (92)
- # cursive (17)
- # data-science (8)
- # datahike (1)
- # datalevin (1)
- # datomic (3)
- # deps-new (7)
- # events (2)
- # fulcro (40)
- # graalvm (110)
- # holy-lambda (16)
- # introduce-yourself (1)
- # lsp (13)
- # malli (8)
- # missionary (12)
- # off-topic (10)
- # pathom (13)
- # polylith (10)
- # portal (28)
- # re-frame (37)
- # reitit (1)
- # releases (1)
- # shadow-cljs (30)
- # spacemacs (1)
- # tools-deps (9)
- # xtdb (10)
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 https://github.com/clojure-emacs/clj-refactor.el/blob/master/examples/add-missing-libspec.gif. 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 https://github.com/clojure-emacs/clj-refactor.el/blob/master/clj-refactor.el#L2958
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: https://clojure-lsp.io/features/#code-actions
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?
oh wow I had no idea
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 manifold.stream
as an option. So if you use a really short alias like s
which can fit many many namespaces it isn't too clever.
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
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
(cider.nrepl.inlined-deps.orchard.v0v7v1.orchard.java/trim-one-dot
clojure.string/trim
clojure.string/trim-newline
clojure.string/triml
clojure.string/trimr)
So I could filter out manifold.stream
from my list of suggestions since it doesn't appear here.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
calva.refactor.addMissingLibspec
will randomly not work for me for some declarations though 🤷
but like the issue I mentioned, it seems they are not working for calva yet c/c @U9A1RLFNV
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
https://github.com/BetterThanTomorrow/calva/issues/1373#issuecomment-978152785 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.