Fork me on GitHub
#lsp
<
2024-04-29
>
andrea.crotti13:04:59

ok so I figured out why in my cider repl I get more complete completion than my normal clojure buffer, simply lsp-completion-mode is enabled in the clojure buffer and not in the cider one. But in theory it should work anyway right, I use company now and I have lsp-completion-provider set to capf , isn't that the right setting?

andrea.crotti13:04:16

my configuration atm is :

(use-package lsp-mode
  :custom
  ;; (lsp-pylsp-plugins-autopep8-enabled  nil)
  (lsp-pylsp-plugins-black-enabled t)
  ;; (lsp-pylsp-plugins-flake8-enabled nil)
  (lsp-pylsp-plugins-isort-enabled t)

  :hook ((lsp-mode . lsp-enable-which-key-integration)
         (c-mode . lsp)
         (c-ts-mode . lsp)
         (c-sharp-mode . lsp)
         (cc-mode . lsp)
         (clojure-mode . lsp)
         (clojure-ts-mode . lsp)
         (clojurec-mode . lsp)
         (clojurescript-mode . lsp)
         (dockerfile-mode . lsp)
         (go-mode . lsp)
         (java-mode . lsp)
         (json-mode . lsp)
         (elixir-mode . lsp)
         (elm-mode . lsp)
         (graphql-mode . lsp)
         (haskell-mode . lsp)
         (html-mode . lsp)
         (lua-mode . lsp)
         (json-mode . lsp)
         (kotlin-mode . lsp)
         (markdown-mode . lsp)
         (python-mode . lsp)
         (python-ts-mode . lsp)
         (rust-mode . lsp)
         (scala-mode . lsp)
         (sh-mode . lsp)
         (typescript-mode . lsp)
         (terraform-mode . lsp)
         (ocaml-mode  . lsp)
         (tuareg-mode . lsp)
         (web-mode . lsp)
         (yaml-mode . lsp)
         (xml-mode . lsp)
         (zig-mode . lsp))

  :bind (("M-?" . lsp-find-definition)
         ;; ("M-/" . lsp-find-references)
         ("M-'" . lsp-treemacs-call-hierarchy))

  :config
  (dolist (m '(clojure-mode
               clojurec-mode
               clojurescript-mode
               clojurex-mode))
    (add-to-list 'lsp-language-id-configuration `(,m . "clojure")))
  (add-to-list 'lsp-language-id-configuration '(direnv-envrc-mode . "shellscript"))
  (add-to-list 'lsp-language-id-configuration '(forge-post-mode . "text"))

  :custom
  (gc-cons-threshold 100000000)
  (lsp-clojure-custom-server-command '("/opt/homebrew/bin/clojure-lsp"))
  ;; change it to :none if using corfu
  (lsp-completion-provider :capf)
  (lsp-completion-show-detail t)
  (lsp-dired-mode t)
  (lsp-eldoc-enable-hover t)
  (lsp-eldoc-render-all nil)
  (lsp-enable-file-watchers nil)
  (lsp-enable-folding t)
  (lsp-enable-indentation nil)
  (lsp-file-watch-threshold 5000)
  (lsp-headerline-breadcrumb-enable t)
  (lsp-headerline-breadcrumb-segments '(symbols))
  (lsp-idle-delay 0.5)
  (lsp-keymap-prefix nil)
  (lsp-lens-enable t)
  (lsp-log-io nil)
  (lsp-signature t)
  (lsp-treemacs-sync-mode t)
  (read-process-output-max (* 1024 1024)))

ericdallo13:04:48

I think your clojure-mode is using lsp-mode completions while the repl is using the cider ones which uses runtime analysis which is more assertive that static analysis (lsp)

ericdallo13:04:21

you could have a config that try to use repl completion unless repl is not connected, falling back to lsp-mode

andrea.crotti13:04:22

yeah I thought that what was I had 😄

andrea.crotti13:04:43

but clearly, does anyone have the right magic spell to get this fallback to work?

andrea.crotti13:04:31

tbf I very rarely need completion on a project if I don't have cider running

andrea.crotti13:04:44

so maybe I can just disable the lsp-completion

Lari Saukkonen14:04:46

I have lsp as fallback and malli based cider completion for data as first. I think this is the core how I’m able to prioritize cider/malli over lsp:

(after! (clojure-mode cider-mode)
  ;; +clojure--cider-disable-completion only gets defined on cider-mode, hence
  ;; the separate after
  (remove-hook! 'cider-mode-hook #'+clojure--cider-disable-completion)
  (add-hook! 'cider-mode-hook
    (defun my/clojure-custom-completions ()
      (setq completion-at-point-functions '(cider-complete-at-point lsp-completion-at-point)))))

andrea.crotti14:04:40

mm actually even disabling is not so easy

(lsp-completion-mode nil)

andrea.crotti14:04:51

I've added that and even restarted Emacs just in case

andrea.crotti14:04:03

but it still shows as enabled in all the clojure buffers

ericdallo14:04:44

I think you want lsp-completion-enable variable

andrea.crotti14:04:45

ah right it was lsp-completion-enable maybe