hrsh7th / nvim-cmp

A completion plugin for neovim coded in Lua.
MIT License
7.53k stars 377 forks source link

cmp will just "stop working" people who havent looked thouroughly online may force themselves to restart nvim thinking cmp is broken. #1692

Closed beastr45 closed 6 months ago

beastr45 commented 10 months ago

FAQ

Announcement

Minimal reproducible full config

lazyvim

Description

this is a really hard issue to find online ecause it is default cmp behaviour as intended and not all people type with horrible accuracy. also due to cmp being less mainstream than big tech the documentation is more limited.

now I dont think that this would be a bugfix because it isnt erratical behaviour but rather nonsensical behaviour. when recoding macros cmp becomes unresponsive and wont work completions wise. now it would already be nice to be able to use completions while recoding macros to speed up productivity but the real issue is that the only indicatiion that a macro is beng recorded is just some text on the lower right of neovim. now sometimes it can be common to accidentally press q while traversing neovim and this will cause cmp to be unresponsive. This would cause frustration because the user cant make cmp work againt without finishing the macro and they might not know that. the most logical step for the user would be to restart neovim which will fix it although not the root cause of the issue. although initially I assumed it was the fault of lazy loading you can not fix it in the plugin manager because the macro state will persist per session. if the user presses q by accident often he will constantly have to restart neovim in order to get completions or check the lower right which will make him mad. the simple solution to this poor design choice is to add support for cmp nvim while recording macros.

Steps to reproduce

start recording a macro cmp stops working

Expected behavior

start recording a macro cmp keeps working and the user is oblivious

Actual behavior

cmp will seemingly stop working for no reason occasionally

Additional context

No response

Shougo commented 10 months ago

Reproduced.

But recording @a message is displayed your command line. Have you disabled command line messages?

Shougo commented 10 months ago

It seems feature.

https://github.com/hrsh7th/nvim-cmp/blob/5dce1b778b85c717f6614e3f4da45e9f19f54435/lua/cmp/config/default.lua#L10-L16

https://github.com/hrsh7th/nvim-cmp/issues/564 https://github.com/hrsh7th/nvim-cmp/issues/800 https://github.com/hrsh7th/nvim-cmp/issues/1128

Shougo commented 10 months ago

The feature seems not documented though.

And user can overwrite the function.

beastr45 commented 10 months ago

yes i saod that you can see the prompt but it is not front and center. if it is a feature theres no reason it seems too me to withold the functionality for the reasons i mentioned. if there is no documentation nobody will change it on their own.

beastr45 commented 10 months ago

It seems feature.

https://github.com/hrsh7th/nvim-cmp/blob/5dce1b778b85c717f6614e3f4da45e9f19f54435/lua/cmp/config/default.lua#L10-L16

564 #800 #1128

said in my bug fix report that this is less of a bug fix and more of a request to fix nonsensical/unexpected behaviour.

gegoune commented 10 months ago

cmp will seemingly stop working for no reason occasionally

Not true:

Reason is that it was likely to yield different results on replaying macro.

Hope my memory serves me well here.

Shougo commented 10 months ago

https://github.com/hrsh7th/nvim-cmp/issues/800#issuecomment-1092777544

The fix is more than 1 year ago. It is not broken recently. I think you have not update plugins or you don't know the change until you enable macro.

SirWrexes commented 10 months ago

For me CMP does crash at seemingly random occasions for no apparent reason. No macro recording or anything like that. I'm just typing code, and at some point I have no completion anymore. I have no idea what causes it.

I feels like it happens more often after putting NeoVim in the background with <C-z> and then coming back to it after a while with the shell command fg... But even when I try never doing that it still crashes randomly. It's VERY frustrating. Also there is no error that shows up, I don't see anything of value (or anything at all for that matter) when I try :messages.

I'm at a complete loss here... Anyone else come to this issue with the same bug ?

Shougo commented 10 months ago

