reddit / emacs
What is your lsp configuration? What do you think works the best?
ank_itsharma · 2022-07-27 18:01
I have been playing with different lsp configuration. My main development revolves around writing C++ and Python code. For python I was using **pyright** with microsoft language server. For C++, I was using **clang**. But, the completion at point was not always accurate and I had to look for other options.
Recently, I discovered `lsp=bridge` which worked out of the box for both the languages but this also came with some caveats. Sometimes in C++ code I would get weird suggestions or no suggestions at all.
Here is my config for `lsp-bridge`
(require 'lsp-bridge)
(global-lsp-bridge-mode)
;; mapping keybindinds for lsp-bridge
(map! :leader
(:prefix-map ("l" . "lsp-bridge")
:desc "Find definition" "d" #'lsp-bridge-find-def
:desc "Find implementation" "i" #'lsp-bridge-find-impl
:desc "Find references" "R" #'lsp-bridge-find-references
:desc "Rename" "r" #'lsp-bridge-rename
:desc "Restart LSP Bridge" "p" #'lsp-bridge-restart-process
:desc "Kill all process" "k" #'lsp-bridge-kill-process))
(setq lsp-bridge-c-lsp-server 'ccls)
;; to get the paths: clang -v -fsyntax-only -x c++ /dev/null
(after! ccls
(setq ccls-initialization-options
'(:clang (:extraArgs ["isystem/usr/local/include"
"isystem/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1"
"isystem/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/13.1.6/include"
"isystem/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include"
"isystem/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include"
"isystem/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"]
:resourceDir "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/13.1.6"))))
Now, I am thinking to switch to `eglot` for lsp configuration. Need some suggestions. What are you using for languages like Python and C++? How is it working out for you?
Horrih · 2022-07-27 18:06
I use lsp-mode, clangd anf pyright just as you do.
I'm afraid to use eglot because i use dap-mode for debugging, which relied on lsp-mode
#Clangd
Ok since a few months.
I had frequent crashes of clangd until I upgraded to the latest version. No issue on completion accuracy, more on the side of formating on type : i should disable it some day
Sometimes lsp-mode hangs when opening a new buffer and i have to restart emacs. It happens if i move in a file before the server has initialuzed. Seems more an lsp-mode issie than clangd
#pyright
really sluggish, and suggestions sub-par so far i think i'll try another server soon
ZecaKerouac · 2022-07-27 19:08
I use lsp-mode, pyright and ccls. I am by no means an experienced user, but it has worked really well for me.
Let me know if you need more information about that.
(use-package lsp-mode
:commands (lsp lsp-deferred)
:init
(setq lsp-keymap-prefix "C-c l") ;; Or 'C-l', 's-l'
:config
(setq lsp-enable-on-type-formatting nil)
(setq lsp-prefer-flymake nil)
(setq lsp-file-watch-threshold 3000)
(setq lsp-completion-no-cache t)
(lsp-enable-which-key-integration t)
(advice-add #'lsp--auto-configure :override #'ignore)
)
(use-package ccls
:defer t
:hook ((c-mode c++-mode objc-mode cuda-mode) .
(lambda () (require 'ccls) (lsp)))
)
;;workaround for ccls bug
(advice-add 'json-parse-string :around
(lambda (orig string &rest rest)
(apply orig (s-replace "\\u0000" "" string)
rest)))
(use-package lsp-pyright
:defer t
:hook ((python-mode) . (lambda () (require 'lsp-pyright) (lsp)))
:if (executable-find "pyright")
:config
(setq lsp-pyright-python-executable "/usr/bin/python3")
(setq lsp-pyright-python-executable-cmd "python3")
(setq lsp-pyright-stub-path "")
(setq lsp-pyright-use-library-code-for-types nil)
(setq lsp-pyright-auto-import-completions t)
(setq lsp-pyright-auto-search-paths t)
(setq lsp-pyright-extra-paths ".")
)
HeyItsLP · 2022-07-27 19:12
I use eglot, pyright and clangd. Works well enough.
your_sweetpea · 2022-07-27 20:03
I also use lsp-bridge but recently I've put some serious consideration to forking it. It's probably the best LSP client for emacs out there but it's insanely opinionated. My configuration looks like this, in which I pretty much completely override lsp-bridge's loading behavior: https://github.com/lambdadog/.emacs.d/blob/6a9e23eb9e209b0d82cd5b60a9e9153fad8385fb/init.el#L330-L391
CorysInTheHouse69 · 2022-07-27 20:42
I use eglot. Worked immediately out of the box
[deleted] · 2022-07-27 20:44
[removed]
hungry_m8 · 2022-07-27 21:43
i've been meaning to try lsp-bridge. is it fast? does it get in your way like lsp-mode?
i don't like that it uses an external python process, but would make the switch if it is fast with low memory footprint
by_wicker · 2022-07-27 21:56
> pyright
>
> really sluggish, and suggestions sub-par
Sub-par how? I definitely find it sluggish - the JS/Typescript really puts it to shame when I see it correct itself in a fraction of a second, meanwhile Python often takes multiple seconds to process even though I have 8 cores. But it's given me more and more useful analysis than those I used before - ms, palantir. Is there a better option?
pajuch · 2022-07-27 22:15
Yeah I've spent a lot of time trying to figure out how to set delays, not the strongest lisper. Really like it's design, speed, and suggestions, but it seems a little too locked down. The file completion is worse than corfu though sadly. Despite it being fast I can get a smoother experience with my understanding of corfu, cape and lsp-mode
J-ky · 2022-07-27 23:33
I put together a blog post about comparison of lsp clients in Emacs a while ago.
[https://blog.drshapeless.com/p/emacs-lsp-clients-comparison.html](https://blog.drshapeless.com/p/emacs-lsp-clients-comparison.html)
I strongly suggest everyone to use eglot.
lsp-bridge is interesting but not mature enough for everyday use. And it does not work well with other packages because of its async nature.
PhantomSeahorse · 2022-07-28 00:33
Honestly I think the completions of Pyright is limited by Python being such a dynamic language
jmhimara · 2022-07-28 00:57
> Worked immediately out of the box
Really? It refuses to work for me, not sure why....
CorysInTheHouse69 · 2022-07-28 01:02
This seems stupid, but did you turn it on?
kj2me · 2022-07-28 01:54
I use this: [https://git.kj2.me/kj/confi-emacs-actual/src/branch/master/configs/base-lsp.el](https://git.kj2.me/kj/confi-emacs-actual/src/branch/master/configs/base-lsp.el)
I never tried with eglot (it's the next on my list), I take a lot of time to make LSP works fine (I tested and disable a lot of things).
jmhimara · 2022-07-28 02:28
It's been a while, but I'm pretty sure. I remember getting some error that I couldn't really figure out.
your_sweetpea · 2022-07-28 03:38
lsp-bridge is blazingly fast and basically its #1 design principle is to not get in your way -- there's a reason I use it over both eglot and lsp-mode, even with the workarounds I have to use.
I'm generally of the opinion that the external python executable is fairly irreplaceable. The author has made a good case for it in the past and I can definitely see how elisp would be a poor candidate for handling the massive amount of data that language servers can send to the client.
That said my main usecase for lsp-bridge is that using a language server has become near necessary for modern development IMO as development flows more and more focus toward it, and I simply wanted something that works well and would not slow down emacs, and neither eglot or lsp-mode fit that usecase for me. I've definitely put much thought to forking it though.
your_sweetpea · 2022-07-28 03:41
You mention your issues with installing lsp-bridge via straight.el, but I'm quite certain that you should be able to just tweak the recipe that straight uses to include the acm folder. I had to do much the same when installing it via borg.
**EDIT:** See [Installing with a custom recipe](https://github.com/radian-software/straight.el#installing-with-a-custom-recipe) and [the recipe format](https://github.com/radian-software/straight.el#the-recipe-format) from the straight.el README, specifically the `:files` keyword.
hungry_m8 · 2022-07-28 07:10
thanks. I'd be sure to check it out sooner rather than later
paretoOptimalDev · 2022-07-28 12:48
I use eglot. Sometimes in a docket container with tramp and docker.el where it works transparently.
LongjumpingAd7260 · 2022-07-28 13:43
I find pyright quite fast. If it is taking seconds to process, probably there are other completions in the completion pipeline. Need to deactivate them all.
ank_itsharma · 2022-07-28 15:49
What’s your config for `eglot?`
by_wicker · 2022-07-28 16:07
I'm talking about checkers rather than completions. I find it tolerably quick at offering completions, but it takes significant time to check files, especially larger ones or those with an extensive import footprint. Meanwhile working with JS it's less than a second before my edits are checked.
paretoOptimalDev · 2022-07-28 16:09
No eglot config for docker/tramp working transparently, just:
- install eglot
- install https://github.com/emacs-pe/docker-tramp.el
- configure tramp to use remote's PATH so lsp server located
- C-x C-f /docker:container-name-or-hash:/project/src/Main.hs RET
paretoOptimalDev · 2022-07-28 19:22
I tried last year and it didn't work for me. Tried 3-4 months ago and things work seamlessly out of the box.
jmhimara · 2022-07-28 20:11
What languages do you use eglot for?
I've tried it several times, last time 6 months ago with F#. I've also tried it with Fortran. I suspect if I tried it with something more popular like python, it would work.
a-concerned-mother · 2022-07-28 21:52
I used \`eglot\` for a while and I really liked the philosophy, but it's support for wasn't on par with \`lsp-mode\`. As much as I hate to admit it \`dap-mode\` is too good for me to give up. It completely upgrades my development experience since it works so well and with basically every language.
Now I use \*\*lsp-mode\*\* biggest reason being the ability to use \*\*dap-mode\*\* Here are the languages I've used with in order of time
\- C++
\- Java
\- Python
\- Haskell
\- Rust
Used the first three with dap mode and required little to no configuration to make it all work. I turn off most of the UI features and the extra config since I prefer lsp features to feel similar to any other emacs feature.
a-concerned-mother · 2022-07-28 22:00
(use-package lsp-mode
:bind (:map lsp-mode-map
("M-<return>" . lsp-execute-code-action))
:hook ((c-mode . lsp-deferred)
(c++-mode . lsp-deferred)
(typescript-mode . lsp-deferred)
(javascript-mode . lsp-deferred)
(js-mode . lsp-deferred)
(rust-mode . lsp-deferred))
:commands (lsp lsp-deferred)
:init
(setq lsp-enable-snippet nil)
(setq lsp-enable-on-type-formatting nil)
(setq lsp-enable-indentation nil)
(with-eval-after-load 'js
(define-key js-mode-map (kbd "M-.") nil))
(setq lsp-diagnostics-provider :flymake)
(setq lsp-keymap-prefix "C-x L")
(add-hook 'lsp-completion-mode-hook
(lambda ()
(setf (alist-get 'lsp-capf completion-category-defaults) '((styles . (orderless flex)))))))
:config
(use-package lsp-haskell :ensure t :hook (haskell-mode . lsp-deferred))
(use-package lsp-java :ensure t :hook (java-mode . lsp-deferred)
:config
(require 'lsp-java-boot)
;; to enable the lenses
(add-hook 'lsp-mode-hook #'lsp-lens-mode)
(add-hook 'java-mode-hook #'lsp-java-boot-lens-mode))
(use-package lsp-pyright :ensure t
:init
(setq python-shell-enable-font-lock nil)
:hook (python-mode . (lambda ()
(require 'lsp-pyright)
(lsp-deferred))))
(use-package lsp-ui :ensure t
:init
(setq lsp-ui-sideline-show-code-actions t)
(setq lsp-ui-sideline-show-diagnostics t))
Sad_Entry9267 · 2022-07-29 01:24
Hi, I'm Andy Stewart, the author of lsp-bridge.
If eglot is works but lsp-bridge not, suggestion you send issue to lsp-bridge github.
Thanks.
ispinfx · 2022-07-29 01:33
Try `lsp-jedi`. Much better than pyright.
Horrih · 2022-07-29 06:24
Thanks, will try !
Ghosty141 · 2022-07-29 12:22
Flymake didnt really work that well for me and getting eglot to work with the much better flycheck requires its own magic so Ill just stick with lsp-mode