Fork me on GitHub
#lsp
<
2023-05-09
>
Matt Ford08:05:31

Consistency in Emacs completion (not entirely sure this is the right place 🙂 ) doesn’t feel great to me. With the patches in this https://clojurians.slack.com/archives/CPABC1H61/p1683265127373769 I can load up a file and have a pretty good completion experience with no REPL. Not everything works Thread/ for example (System/ does work) and I guess anything you need the REPL for - importantly local project namespaces work nicely. I fire up CIDER which takes over and things like Thread/ start to work but local project namespaces don’t complete until I remember to evaluate the relevant files or every file in the project (sometimes that’s not possible). Is it possible to have CIDER completion fallback to LSP completion? Or am I doing something wrong?

borkdude08:05:03

Yes, this is possible. Let me look it up

borkdude08:05:58

Hmm, sorry, my fallback was about something else, find-definition: https://github.com/borkdude/prelude/blob/3018a3b99de894167a01d0273768f9fc077f92a3/personal/init.el#L412-L421 but perhaps you can create a similar completion fallback, haven't tried myself

mpenet08:05:43

(add-hook 'cider-mode-hook (lambda () (remove-hook 'completion-at-point-functions #'cider-complete-at-point t)))

mpenet08:05:47

at least with eglot that works

mpenet08:05:53

I suppose it's the same with lsp-mode

mpenet08:05:08

you'd get the previous entry for completion-at-point-functions

mpenet08:05:12

that would make lsp do completion even in cider enabled buffers. There's no merging of candidates

👍 2
borkdude09:05:09

Perhaps these tricks can be captured in the clojure-lsp docs / cc @UKFSJSM38

djm09:05:02

You can use cape (https://github.com/minad/cape) to combine lsp and cider completions, if that’s closer to what you want.

Matt Ford09:05:26

ohhhh - that cape looks interesting thanks!

djm09:05:24

Yeah, it’s nice - just add something like this to completion-at-point-functions: (cape-super-capf #'cider-complete-at-point #'lsp-completion-at-point)

djm09:05:15

(Well, not quite “just add” - either make sure it’s before the lsp and cider functions, or remove them).

ericdallo10:05:24

The completion of .java files ( like JDK classes) is WIP in a open PR waiting for clj-kondo, soon should be available

ericdallo10:05:06

I was thinking in have a page in clojure-lsp docs with tips and tweaks for each editor for the most common questions, would be helpful indeed

borkdude10:05:01

I'm actually waiting for someone to help me get that PR working locally ;)

Matt Ford10:05:42

> The completion of .java files ( like JDK classes) is WIP in a open PR waiting for clj-kondo, That was the thread I referred to - some things like Thread/ didn’t work still - and I guess any macro stuff.

Matt Ford11:05:47

I did this

;; Add extensions
(use-package cape
  :init
  (defalias 'cape-cider-lsp
    (cape-super-capf #'cider-complete-at-point #'lsp-completion-at-point))
  (add-to-list 'completion-at-point-functions #'cape-cider-lsp)
  (add-to-list 'completion-at-point-functions #'cape-file))

(use-package cider
    :hook (cider-mode . (lambda () (add-to-list 'completion-at-point-functions #'cape-cider-lsp))))
And it worked a treat, using cider and falling back to lsp when cider didn’t find anything

shaunlebron20:05:44

I got tired of trying to setup clojure-lsp with vim. is there just a way I can find all references to a symbol using the cli?

ericdallo20:05:05

I plan to work in guides including setup on vim in the future, sorry about that

ericdallo20:05:36

there is no API function to find references yet, nobody asked for that yet as well, so please open a issue

shaunlebron20:05:59

it wasn’t for lack of guides, I followed three of them I found and had no luck

shaunlebron20:05:44

I’ll make an issue, thank you for your work

shaunlebron20:05:56

is there any part of the api I could call from a script so I could put together a cmd like clj-refs foo.bar/baz from a project root

borkdude21:05:29

@U061E2UBT what vim was this? neovim even has lsp functionality built-in now right?

borkdude21:05:09

All the information you need comes from clj-kondo analysis, you can use it directly: https://github.com/clj-kondo/clj-kondo/tree/master/analysis You can even get this analysis through babashka and https://github.com/clj-kondo/clj-kondo-bb to make a quick CLI tool

shaunlebron21:05:40

I’m using neovim. It looks like it has native support for it, but I just now looked it up after reading your comment

borkdude21:05:45

k. perhaps @U7ERLH6JX can help you out, he also uses neovim + clojure-lsp

shaunlebron21:05:03

thanks, I’ve run out of time to figure out much else today, but good to know kondo has an api for finding all refs to a var

shaunlebron21:05:15

thanks for the references

lispyclouds22:05:58

@U061E2UBT would you like to find references in nvim too or just the command line?

lispyclouds22:05:27

if its just from nvim, my nvim dotfiles like mentioned or the standard lsp setup works. when on the symbol, running :lua vim.lsp.buf.references() should do it. this could be bound to some key(s).

lispyclouds22:05:31

happy to answer any nvim specific things! also thanks a ton for parinfer, cant live without it 😄

🙏 1
shaunlebron03:05:21

thanks! I’ll have to look at this when I have more time, I’ll try the lua method next

lispyclouds08:05:15

These are the minimal steps that should get you going on clojure-lsp on nvim: • Make sure clojure-lsp is installed and on PATH • https://github.com/neovim/nvim-lspconfig is installed in nvim using your favourite package manager • This config is there to hook clojure-lsp up:

local lspconfig = require("lspconfig")
lspconfig.clojure_lsp.setup({})
• Opening up a clojure file after all this is done, should get everything working • Bonus: https://github.com/gpanders/nvim-parinfer 😛 The setup I have is a bit more involved and nuanced but same in spirit.