Fork me on GitHub
#lsp
<
2022-07-26
>
nate00:07:53

For this code:

(defn foo []
  "baz")

(comment
  (foo))

#_(foo)
If I am on the (foo) in the comment block, go to definition works. However, if my cursor is on the (foo) in the last line, go to definition fails (`[coc.nvim] definition not found`). Is it possible to support go to definition from forms in a discard?

ericdallo01:07:07

It'd be a little bit harder as we would need to clj-kondo provide analysis for commented forms, but sounds possible. Not sure how common would be that too... WDYT @U04V15CAJ?

nate02:07:56

I tend to use discard forms instead of comment forms for Rich Comments as my editor/plugin has a very-useful “eval top-level form” command that lets me run code without moving my cursor to a specific location. I don't know how common my use case is.

borkdude05:07:58

Clj-kondo already provides analysis for that unless you disable that with skip-comments true

borkdude05:07:44

But not in discarded forms, those are just ignored

seancorfield05:07:30

@U0510902N For comparison, Calva treats forms inside comment as top-level forms so the usual shortcut for eval works (even tho' they are not really top-level forms). Perhaps you could petition the coc.nvim maintainer(s) to add support for that too?

nate14:07:49

@U04V70XH6 that's awesome. Conjure (my repl plugin) is getting closer to supporting that reliably. It works for me sometimes, could be related to a Neovim bug.

dpsutton01:07:03

I just did lsp-clojure-server-info and I see this entry: > :port “NREPL only available on :debug profile (`make debug-cli`)“, what’s the story of this? Is this an nrepl port to lsp itself or can you pass a port to lsp of the running project?

ericdallo01:07:28

LSP itself for debugging clojure-lsp :)

dpsutton01:07:44

neat. I was wondering if you could provide a port to your running repl. Would be awesome if i could tell it there’s a socket repl at 50505 and it can query all it likes

ericdallo01:07:52

Not sure if I understood but that would probably not work with native images

nate17:07:53

I updated to the latest version 2022.07.24-18.25.43 so I could try out the experimental scanning feature, but I haven't enabled it yet. I did notice that the startup status messages don't seem to be coming through. Were they removed?

nate17:07:59

ah, thank you for that, must have missed it

nate18:07:33

It looks like the coc.nvim project globally disabled startup progress indicators recently. I was able to get the progress back by adding:

"progressOnInitialization": true
to the clojure-lsp language server config. Here's the https://github.com/justone/dotfiles-personal/commit/e5a9934163ba40f27a789e2f867df663d946add7 for reference. Now the progress shows up in the lower right as a not-too-pretty-but-very-useful popup.

👍 3
snoe18:07:03

nice find, thanks!

ericdallo20:07:30

Do you know why coc disabled that by default?

nate22:07:09

It looks like they added the new floating window and disabled it by default.

nate18:07:33

It looks like the coc.nvim project globally disabled startup progress indicators recently. I was able to get the progress back by adding:

"progressOnInitialization": true
to the clojure-lsp language server config. Here's the https://github.com/justone/dotfiles-personal/commit/e5a9934163ba40f27a789e2f867df663d946add7 for reference. Now the progress shows up in the lower right as a not-too-pretty-but-very-useful popup.

👍 3
Chase23:07:51

