reddit / emacs

Building an Intelligent Emacs with LSP

yep808 · 2022-02-11 01:56
spudlyo · 2022-02-11 02:55
This is well written and the blogs and screenshots look very really nice!
yep808 · 2022-02-11 03:15
Thank you!
Kaligule · 2022-02-11 06:08
LSP is truly a gamechanger. The hardest part for me is organisation: I can not just spawn an editor anymore. Suddenly I have to install multiple language-servers along emacs. Do you install those globally? Don't thy belong in some kind of virtual environment or so? should they live in docker perhaps? What if I use different versions of the same language? will the server notice?
hangingpawns · 2022-02-11 08:23
Since I work on HPC clusters, I often lack sudo privileges. Anaconda seems to fit most of my needs for installing various compilers. Llvm, clang, rust, ICC, gcc, fortran, etc. I can create a conda environment for each version and just activate the one accordingly.
saarin · 2022-02-11 08:31
Any sign that lsp mode will be integrated into emacs core?
chandaliergalaxy · 2022-02-11 08:49
My understanding was that eglot is much more amenable for integration into emacs core though I don't know if this was seriously considered.
Drishal · 2022-02-11 10:11
Well I think at that point Nix can do it even better
[deleted] · 2022-02-11 10:31
LSP is pretty cool. Thanks for briefly explaining everything. Just a side note, one can use [eglot](https://github.com/joaotavora/eglot) to get pretty much same functionality.
Wonnk13 · 2022-02-11 11:50
I've been using lsp-mode and for the most part it works just fine. Each lang server has their own little quirks, but whatever. What I haven't seen is a 2021/2022 apples to apples comparison with eglot. I'd love for the community to standardize on one approach, but that doesn't seem to be the Emacs way. Am I missing anything by not adopting Eglot? The only thing that mildly annoys me with lsp-mode.el is that code actions are kind of wonky / not clickable sometimes. I don't know if that's an artifact of my own configuration, or something intrinsic to the server itself.
redrick_schuhart · 2022-02-11 12:12
I went down the LSP rabbit hole when I was looking to configure some completion stuff I hadn't touched in a while - and I'm enjoying it. I couldn't get lsp-mode itself to work properly but eglot worked first time out of the box.
paretoOptimalDev · 2022-02-11 12:18
> The hardest part for me is organisation: I can not just spawn an editor anymore. Suddenly I have to install multiple language-servers along emacs. Treat it more as a full fledged platform or human computing environment. Then use Nix (or maybe docker if you really must) to lower the friction of guaranteeing that environment is always the same everywhere. > Do you install those globally? Don't thy belong in some kind of virtual environment or so? should they live in docker perhaps? Nix, direnv, and emacs-direnv makes per project virtual environments seamless and transparent. The learning curve and setup can be challenging though. > What if I use different versions of the same language? will the server notice? In my experience it will loudly fail at best or do weird things.
sammymammy2 · 2022-02-11 12:29
Why do people still use setq when setf exists? Also, Pyright is unfortunately very troubling. It's MIT licensed and the repo is Microsoft controlled, with MS building their own proprietary LS on top of Pyright for VSCode exclusively. This means that MS has reason to keep Pyright worse than their own offering.
Prize_Comb1053 · 2022-02-11 12:59
Yeah, I'm a NixOS user, and nix helps a lot with managing LSP servers on my system at the point that this is not a issue for me, but I agree a solution runing then in a docker or something would fit nice as well, we already have this conecpt: https://github.com/emacs-lsp/lsp-docker/
Drishal · 2022-02-11 13:00
tbh I am using Nix on top of Arch (cause I prefer FHS for the base system)
ericdallo · 2022-02-11 13:03
I'm not aware of this kind of issue on code actions, please open a issue where we can discuss it :)
yyoncho · 2022-02-11 13:12
You don't want that. Do you want lsp-mode releases to happen on yearly basis? (and much more, but that one should be enough)
by_wicker · 2022-02-11 14:06
Which is a less troubling choice then? I had a weird interaction once when someone was saying MS was evil so they used the Palantir one...
sebhoagie · 2022-02-11 14:15
Some packages are officially in Emacs but update via ELPA. Not sure about the details. That said, with the amount of contributors to lsp-mode, the whole copyright thing might be impossible to solve.
sebhoagie · 2022-02-11 14:20
I use both almost interchangeably (switch every few months). lsp-mode has way more features than eglot. If you want dap-mode (debugger) you need lsp. Ditto for lenses, code preview, breadcrumbs, and many other UI features. TBH I don't use any of them, which is why they are more or less equivalent for me, but lsp-mode offers a lot more functionality.
sebhoagie · 2022-02-11 14:28
If I had to do a short comparison of both, I would say: Eglot is leaner, smaller, and simpler. But it also offers way fewer features than lsp-mode. And for the three language servers I've used (python-lsp-server, omnisharp (C#) and Eclipse jdt (Java)) I didn't see a big difference in speed. lsp-mode has dap-mode (debugger support) and a lot of bells and whistles in lsp-ui that can make it really attractive to more....modern sensibilities than mine (I disable everything!). I really dislike the fact that the Eglot README still has the outdated comparison, I find it pointless and worthless even as a historical artifact. I use both packages, switching every few months, and I *like* eglot, but if I had to recommend a package for people to try first, it would be lsp-mode, no question.
nullmove · 2022-02-11 14:47
I mean in the base simple case, `setf` macro expands to `setq` all the same, it just packs a bunch of other hardcoded rules that makes it work in few other contexts. Generalisation is nice, but there is also an argument to avoid unnecessary abstraction if all you care about is the simplest use case.
WallyMetropolis · 2022-02-11 15:05
I would say that lsp-mode is the standard and eglot is a somewhat popular alternative with a waning community. I was an eglot user for some time while lsp-mode was still working out a few issues. I appreciated how much easier it was to get eglot configured, but it's no longer the case that eglot is an order of magnitude easier to use. I switched to lsp-mode perhaps two years ago after getting a bit envious of the ecosystem and haven't looked back.
WallyMetropolis · 2022-02-11 15:08
I've tried a few different Python language servers and Pyright has been the most stable for me and least painful for me. What server would you suggest?
gdaythisisben · 2022-02-11 15:09
Fantastic write up. Lack of LSP made me return to Vim initially, but now, let’s go back to the good old parens. 🥳
DerArzt01 · 2022-02-11 15:53
The one 'killer' feature that lsp-mode has over elgot for me is interop with dap-mode for debugging. While I don't use a debugger most days, when I need one I really need one. So having that available in emacs means that I don't have to open another editor/ide/tool which is great! (Still an emacs noob so I'm not sure if you can use dap with elgot, just piggy backing off what others mentioned).
yyoncho · 2022-02-11 16:39
That means we will end up with a package in emacs, that will have on the first line in its README - "Please don't use the built-in version and make sure that you have installed the version from ELPA/MELPA."
sebhoagie · 2022-02-11 16:45
Specially considering how fast you guys move in lsp-mode. The built-in version would be outdated veeeeery quickly.
sebhoagie · 2022-02-11 16:46
AFAIK you can't use dap-mode without lsp-mode :)
sammymammy2 · 2022-02-11 17:06
I also use Pyright :-), it just bothers me and I wanted to vent.
ajitid · 2022-02-11 17:48
^ TIL. Do you have publicly visible Anaconda config files? How do you create environments, do you use YAML file for it?
Icommentedtoday · 2022-02-11 18:00
Maybe handy to also mention you need Company or Corfu for the completion popup you're showing in your screenshots? Great article!
BeetleB · 2022-02-11 18:09
> Why do people still use setq when setf exists? The only benefit of setf is that you can evaluate an expression to get the variable name. 99% of the times you don't need that.
hangingpawns · 2022-02-11 18:36
conda create --prefix /home/hangingpawns/emacs_lsp conda activate /home/hangingpawns/emacs_lsp conda install clang clangd libclang bear export PATH=/home/hangingpawns/emacs_lsp/bin (or wherever the bin is) Do the same with ld_library_path You can also have just a master script that calls conda activate and sets your envvars accordingly.
[deleted] · 2022-02-11 18:59
Pretty nice post, i made the transition from neovim to emacs and configuring emacs has been hell lot more intuitive, thanks to lsp mode, org and magit but also the hundreds other useful packages.
Qkesslerr · 2022-02-11 19:14
Really good article! It really seems like a good introduction for getting emacs more IDE-like. Keep it up! As I side note: do you use “setq” inside :config instead of :custom for any reason? I haven’t tested whether :custom takes a hit on init time. Thanks!
yep808 · 2022-02-11 19:36
Thanks for reading my article. I use :config with explicit setq so I can evaluate an experimental variable change quickly with C-x C-e at the end of its parentheses.
yep808 · 2022-02-11 19:37
>Maybe handy to also mention you need Company or Corfu for the completion popup you're showing in your screenshots? Thanks for the heads-up, I'll add it in my next edit!
yep808 · 2022-02-11 19:41
Regarding pyright, I came across this thread in the (neo)vim community: [https://www.reddit.com/r/neovim/comments/ogy3hb/what\_python\_lsp\_are\_you\_using/](https://www.reddit.com/r/neovim/comments/ogy3hb/what_python_lsp_are_you_using/) You might find it interesting.
RichieHHam · 2022-02-11 20:12
I found dap-mode to be too limited in variable inspection. I must try it again.
RichieHHam · 2022-02-11 20:13
But cedet is...
hangingpawns · 2022-02-12 00:11
Doesn't Nixos require sudo to install? > Above command will perform a single-user installation of Nix, meaning that /nix is owned by the invoking user. You should run this under your usual user account, not as root. The script will invoke sudo to create /nix if it doesn’t already exist.
hangingpawns · 2022-02-12 00:11
Doesn't Nixos require sudo to install? > Above command will perform a single-user installation of Nix, meaning that /nix is owned by the invoking user. You should run this under your usual user account, not as root. The script will invoke sudo to create /nix if it doesn’t already exist.
FrozenOnPluto · 2022-02-12 04:02
Great post, thanks! I've been getting by on elpy for years, and its worked pretty well for local edits.. sort of works sometimes for Tramp remote edits. I gather it is currently lacking a maintainer and hasn't been updated in a few years? Not sure.. anyway, its been great. I have tried lsp-mode and eglot over the years on and off, but its been awhile and they're always a little rough to get going, so I've ignored them for awhile, despite knowing they've come a long ways. I dug out my old config and it mostly worked, but now saw your post here and it inspired me to comapre notes and clean things up; I fiddled a bit and got LSP working over tramp mode (well, LSP, not the DAP part), and its working a treat local and remote now .. better than elpy. Now if only dap-mode had an easy way to work over a TCP socket or the like, and we'd be really rocking it. Thanks!
yep808 · 2022-02-12 05:03
Glad you find my post helpful, thanks for reading!
Drishal · 2022-02-12 08:09
just the first time setup
hangingpawns · 2022-02-12 08:37
Yeah. On an HPC cluster, they're unlikely to have Nixos.
Drishal · 2022-02-12 10:08
maybe request the admins to allow you to run just one script with sudo or something
hvis · 2022-02-12 12:11
Does the core of the package move fast as well? I would imagine at some point the users should be able to install an older version and still have it work (for most languages, most of the time). At the very least, it could be published in NonGNU ELPA.
yyoncho · 2022-02-12 12:54
IDK but I can number several packages that I want to be out of emacs core from lsp-mode's perspective.
hangingpawns · 2022-02-12 16:39
They're not going to allow that. These are the systems at US national labs. What's wrong with just using conda?
hvis · 2022-02-12 21:33
No argument about that.
[deleted] · 2022-02-12 23:54
[deleted]
trararawe · 2022-02-13 00:47
Thanks a lot for this! I was long waiting for a comprehensive post on setting up LSP, there are so many pieces and I never had enough time to understand and set up each one of them.
yep808 · 2022-02-13 02:37
Thanks for reading!
Drishal · 2022-02-13 07:33
aah ok if its that protected then maybe you can change where /nix/store is supposed to go