lsp 2025-02-08

Is there a feature in clojure-lsp like the cljr-magic-require-namespaces of clj-refactor?

✅ 1

Somehow related to that. If I imported a wrong namespace (fat fingered), then I don’t have the option to import another one even after removing the require and reloading the namespace.

Do you think that can be solved somehow?

removing the require would make the symbol unresolved again and re-show the option to add the require

Keep in mind LSP has nothing related with REPL or reloading things

Well, I removed and saved the file, but the lsp-execute-code-action didn’t not pop it up, just the wrongly required one

after removing the require, you didn't receive a LSP diagnostics squiggle mentioning that symbol doesn't exist? I can't repro that, BTW it's something that happens all the time on my daily work, so I doubt there is a bug there

I needed to restart clojure-lsp

With “cached” state:

After restart:

It noticed that the symbol is missing, but it did not suggest me all the options, just one as you can see on the screenshot

there is no cache code-actions or diagnostics, that's weird

if you can make a consistent repro on https://github.com/ericdallo/clojure-sample, LMK

I’ll try to do that

It does work there so far, I’ll try to keep an eye when it happens

We have a debug namespace in our project that is only being used rarely in the development, therefore it is not loaded in any of the namespaces. When I try to lsp-clojure-add-missing-libspec, then it loads the incorrect namespace all the time.

Yeah, this is the most recommended way ☝️

IIRC cljr-add-missing-libspec asks for the right library if there are multiple matches.

clojure-lsp as well

I can see, that I need to select the right library when using lsp-execute-code-actions, but I am asking bout the lsp-clojure-add-missing-libspec function here

the lsp-execute-code-actions delegates to the add-missing-libspec + add-missing-import feature

the best lib to require is already sorted via code actions

My question is about to make lsp-clojure-add-missing-libspec behave similar as cljr-add-missing-libspec and ask for the user input to select the right matches after lsp-clojure-add-missing-libspec has been called.

I can live with the current solution, I am just curious about the design decision here

not easy, because those are commands and they are generic, so the clients (editors) just know that they can spawn them, and server process and return edits to the editor apply. the code actions is a feature that can show available code changes in current line/col, and each code changes is related to a command

👍 1

changing this behavior would need to workaround the LSP protocol for each editor

or create a new command that asks user too, it's a option, although doesn't look like a priority

That makes sense. Thank you!

👍 1