emacs-lsp / lsp-mode

Emacs client/library for the Language Server Protocol
https://emacs-lsp.github.io/lsp-mode
GNU General Public License v3.0
4.78k stars 884 forks source link

Clojure-LSP and CIDER interaction: lsp affects negatively cider. #2445

Closed davidpham87 closed 3 years ago

davidpham87 commented 3 years ago

Describe the bug Cider and lsp-mode for clojure conflicts and lsp-mode effects negatively the behavior of Cider.

One of which is when inside a function call, cider displays the signature of the verb in the bottom message bar. (For example for max-keys, cider would show the 3 arities, wheras LSP only displays the first in the UI). Moreover, it seems LSP confuses cider and cider can't lookup any core docs or definition.

To Reproduce

  1. Download from cider melpa, and install the lsp-server for clojure.

  2. Activate both of them.

  3. Download and install babashka

    apt update
    apt upgrade
    apt install curl unzip
    curl -s https://raw.githubusercontent.com/borkdude/babashka/master/install
    bash install
  4. , and launch a nrepl-server

    bb --nrepl-server 1667

    Alternatively, one can download clojure and launch a nrepl.

  5. Write this file somewhere:

    (ns com.lsp.clojure.bug)
    (reduce + [1 2 3])
  6. Connect the cider session to the clojure file.

Expected behavior Normally, when the cursor is on the space of the cursor, cider displays clojure.core/reduce and several of the arities in the bottom message bar. However, with LSP, this is not the case. Moreover, when using the full clojure-cli version (ie. java + clojure.jar + nrepl) and with LSP is activated, one can not use cider-find-var on reduce (shortcut is M-.).

Which Language Server did you use lsp-clojure.

OS Ubuntu. Emacs GUI. Emacs version 28.0.50 native compiled.

nbfalcon commented 3 years ago

Can you try M-x cider-find-var manually? By default, lsp-mode replaces eldoc and xref to use the language server, so that is probably used instead. You can add the following to your config before lsp-mode is loaded (you'll need to restart Emacs):

(setq lsp-enable-xref nil)

to disable lsp-xref. You can use lsp-find-definition instead. lsp-eldoc can currently not be disabled though.

davidpham87 commented 3 years ago

Thanks a lot. the lsp-enable-xref trick worked like a charm with cider-find-var. However, the other issue (cider not displaying the arities in the message bar at the bottom) is not disappearing.

nbfalcon commented 3 years ago

The issue is that lsp-managed-mode adds lsp-eldoc-function unconditionally, with no way for the user to control that. We'd need something like lsp-eldoc-mode + a defcustom so this can be changed. However, I'd assume that cider-mode does the same, so a temporary workaround would be to somehow make cider-mode turn on after lsp-mode.

ericdallo commented 3 years ago

@yyoncho shouldn't we have a option to disable lsp-eldoc ?

yyoncho commented 3 years ago

@yyoncho shouldn't we have a option to disable lsp-eldoc ?

Yes.

davidpham87 commented 3 years ago

@nbfalcon The trick of loading cider after lsp works like a charm! I could close the issue, but it would be interesting to have this documented, maybe?

ericdallo commented 3 years ago

Yes @davidpham87, I'll try to create a documentation section "integrating lsp with cider" on clojure language docs or a tutorial page

nbfalcon commented 3 years ago

IMHO, more parts of lsp-mode need to be exposed as modes:

This way, lsp-mode would be more emacs-y. @yyoncho what do you think?

ericdallo commented 3 years ago

@nbfalcon I'm opening a PR right now about the semantic tokens :sweat_smile:

yyoncho commented 3 years ago

@nbfalcon ATM we are refactoring to minor modes + a flag. Initially, everything was just a flag. @ericdallo did that refactoring for a few features.

nbfalcon commented 3 years ago

Is someone working on lsp-eldoc-mode and lsp-document-highlight-mode already? There are lots of other fun new features in lsp-mode; I especially like monikers, since that would give us live-rename as can be found in Eclipse CDT and IntelliJ.

ericdallo commented 3 years ago

FYI: https://github.com/emacs-lsp/lsp-mode/pull/2447

yyoncho commented 3 years ago

Is someone working on lsp-eldoc-mode and lsp-document-highlight-mode already? There are lots of other fun new features in lsp-mode; I especially like monikers, since that would give us live-rename as can be found in Eclipse CDT and IntelliJ.

AFAIK no. What do you mean by monikers? I think that the new protocol has live rename.

nbfalcon commented 3 years ago

The "monikers" are the live rename, unless I confused something. It works like this: in lsp-rename we can request a list of all regions that have the symbol being renamed. They could then be edited in parallel, like iedit-mode. We could probably also add something to the minibufer-style lsp-rename so that they are all changed as the minibuffer contents change.

yyoncho commented 3 years ago

@nbfalcon IMHO that won't work, since rename might take several seconds. Here is what you are describing in the new protocol: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_linkedEditingRange

nbfalcon commented 3 years ago

Sorry, I meant textDocument/linkedEditingRange.

davidpham87 commented 3 years ago

I can actually be more precise in the cider mesasge tool behavior: when applying the options {:show-docs-arity-on-same-line? true} in ~/.lsp/config.edn, lsp mode replace the cider message on the bottom bar with one line arity. However, cider usually displays the version of the repl doc, which I find more relevant. Is it still ignore by removeing eldoc?

ericdallo commented 3 years ago

That's a good idea for clojure-lsp displays the version too ;)

No, if you in the future disable the lsp-eldoc feature, it will not override cider eldoc messages.

yyoncho commented 3 years ago

Do we have more work on that?

ericdallo commented 3 years ago

This conflict still exists, but clojure-lsp was improved a lot and do most of those things: ✅ "wheras LSP only displays the first in the UI": This could be fixed with show-docs-arity-on-same-line? true ✅ "it seems LSP confuses cider and cider can't lookup any core docs or definition": this probably could happen in frameworks like doom or spaceemacs and it depends on how they configure the find-definition, using lsp-find-definition will probably don't cause that issue. ❓ "However, cider usually displays the version of the repl doc, which I find more relevant.": I didn't find any repl doc version on cider docs display, if you meant the file path which includes the lib version, clojure-lsp started to include this as well.

cider image

lsp-describe-thing-at-point image

simon-katz commented 3 years ago

How about this as a way to avoid blatting the CIDER eldoc info?…

(defun nomis/lsp-eldoc ()
  ;; Don't blat signatures from CIDER.
  (unless (ignore-errors (cider-repls))
    (lsp-hover)))

(setq lsp-eldoc-hook '(nomis/lsp-eldoc))
yyoncho commented 3 years ago

Closing based on https://github.com/emacs-lsp/lsp-mode/issues/2445#issuecomment-831924422 . Please reopen or file another issue if there are more things to be adressed.