reddit / emacs

Problems with lsp mode

ThePullinger · 2022-06-15 13:23
I recently set up lsp mode and company mode and it was working fine for a while until i started getting frequent freezes, the only way to end the freeze is to restart emacs. The freeze happens after entering a character and i think it might be a problem with auto complete but i can't find a solution on the internet that works, i've tried everything i could think of does any have any ideas or suggestions? ​ edit: The problem is likely to do with company mode, i tried turning off and i couldn't reproduce the error, any ideas?
MitchellMarquez42 · 2022-06-15 15:11
!remindme 5d
RemindMeBot · 2022-06-15 15:16
I will be messaging you in 5 days on [**2022-06-20 15:11:10 UTC**](http://www.wolframalpha.com/input/?i=2022-06-20%2015:11:10%20UTC%20To%20Local%20Time) to remind you of [**this link**](https://www.reddit.com/r/emacs/comments/vcufs9/problems_with_lsp_mode/icgp0gj/?context=3) [**2 OTHERS CLICKED THIS LINK**](https://www.reddit.com/message/compose/?to=RemindMeBot&subject=Reminder&message=%5Bhttps%3A%2F%2Fwww.reddit.com%2Fr%2Femacs%2Fcomments%2Fvcufs9%2Fproblems_with_lsp_mode%2Ficgp0gj%2F%5D%0A%0ARemindMe%21%202022-06-20%2015%3A11%3A10%20UTC) to send a PM to also be reminded and to reduce spam. ^(Parent commenter can ) [^(delete this message to hide from others.)](https://www.reddit.com/message/compose/?to=RemindMeBot&subject=Delete%20Comment&message=Delete%21%20vcufs9) ***** |[^(Info)](https://www.reddit.com/r/RemindMeBot/comments/e1bko7/remindmebot_info_v21/)|[^(Custom)](https://www.reddit.com/message/compose/?to=RemindMeBot&subject=Reminder&message=%5BLink%20or%20message%20inside%20square%20brackets%5D%0A%0ARemindMe%21%20Time%20period%20here)|[^(Your Reminders)](https://www.reddit.com/message/compose/?to=RemindMeBot&subject=List%20Of%20Reminders&message=MyReminders%21)|[^(Feedback)](https://www.reddit.com/message/compose/?to=Watchful1&subject=RemindMeBot%20Feedback)| |-|-|-|-|
csemacs · 2022-06-15 16:11
run `M-x profier-start` for `cpu+ram`, keep working on your buffer for a minute or two. run `M-x profier-stop` and `M-x profiler-report`. check the report to see what mode or function is consuming more resources. In my case `Flyspell-prog-mode` was the culprit. Disabling it smoothed things out.
ThePullinger · 2022-06-15 17:08
The problem is I can't do any work in the buffer at all, when i try to type something emacs will freeze and I can't figure out a way to recover it from this state without a restart so I don't know how to diagnose it. This only happens in lsp mode buffers and I think it's the auto complete because it happens after I type a single character when the auto complete would normally come up.
ckoneru · 2022-06-15 18:00
Can you share your config link?
ThePullinger · 2022-06-15 18:02
here's my config for lsp mode ``` (use-package lsp-mode :commands (lsp lsp-deferred) :init (setq lsp-keymap-prefix "C-c s") :config (setq read-process-output-max (* 1024 1024)) (setq gc-cons-threshold 100000000) (lsp-enable-which-key-integration t)) ``` and here's my config for company mode as well ``` (use-package company :after lsp-mode :hook (lsp-mode . company-mode) :bind (:map company-active-map ("<tab>" . company-complete-common) ("<backtab>" . company-complete-selection)) (:map lsp-mode-map ("<tab>" . company-indent-or-complete-common)) :custom (company-minimum-prefix-length 1) (company-idle-delay 0.0)) ```
WallyMetropolis · 2022-06-15 20:01
You might have added a huge number of files to your workspace, accidentally. When you open a new project in lsp-mode it will prompt you to ask to import the project. Depending on the structure of your directory system, doing so can add many, extraneous files to your workspace. This can cause extraordinarily slow performance, exactly like what you've described. Try this: Check you `lsp-session-file` which you can find with `C-h v lsp-session-file` and delete any directories that aren't actually project root directories. For me, I had added my home directory as a workspace root somehow.
flamingbear · 2022-06-15 23:04
`(setq gc-cons-threshold 100000000)` That's a pretty big gc value. It could be just stuck in garbage collection? It can't hurt to try a smaller value there.
mmaug · 2022-06-16 00:18
I've had a similar auto complete "hang" in the editor. It runs in idle time so if I'm typing a word I have no problem, but as soon as my creaky brain needs a cycle to think, the editor thinks it's idle and starts a 2 minute search for nothing I need. `C-g` will usually free the keyboard so that I can type the next 3 characters. Try setting `debug-on-quit` to `t` and go about your business. If you encounter a hang, type `C-g` and you should get a backtrace that might identify the culprit. Closing the buffer and reopening it will often be sufficient to fix it. But since I'll run the same session for weeks, I'll usually take it as a sign that the old CS solution to the all problems is called for: Save everything, close all of the windows, and then reopen them again.
FrozenOnPluto · 2022-06-16 03:41
You can specify a limit to the lsp scanner, for most lsp servers; I have mine limited to a certain number of projects distance from current file, something like that.
ThePullinger · 2022-06-16 07:58
the problem started before I added the value, I added it because on the lsp mode website it said it could help fix performance problems
ThePullinger · 2022-06-16 07:58
C-g doesn't fix the hang, i have to force quit emacs
ThePullinger · 2022-06-16 09:02
i tries that, couldn't find any files which weren't project roots
samsjj · 2022-06-16 13:38
Try increasing company minimum prefix length to 2 or 3 and idle delay to higher value
WallyMetropolis · 2022-06-16 13:54
Can you expand on that? What settings control that?
FrozenOnPluto · 2022-06-16 16:18
Hmm, looks like my current config related to this performance is just: (setq lsp-enable-file-watchers nil) ;; disable watching files all over the workspace - see https://emacs-lsp.github.io/lsp-mode/page/file-watchers/ (setq lsp-enable-suggest-server-download nil) ;; don't offer to download servers all the time My config in general is a little goofy and long so I'll spare you :)
WallyMetropolis · 2022-06-16 18:55
>My config in general is a little goofy and long So ... the usual!
FrozenOnPluto · 2022-06-16 19:00
mmmm, yeah, no doubt ;) For LSP its a little hairy in the sense of .. theres elpy, and lsp, and eglot, and I think another one for python and LSP in general; but for LSP, I took a swing several different times, and kept all that in my config, in various states of commented out or if/when'd out. In general for my config I switched to a system of ... at the top, work out which of my many environments its running in (text? GUI? work machine? email server? my home dev boxes? etc), and then enable various flags .. "gui-yes" and "dev-machine" and "email-machine" and such, as goals. Then a bit later it maps each of those goal config items into feature items (dev machine implies things like lsp, causing a pile of packages ot get sucked in and added to hooks; but my underpowered email server doesn't need that, just needs a simpler emacs that loads faster and not take 20 mins...) ... and then based on feature flags, it use-package inhales, does the configuration etc. So, its a big old mess, but it works well enough for me.. so yeah, like everyone. I'm afraid to look at Doom or other peoples configs, since it'd no doubt make me question my own setup, and have to rewrite it (yet again..) -- &#x200B; ... doing Emacs config is a hobby of its own, right? :)