For me CMP does crash at seemingly random occasions for no apparent reason. No macro recording or anything like that. I'm just typing code, and at some point I have no completion anymore. I have no idea what causes it.

Hm.. But the reproduce instruction is needed to fix it.

beastr45 commented 10 months ago

For me CMP does crash at seemingly random occasions for no apparent reason. No macro recording or anything like that. I'm just typing code, and at some point I have no completion anymore. I have no idea what causes it.

Hm.. But the reproduce instruction is needed to fix it.

user just explained he cant find out how to reproduce it did you read.

seems like cmp is shutting itself down unexpectedly under certain actions. although it may be a feature its not predictable to the user or verbose which is problomatic

SirWrexes commented 10 months ago

Yep. It does feel like it shuts down at random. Is there any command to manually turn it on or restart it ? It would be a good starting point to figure out what's going on. In the meantime, I'll try reloading it with Lazy.nvim when that happens and report here if it did anything. Also I wonder if there is a way to get verbose logs from CMP, like a log file and/or a config option to make it log everything. :thinking:

SirWrexes commented 9 months ago

Hey there I've noticed there is one particular situation that often causes nvim-cmp to break. Apparently, on a JS/TS project, when I <C-z> to send NeoVim to the background, install a new dependency, and then come back to my editor with the fg shell command, nvim-cmp will quite often be dead with no way to get it back other to restart NeoVim completely.

Edit: Additional info that might help: Usng PNPM in a mono-repo with a bunch of micro-services, some depending on others, some not. Dependencies are hoisted to the root (because of Expo and the Metro bundler nor supporting links). Aside from the random crashes, everything really works as expected.

miversen33 commented 8 months ago

I am seeing this issue as well. I wish I could give literally any useful information but there I have not seen anything predictable to cause the behavior and there is no error, I just suddenly don't have completions anymore. Is there anything we can do to possible get some kind of logging to provide useful info? I don't have the time to start digging into nvim-cmp right now as I am working on several other plugins (the newest nightly seems to have broken all kinds of shit).

SirWrexes commented 8 months ago

Short update on my case: Changing stuff in the project/services' dependencies (same project as mentioned before here) seems to break cmp even when done from another terminal, without sending NeoVim to the background.


Is there anything we can do to possible get some kind of logging to provide useful info? I don't have the time to start digging into nvim-cmp right now [...] — @miversen33

I second this question. I think one of my biggest grudges with this bug is not the bug itself, but the fact that I couldn't find any place where I'd have a stack trace or crash report to read. I wish there was an option to enable logging everything to a file, or at least errors.

daliusd commented 7 months ago

It is really well hidden behaviour/feature :-) Even after reading the whole thread, I have not figure out what's wrong, then I had to read through issues.

So, my summary + video: Is is hard to do it properly and @hrsh7th tried to do it at least once. In the end they did some improvement but it is not obvious. When you are using nvim-cmp normally you get autocomplete options live, but when you are in macro recording option (e.g. you have accidentally clicked q) then autocomplete options are not live anymore. You can get them but you have to click Ctrl+N for popup to show up and use up/down to select option you want to. I am attaching video to demonstrate this.

https://github.com/hrsh7th/nvim-cmp/assets/1944737/bf52569a-151e-40a1-9dc7-6705092de4c8

Maybe the only quick lesson from this is to disable or move macro recording to something less accidentally clickable, e.g.:

nnoremap Q q
nnoremap q <Nop>
SirWrexes commented 6 months ago

but when you are in macro recording option (e.g. you have accidentally clicked q) then autocomplete options are not live anymore — @daliusd

I have mentioned in this comment that I made sure I wasn't recording a macro and it still happens. Sadly, if it was that simple, this particular issue would be closed. :/

daliusd commented 6 months ago

but when you are in macro recording option (e.g. you have accidentally clicked q) then autocomplete options are not live anymore — @daliusd

