Fork me on GitHub
#lsp
<
2022-12-16
>
practicalli-johnny13:12:49

Should Clojure LSP support completion of function names in a library using the aliases defined in the requires of an ns forms? In this example (https://github.com/practicalli-john/completion-testing) I was expecting completion when typing edn/ or io/ but with LSP alone there is no completion of function names in these libraries. The full library name is recognised, i.e. but functions are also not completed when using the full name

(ns practicalli.project
  (:require [ :as io]
            [clojure.edn :as edn]))

(def config (-> "deps.edn"
                slurp
                ))    ; typing edn/ here does not show completions
This has been tested with LSP :: lsp-mode <tel:202211302254|20221130.2254>, Emacs 28.1, gnu/linux and similar results with Neovim 8 (although that does seem to autocomplete when the full name is used, i.e. ). When using CIDER / Conjure with the REPL (without LSP) then completion works for the aliases as soon as I evaluate the relevant buffer or ns form. Switching LSP back on blocks the completion that CIDER was providing, so there may also be a conflict in the client or a missing setting. The completion from Conjure for aliases still works via the REPL with Clojure LSP enabled though, also suggesting there is an issue with Emacs lsp client. Does this make any sense? Any known issues?

ericdallo13:12:36

yes, it should work

ericdallo13:12:06

my guess is that your emacs completion backend is using cider and not lsp

practicalli-johnny15:12:19

Thanks. I've added that config but still have the same issue. There must be another issue with the Emacs configuration somewhere, I'll investigate further. Good to know it should be working though. Thank you

ericdallo15:12:10

👍 Maybe compare with my config and check if you missed anything

practicalli-johnny16:12:03

So completion is working for some namepaces (without any additional config), i.e. if I add a practicalli/utils.clj file to the project and require [practicalli.utils :as utils] then I get completion on utils/ So it seems to be namespace specific, but those are two namespaces from org.clojure/clojure so should be there in every project.... I'll do some more investigation.

ericdallo16:12:54

Sounds like classpath scan issues, so completino and lots of other features may be working only for project analysis, can you confirm you clojure-lsp version via lsp-clojure-server-info ?

practicalli-johnny17:12:16

:server-version "2022.11.03-00.14.57",
 :clj-kondo-version "2022.11.02",
If i manually copy the clojure/edn.clj from the Clojure source code into the project src directory, then LSP is autocompleting. so I concur it seems some kind of class path issue. I see there is a newer version of clojure-lsp, so I will give that a try

👍 1
practicalli-johnny18:12:42

I seem to have success 🤞 I updated clojure-lsp, lsp-mode in Emacs, clojure-cli, removed an .lsp config and then removed my usual .config/clojure-lsp configuration (that is when even utils would not complete any more). Adding my config back in and restarting everything and it seem to work now, both in Emacs and Neovim. Hopefully it stays that way. Thanks for the advice.

👍 1
Drew Verlee19:12:44

@U05254DQM why would updating those matter? was the old .lsp config just a project specific one or was that a global config? I suspect if anything it might be the .config/clojure-lsp if that somehow aged and is broken. Asking because (as you know) i have the same issue.

Drew Verlee19:12:39

i don-t have a .config/clojure-lsp in my project or root. So that can't be it.

practicalli-johnny20:12:16

I dont have any idea why it works and there are still a few inconsistencies, especially with aliases from the Clojure library. I'll experiment with other libraries.

practicalli-johnny22:12:10

Further experiments just make this even more weird, specifically in Emacs. Neovim seems to be working consistently at the moment. In Emacs, some alias names for a library wont complete, but changing the name to something very different then does make it complete. Some libraries will complete with the fully qualified domain, eg. clojure.inspector but [clojure.inspector :as inspector] doest not complete on inspector/. If I change that to [clojure.inspector :as gadget] then it will complete on gadget/ Totally bizarre. This suggests that some names are discarded or somehow clash, but this is just a wild guess and have no idea if that is even feasible or relevant. As its now working on Neovim, it seems specific to the lsp client side in Emacs and/or completion config, or possibly a conflict with Cider (clojure-mode as this happens without the REPL running). It may also be related to LSP client package versions and/or configuration.

Drew Verlee02:12:51

Yeah, john this is the behavior i have been seeing as well. Making an error report it has been really hard and because it comes and goes im always tempted to just move on and deal with it, but it's been a huge thorn in my side.

ericdallo13:12:40

There is a way to debug that and for sure know if it's a server or client side issue, enable lsp-log-io restart server, and then lsp-show-workspace-log will show the communication between client and server and you can check what server is returning during completion request

👀 1
Drew Verlee02:12:27

@UKFSJSM38 i don't have a lsp-show-workspace-log command.

ericdallo02:12:40

Sorry, it's lsp-workspace-show-log

Drew Verlee02:12:10

my emacs command finder needs AI

ericdallo02:12:40

I always search like lsp workspace show , then the search results are always great and would avoid mistypes like that

Drew Verlee02:12:17

oh weird, that does show it

Drew Verlee02:12:35

adding the dashes apparently locks it down too much

ericdallo02:12:31

it's like each space requests a a subsearch, it's how ripgrep works

Drew Verlee02:12:20

thats super helpful.

Drew Verlee03:12:00

What would the autocomplete look like in the logs roughly? There is so much activity. i don't see anything obvious.

ericdallo11:12:09

Search for completion response