lsp

frankitox 2025-07-08T23:42:05.247749Z

Hello! I see a ton of commands on the https://clojure-lsp.io/features/#execute-command. Is it possible to add my own custom commands?

frankitox 2025-07-08T23:46:51.506779Z

I'd like to be able to run a command that modifies my top requires for each Unresolved namespace X error on the current file

ericdallo 2025-07-09T00:31:01.360969Z

That's an idea I discussed with @andreribeirocamargo , it should be simpler now that we have sci integration for custom linters, we should have a similar feature. So these commands could be setup and have a function predicate to show them as code actions, which would be convenient. Feel free to create an issue about it,.it would help with priorization

frankitox 2025-07-09T17:23:42.915669Z

Well, I just managed to use the diagnostics information to run add-missing-libspec . I ended up with something like:

(fn add-missing-libspec [diagnostics uri]
  (let [unresolved (->> diagnostics
                        (filter (fn [{: code}]
                                  (= code :unresolved-namespace)))
                        (first))]
    (when unresolved
      {:command :add-missing-libspec
       :arguments [uri unresolved.lnum unresolved.col]})))

(fn get-lsp-client! []
  (->> (vim.lsp.get_clients)
       (filter (fn [client]
                 (= client.name :clojure_lsp)))
       (first)))

(let [bufnr 15]
  (let [client (get-lsp-client!)]
    (-?> (add-missing-libspec (vim.diagnostic.get bufnr)
                              (vim.uri_from_bufnr bufnr))
         (client:exec_cmd {: bufnr}))))
I'll skip creating the issue until I find something that really requires a custom command

frankitox 2025-07-09T18:01:37.079859Z

(☝️ the code is for neovim, using fennel)

ericdallo 2025-07-09T18:35:32.502139Z

Cool, looks promissing