I have mentioned in this comment that I made sure I wasn't recording a macro and it still happens. Sadly, if it was that simple, this particular issue would be closed. :/

Yes, I was sad/frustrated as well until I have found that I end up randomly in recording mode somehow. It might be that your problem is different. I have tested if sending vim to background affects cmp for me, but everything seems to work. You can check if ctrl+n works for you when cmp seems to be down, click q to test if that solves the problem (while you have already said that it is not macro recording issue). As well you can check CmpStatus and checkhealth output (after starting neovim and/or when cmp is not working for you).

hrsh7th commented 6 months ago

I have the same experience with TS/JS file types. In my case it was caused by the language server crashing from time to time.

I don't think it's a wrong decision that cmp won't complete any items when macros are enabled.

bew commented 6 months ago

I don't think it's a wrong decision that cmp won't complete any items when macros are enabled.

I'd argue this is a limitation of Vim, that cmp can't do actions like completion selection without having them be in the macro recording... The ideal behavior here (if nvim fixes this somehow) should be that cmp allows to select completions and put in the macro that somecompletion was typed (instead of only saving the keys used to select the completion)

miversen33 commented 6 months ago

I am absolutely sure I was not recording or executing a macro any of the times I have seen this happen. I don't use macros pretty much ever.

And even in the case that completions don't show during macros (which does make sense), why would it be acceptable that using macros completely breaks completions?

When this "crashes", it isn't simply a "I can't use them right now" thing. It's a, "I have to restart neovim because completions NEVER work again" thing.

daliusd commented 6 months ago

When this "crashes", it isn't simply a "I can't use them right now" thing. It's a, "I have to restart neovim because completions NEVER work again" thing.

So it might be LSP server crash. Try :LspRestart.

miversen33 commented 6 months ago

When this "crashes", it isn't simply a "I can't use them right now" thing. It's a, "I have to restart neovim because completions NEVER work again" thing.

So it might be LSP server crash. Try :LspRestart.

The next time that happens I'll try it. However LSP is not the only thing feeding cmp, I would imagine the rest of my sources should still work

SirWrexes commented 6 months ago

I've had a binding for :LspRestart for forever so, naturally, when the crashing happened I've tried it but it didn't bring cmp back to life.

piush-terminalwitchcraft commented 4 months ago

Any updates regarding this issue?

cam-jw commented 2 months ago

Was also experiencing something similar to this. I had cmp disable in markdown files. When I was using python and markdown in different buffers, switching to a markdown buffer then back to a python buffer caused cmp to remain disabled in python.

Zeta611 commented 2 months ago

I don't know where to start looking to debug this---cmp just breaks after ~5min of usage, and LspRestart won't help.

SirWrexes commented 2 months ago

Since this issue seems to be going nowhere, I've been trying out Coq and I have to say I've been very satisfied with it. It's also much easier to set up. I kinda hate that I'm doing this here because it feels disrespectful, but it is with intention to help fellow developers having troubles with such an important tool as code completion.

Zeta611 commented 2 months ago

@SirWrexes I do use Coq (the theorem prover), so Coq.nvim seems promising as well. Does it have unicode/TeX completion, e.g., \infty -> ∞ completion sources?

SirWrexes commented 1 month ago

@SirWrexes [...] \infty -> ∞ completion sources?

I'm not sure. I tend to use my terminal for that. Kitty has a unicode search & copy/input overlay mode.

You could simply write autosnippets for that purpose, it's a little bit of setup but that would make it portable; as long as the completion engine that you use supports your snippet engine, and most options available out there are compatible. LuaSnip works great with Coq.nvim.

Autosnippets are simple: During the writing of your snippet, there is an option (I think it's auto, I don't remember and can't check right now). And done, when you type the trigger word it'll automatically expand without having to select it in your completions.

alecgerona commented 1 month ago

Chiming in to say that I am also facing these issues without using any macros. LSP restart doesn't work.

erlangparasu commented 1 month ago

facing same issue