Fork me on GitHub
#lsp
<
2023-06-23
>
lassemaatta12:06:48

More questions about completions: how does clojure-lsp handle keyword completions (ie. how are the available candidates chosen/found)?

lassemaatta12:06:28

In my current setup it looks like completing something like :foo| suggests candidates like :foo/bar, :foobar etc but this seems to require that these keywords appear in the same namespace

ericdallo12:06:42

so there are checks for aliased keywords and lots of corner cases

ericdallo12:06:44

So AFAI remember, we don't have logic to exclude namespaced keywrods, so :foo| will bring all namespaced and simple keywords

lassemaatta12:06:26

Ah sorry, I may have been unclear in my problem statement: what I'm seeing is that if I go to a different namespace, completing for :foo| returns no matches

lassemaatta12:06:13

That is, the set of all possible candidates seems to be derived from the keywords from the current namespace, and nowhere else

ericdallo12:06:04

I see, I think that was on purpose for simple keywords

lassemaatta12:06:50

ah, ok. Does that also apply to keywords like :foo/bar?

ericdallo12:06:46

checking https://github.com/clojure-lsp/clojure-lsp/blob/2124c1c3e0d2e3fcd00eb128fe55b0c0843111c4/lib/src/clojure_lsp/feature/completion.clj#L302, yes, and I think it's not intended, but a tech issue. we complete only things available in the current ns for when we identified it's a keyword

ericdallo12:06:21

I think that deserves a issue, but I'd like to see more use cases in the issue for why that makes sense

lassemaatta12:06:25

interesting, I guess there's some special handling for clojure.spec? Registering a spec in ns1 with some keyword enabled completion for that kw in ns2.

ericdallo12:06:14

I'm not finding the code proving that works, but it should, I did for spec and reframe keyword-defs

lassemaatta12:06:26

right, ok. Well I'm quite happy to know this is at least somewhat the expected behaviour and thanks a bunch for investigating this

lassemaatta12:06:28

regarding the use case: we use a lot of qualified keywords for datomic attributes, like :user/first-name and such and it might be nice to be able to complete those anywhere

ericdallo12:06:53

yeah, that makes sense, that would be useful for my day development with datomic as well 😂 I think we only present those keywords if they were written in the current ns indeed, would be nice to improve that if this behavior is confirmed for namespaced keywords, not sure for simple keywords

lassemaatta12:06:12

I can write up a feature request issue for this with some use case examples

ericdallo12:06:43

that would help, thanks!

voltecrus08:10:55

piggybacking on this conversion - is there an option to enable global keyword completions for all keywords a la intellij + cursive? Meaning let's say I have :access-token in one namespace and I am in a different namespace, I'd like to get that completion too.

ericdallo12:10:22

cursive doesn´t use lsp, it has it's own way of completions. There is https://github.com/clojure-lsp/clojure-lsp-intellij but it's not compatible with cursive

lassemaatta12:10:21

I think the idea was that cursive already provides completion for all keywords so would it be possible for clojure-lsp to also support such a functionality

ericdallo12:10:42

ah yes, it's possible to support that indeed on clojure-lsp

lassemaatta12:10:05

sad RAM noises in my 200k+ loc clojure projects 🙂

ericdallo12:10:29

clojure-lsp already has all keyword analysis, so that should not affect performance 🤞 but is that a thing? when do you want to complete keywords from other ns in this ns?

nice 1
ericdallo12:10:41

I actually removed that feature on purpose when implement keyword support 😅

ericdallo12:10:56

because otherwise you would see lots and lots of keywords on completion

ericdallo12:10:30

like, should we show only project keywords? keywords from deps as well? I'm not understanding exactly when this is useful

voltecrus14:10:52

Let's say you use a long keyword several times in your codebase, something like :user-settings. Not only do you save keystrokes when you need to introduce it to a different namespace, but more importantly you save on keyword implosion since in a large codebase it's a matter of when not if before someone adds :users-settings Yes, you get more completions but they've never bothered me since you can easily narrow down to the one you want and modern completion sorting algorithms are quite good at getting you there with a few keystrokes.

ericdallo15:10:40

Yeah, makes sense, I hope this not affects completion payload performance that much since will be returning way more keywords, but we can start with only project keywords for now and move keywords from current ns to top of suggested items

🙌 1
ericdallo16:10:58

Feel free to create a issue mentioning this feature request

voltecrus08:10:48

Yeap, will do! Thanks!