Is there a way for LSP to infer the list of importable variables/functions from a namespace? Say I have:
(ns my-ns
(:require [my-other-ns :refer [ <trigger an auto-completion box filled with vars/fns> ]]))
It's probably possible, bringing the cursor's context into the completion code could work. That'll probably require moving the hairy completion code into its own namespace at that point and some better test coverage.
Oh right. That makes sense (on a high-level). I haven't seen the codebase though, but will have a look now
@snoe Which LSP capability(?) should I be looking at? Also, which part of the clojure-lsp
codebase?
@nicdaoraf it would just be the completion capability. Here's the code: https://github.com/snoe/clojure-lsp/blob/master/src/clojure_lsp/handlers.clj#L173 https://github.com/snoe/clojure-lsp/blob/master/src/clojure_lsp/handlers.clj#L593
The latter might be useful because that determines some sort of cursor context.
Sweet thanks. I'll have a look later. I'm still amazed that it takes this little code to do stuff using Clojure. I'm willing to bet the JS counterpart of this is 10x more verbose
well, it's built on a lot of libraries, eclipse's lsp4j and rewrite-clj in particular
and kondo of course
I suppose, but so are most JS apps. By the way, my workflow ATM is: • In emacs config, I have
(setq lsp-clojure-server-command '("java"
"-jar"
"path/to/clojure-lsp/target/clojure-lsp-release-20201009T224414-standalone.jar"))
• I change stuff, build the jar via lein uberjar
• Restart workspace's clojure LSP session
• See changes
What's your workflow like?@nicdaoraf I launch like this https://github.com/snoe/dotfiles/blob/master/home/.vim/coc-settings.json#L9-L10 There's a repl that launches that you can connect to so you don't have to restart and can just eval anything that's not in main.clj.
I also use tests a lot because it's still pretty stateful
so lein test-refresh
is very helpful
> can just eval anything that's not in main.clj. Sorry, but what do you mean by this?
And cool, I'll see if I can wrap my head around the tests. Also, stealing stuff from your lein profiles 😛
No, currently there is no such option 😕 But if you have a ns imported with alias in another workspace, example:
(ns a
(:require [my.c :as c]))
When you write in another namespace:
(ns b)
(c/foo)
with the cursor at the unimported namespace, clojure-lsp
will be able to add the required because already know that c/
refer to my.c
.
You just need to call the lsp-execute-code-action
and select add missing namespace