I've noticed when I have something like (:require [ :as io]) I don't get autocompletion/doc suggestions from the LSP when I am writing something like (io/| ) in the source file where | is my cursor position. I do get such help if I write out the whole () and I do get such help if I've required [clojure.string :as s] and am writing something like (s/| ) . I haven't tracked down which ones this works for and which it does not but just curious if this is a known issue? Or is it a specific editor issue? (I'm using neovim w/ conjure and coc.nvim).

ericdallo23:07:30

I suspect you are using a outdated clojure-lsp, what's you version?

Chase23:07:07

clojure-lsp 2022.07.24-18.25.43

ericdallo23:07:23

clojure.string working and http://java.io not is weird. Could you create a repro sample where I can try?

ericdallo23:07:37

Also, check clojure-lsp server logs

Chase23:07:39

Will do. How do I check the logs?

Chase00:07:09

In trying to make that little sample repo for you, I'm getting slightly different behavior. The (s/| automatically pops up with suggestions with a [LS] designation as the source, but if I do (io/| and then press TAB I do now get the suggestions with a [CLJ] source.

ericdallo00:07:17

Not sure what is that, probably something from your editor, but I'd guess one is from the LSP and the other from the repl or built-in editor

Chase00:07:26

Unless I have already written something like (io/reader ...) before because then it autosuggests that only with the [A] source which I think means it's just reading the file for current suggestions.

👍 1
Chase01:07:22

Here are those logs

Chase01:07:03

I think the multiple :resolve-completion-item was when I was TAB -ing through the suggestions for (s/| and then after that I tried with (io/|

Chase01:07:08

So if I had to guess, the LS is giving the suggestions for clojure.string and then the repl/editor is giving the spotty suggestions for even when using the full namespace instead of just (io/

ericdallo11:07:46

@U9J50BY4C from the logs we can see clojure-lsp is returning completion items, which looks correct. Is there a repro where I can try?

Chase14:07:01

Hmmm. Are you asking for me to get a setup on github for neovim with conjure and coc.nvim configurations? I'm not sure how that would work. Otherwise, I would just be putting up a bare bones clojure repo that requires in [ :as io]. No worries though, it might just be some silly thing I have in my setup, I wouldn't want you spending a lot of time on that.

ericdallo14:07:48

I just need the project so I can try exactly what you are trying and check if the project setup is correct

Chase16:07:17

Here ya go: https://github.com/Chase-Lambert/clojure-scratch I feel like I'm already taking up too much of your time though

ericdallo17:07:36

it seems to work on emacs, so maybe something with vim? could you get logs between client and server https://clojure-lsp.io/troubleshooting/#client-server-log

Chase17:07:19

I'll work on getting that for you. I'm also asking in #conjure to see if this is just my setup or if others are seeing the same issue.

Chase17:07:35

I think this is the log you are looking for?

2022-07-27T12:08:45.809 INFO (pid:2543) [services] - registered service "languageserver.clojure-lsp"                                                                                                 
2022-07-27T12:08:45.818 INFO (pid:2543) [coc-conjure] - CoC conjure enabled!                                                                                                                         
2022-07-27T12:08:45.839 INFO (pid:2543) [plugin] - coc.nvim initialized with node: v18.4.0 after 224ms                                                                                               
2022-07-27T12:08:57.371 INFO (pid:2543) [services] - clojure-lsp state change: stopped => starting                                                                                                   
2022-07-27T12:08:57.398 INFO (pid:2543) [language-client-index] - Language server "languageserver.clojure-lsp" started with 2742                                                                     
2022-07-27T12:08:59.501 INFO (pid:2543) [services] - clojure-lsp state change: starting => running                                                                                                   
2022-07-27T12:08:59.543 INFO (pid:2543) [services] - service languageserver.clojure-lsp started                                                                                                      
2022-07-27T12:09:15.101 WARN (pid:2543) [completion] - Suggest not triggered with input "", minimal trigger input length: 1                                                                          
2022-07-27T12:09:15.102 WARN (pid:2543) [handler-format] - Format on type provider not found for buffer: file:///home/chaselambert/projects/clojure/scratch/src/scratch/core.clj                     
2022-07-27T12:09:23.608 INFO (pid:2543) [attach] - receive notification: startCompletion [                                                                                                           
  {                                                                                                                                                                                                  
    word: 'io/',                                                                                                                                                                                     
    bufnr: 3,                                                                                                                                                                                        
    col: 1,                                                                                                                                                                                          
    disabled: [],                                                                                                                                                                                    
    filepath: '/home/chaselambert/projects/clojure/scratch/src/scratch/core.clj',                                                                                                                    
    indentkeys: '',                                                                                                                                                                                  
    blacklist: [],                                                                                                                                                                                   
    line: '(io/)',                                                                                                                                                                                   
    filetype: 'clojure',                                                                                                                                                                             
    linenr: 6,                                                                                                                                                                                       
    input: 'io/',                                                                                                                                                                                    
    colnr: 5,                                                                                                                                                                                        
    changedtick: 489                                                                                                                                                                                 
  }                                                                                                                                                                                                  
]                                                                                                                                                                                                    
2022-07-27T12:09:39.062 INFO (pid:2543) [attach] - receive notification: openLog [] 

Chase17:07:16

First I checked the autocompletion with (s/| and then I did it with (io/|

ericdallo17:07:56

No, it should be a log which logs whant client and server are sending and receiving, usually as json

Chase17:07:34

Ok, I think I'm seeing that but it might be 3000+ lines long

Chase17:07:25

I can open it in the editor using the command the coc.nvim docs told me to use but I don't know where that file is quite yet. lol sorry give me a second

ericdallo17:07:25

I think it's best to restart the server, repro the bug and then get the log, to avoid too many logs

Chase17:07:25

Yeah, I've done that. It's still 1200 lines but I just can't figure out how to save it or find it in my system. It's like a temporary vim buffer that disappears showing at output:///languageserver.clojure-lsp Sorry about this, I'm trying to figure it out

👍 1
Chase17:07:55

I guess I have the tracing log set to "verbose" I can change that and give you a smaller log.

ericdallo17:07:43

From the logs it seems you tried to complete for the code (i|) ?

Chase17:07:10

hmmm, maybe it's trying autocompletion too quickly then. I'm definitely getting the cursor to (io/ and just letting it sit there. Someone else on the #conjure channel is seeing the same behavior.

ericdallo17:07:06

From the logs, this is the code sent on the last didChange request:

(ns scratch.core\n  (:require \n    [ :as io]))\n\n(i)\n\n\n(defn -main [])\n

Chase17:07:05

I think line 1216 is showing the (io/| properly now

ericdallo17:07:22

right, but no completion requests after that 😅

Chase17:07:42

Haha, I thought that was the whole issue lol

ericdallo17:07:50

My guess is that your editor is requesting completion and caching it

Chase17:07:01

I can try with the (s/| first and see how that looks different.

ericdallo17:07:19

s is a small alias, rename it to str just to be similar to io

Chase17:07:27

ok, will do.

ericdallo17:07:10

Also, check if there is no flag to disable client completion cache if any, just to confirm there is nothing wrong on server side but on client

Chase18:07:42

lol, now I'm not getting [LS] completion for str or io

ericdallo18:07:16

So is it working as expected?

Chase18:07:37

I have to step away for a brief moment. When I get back I'll look for that client completion cache stuff

👍 1
Chase18:07:37

What's weird is the language server autocompletion works for s but not for str

Chase18:07:23

And not for clojure.string/

Chase18:07:57

So I imagine something is going on with coc.nvim and the language server. or the way conjure brings them both together.

☝️ 1
nate22:07:47

I'm seeing the same behavior with s vs string with the former completing and the latter not, very odd

nate23:07:59

I think I tracked it down to a recent change in coc.nvim. I did some git bisecting to weed out the commit where it stops working. See this thread in #conjure: https://clojurians.slack.com/archives/CK143P6D7/p1658963667671899

👍 1
snoe15:07:14

nice find; for completion I often find I have to manually trigger around / with this from the coc doc

" Use <c-space> to trigger completion.
if has('nvim')
  inoremap <silent><expr> <c-space> coc#refresh()
else
  inoremap <silent><expr> <c-@> coc#refresh()
endif

Chase15:07:20

I am now curious to compare the LSP experience with coc.nvim vs the inbuilt tools. I've been fighting off making the switch to a lua (or maybe even fennel) config but that could change if coc.nvim is starting to fall behind the LSP integrations of the "native" solution. Of course if it's just a tiny bug I could be making a mountain out of a molehill here

snoe15:07:18

I suspect they both have tradeoffs; most clients do as they are all trying to play catch up with vscode and the spec and fit it into their editor's quirks.

Chase20:08:46

Just for closure, this problem seems to have fixed itself when updating to the latest version of coc.nvim . (Also note that that update does include some frustrating breaking changes to the autocompletion workflow but it was decently easy to fix by using the changed example config on the main repo README.md. https://github.com/neoclide/coc.nvim/releases/tag/v0.0.82)

ericdallo20:08:35

Thanks for the update @U9J50BY4C!