Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need a way to temporarily halt autocompletion #1731

Closed
krafczyk opened this issue Oct 13, 2015 · 33 comments
Closed

Need a way to temporarily halt autocompletion #1731

krafczyk opened this issue Oct 13, 2015 · 33 comments
Labels
PR Welcome A good quality PR for this feature would be considered.

Comments

@krafczyk
Copy link

I've been finding lately, that when I have a command to format a bunch of lines of code, and that code involves a class of some sort, YouCompleteMe will attempt to recompile and present a list of suggestions after getting to the end of a pointer or what-have-you.

Unfortuantely, this greatly slows down vim.

We need a way to temporarily disable the autocompletion features while a large command block executes.

(for instance I'm often doing 200@z or something like it, and it takes a while with all the recompiles and suggestion boxes popping up.)

I looked, but didn't see anything which would help me in the documents.

@micbou
Copy link
Collaborator

micbou commented Oct 13, 2015

You just need to type

:let g:ycm_auto_trigger = 0

before the command and

:let g:ycm_auto_trigger = 1

after.

@krafczyk
Copy link
Author

No, that just disables the completion suggestions.

The file is still compiled after every insert command as part of my command block, which seems to account for the majority of the time the command is executing.

@mispencer
Copy link
Contributor

Try using the noautocmd command

@vheon
Copy link
Contributor

vheon commented Oct 13, 2015

you should use call youcompleteme#DisableCursorMovedAutocommand() and call youcompleteme#EnableCursorMovedAutocommand()

@krafczyk
Copy link
Author

trying noautocmd doesn't work. I'm still getting updated error messages (compiler messages in the gutter) when my code passes through intermediate states.

When calling call youcompleteme#DisableCursorMovedAutocommand() I get:
E117: Unknown function: youcompleteme#DisableCursorMovedAutocommand

@krafczyk
Copy link
Author

On second glance, it seems the vim help claims that noautocmd is to be used with : style commands. When I do :noautocmd @a I get the following:

E492: Not an editor command: bye0v$hdi^Iptree->Branch("

Which of course is the content of my register.

@micbou
Copy link
Collaborator

micbou commented Oct 13, 2015

This is kind of a hack but the command

:let b:ycm_largefile

should do the job. Use

:unlet b:ycm_largefile`

to revert it.
I am confident this will work this time (or not?) because I tested it on an example.

When calling call youcompleteme#DisableCursorMovedAutocommand() I get:
E117: Unknown function: youcompleteme#DisableCursorMovedAutocommand

A s at the end of the command is missing. You should be able to autocomplete those kind of commands.

@vheon
Copy link
Contributor

vheon commented Oct 13, 2015

A s at the end of the command is missing. You should be able to autocomplete those kind of commands.

Yeah, sorry. For me using those functions is the way to go. We put those there for compatibility with other plugins which would suffer for try to complete on every key stroke, so I think is appropriate.

@krafczyk
Copy link
Author

Okay, we're closer, but not there yet.

with call youcompleteme#DisableCursorMovedAutocommands(),

It's not presenting the popup suggestions, however, it's still compiling and updating the warnings and errors whenever I go between insert and normal mode as part of the command in my register.

It's slightly faster though I think.

When I try :let b:ycm_largefile,
I get the error: E121: Undefined variable: b:ycm_largefile

Suspecting that it should be g:ycm_largefile, I still get: E121: Undefined variable: g:ycm_largefile

@micbou
Copy link
Collaborator

micbou commented Oct 14, 2015

My mistake. You need to set a value to the variable:

:let b:ycm_largefile = 1

@krafczyk
Copy link
Author

Yes! I believe that's done it!

How do I go back? I tried let b:ycm_largefile = 0 but, it doesn't seem to be providing suggestions anymore.

@micbou
Copy link
Collaborator

micbou commented Oct 14, 2015

You need to undefine the variable, that is:

:unlet b:ycm_largefile

@krafczyk
Copy link
Author

Excellent. This does exactly what I want.

Thanks very much for your help everyone!

It would be good if this was mentioned somewhere in the Readme.

@vheon
Copy link
Contributor

vheon commented Oct 14, 2015

It would be good if this was mentioned somewhere in the Readme.

What you're doing is just a hack using is an internal detail and not part of a public API, so mention it in the README is not a good idea, since we could change how we manage large files and that will not longer work as you expect. What seems strange to me is that even after call youcompleteme#DisableCursorMovedAutocommands() you still have problems :S

@krafczyk
Copy link
Author

Then perhaps I should reopen this issue and a more permanent solution
should be developed.

On Wed, Oct 14, 2015 at 6:47 PM, Andrea Cedraro notifications@github.com
wrote:

It would be good if this was mentioned somewhere in the Readme.

What you're doing is just a hack using is an internal detail and not part
of a public API, so mention it in the README is not a good idea, since we
could change how we manage large files and that will not longer work as you
expect.


Reply to this email directly or view it on GitHub
#1731 (comment)
.

@krafczyk krafczyk reopened this Oct 14, 2015
@micbou
Copy link
Collaborator

micbou commented Oct 14, 2015

What seems strange to me is that even after call youcompleteme#DisableCursorMovedAutocommands() you still have problems :S

This is because youcompleteme#DisableCursorMovedAutocommands() disables the youcompletemecursormove autocommands group but not the youcompleteme one. The function that takes time is s:OnInsertLeave and is part of the youcompleteme group (InsertLeave autocommand).

@vheon
Copy link
Contributor

vheon commented Oct 14, 2015

If we want to support halting YCM, I think that all we need to do is return 0 form s:AllowedToCompleteInCurrentFile, right?

so all we need is:

let s:halt_ycm = 0
function! youcompleteme#Halt()
  call youcompleteme#DisableCursorMovedAutocommands()
  let s:halt_ycm = 1
endfunction

function! youcompleteme#Resume()
  call youcompleteme#EnableCursorMovedAutocommands()
  let s:halt_ycm = 0
endfunction

and add the check to s:AllowedToCompleteInCurrentFile

if s:halt_ycm
  return 0
endif

The question here is if this is a valuable feature to implement and to support indefinitely.

@mispencer
Copy link
Contributor

In all the use cases which I have personally wanted YCM to not run (for example, running something like :argdo %s/red/blue), I have also wanted all my other plugins to not run either. For my use case at least, the eventignore vim option or the noautocmd vim command is superior to anything YCM could possibly implement.

@vheon
Copy link
Contributor

vheon commented Oct 14, 2015

@mispencer thanks for sharing your experience. I didn't thought of using eventignore: so basically you let save_ei = &eventignore set eventignore=all do your stuff let &eventignore = save_ei, right?

@mispencer
Copy link
Contributor

Yes, through I normally use the :noautocmd shortcut, which does that for a single command. I use :noautocmd a lot for command like :argdo, :windo, etc, since suppressing autocmds is a significant speedup. And YCM is not the only plugin in my setup which is a offender here.

@vheon
Copy link
Contributor

vheon commented Oct 14, 2015

My opinion on this is that we should keep things like they are and use :noautocmd or eventignore.

@puremourning
Copy link
Member

Just weighing in on a slight tangent. I have long considered a :YcmDisable command which shuts off YCM for the current buffer. I have this need because some files (like 10,000 line test scripts) have disappointing performance (for good reason). I don't want to disable for all test scripts, just some. Eclim offers :EclimDisable which I also use. I know this is a different use case, but interested in your thoughts.

@vheon
Copy link
Contributor

vheon commented Oct 14, 2015

@puremourning then how would you remember in which buffer you have YCM disabled? I see it like a flag in the statusline, but then I see that I'm overengeering this too much :P

@puremourning
Copy link
Member

I'd know because when I type I'd be disappointed that YCM wasn't working

@krafczyk
Copy link
Author

@puremourning : Exactly, you don't really need to put it in the statusline

@vheon
Copy link
Contributor

vheon commented Oct 14, 2015

@puremourning IMHO if we do it like that we would have different scenarios:

  • a guy would say "oh, YCM isn't working because I disabled on this buffer before" and then it would do :YCMResume
  • another guy would say "why YCM isn't working? oh, right I disabled it before... is not a great experience, let's file a bug for adding a way to know in which buffer YCM is disabled"
  • an another gut would just say "YCM isn't working. Let's file a bug"

that is because disabling YCM in a singular buffer without a way to mark it IMHO is not a great experience.

@puremourning
Copy link
Member

i mean we could have YcmDebugInfo print a big old

YouCompleteMe is disabled. Type YcmEnable to enable.

Shrug. I think if I manually went to the trouble of disabling something I'd hope that I'd remember that I did so. But yeah, I'm not the sort to just raise a bug if I can't get sonething to work :)

@sehe
Copy link

sehe commented Apr 26, 2016

I'm having this issue with very large diffs opened by vim-fugitive.

Browsing a commit, pressing "Enter" on a particular file will open the diff side-by-side. That is: you get two _new_ buffers with potentially large contents. What's more I don't think these buffers are backed by physical files, making the builting YCM protection for large files ineffective. This hangs up my vim for long periods of time (killed after 10 minutes) - seemingly even if the buffer contents is not a supported language by YCM.

All the above suggestions that center on "disabling YCM for the current buffer" work, because they are new buffers.

I've tried combining ideas above like :noautocmd normal <CR> instead of pressing Enter directly, but that just makes Fugitive unfunctional, leading to errors like

"fugitive:///home/sehe/WORK/.git//1604bd0d97fbd25f2b3c3cc52939272ea9a9b9b5/bla.py" [New DIRECTORY]
 E492: Not an editor command: Gdiff! 1604bd0d97fbd25f2b3c3cc52939272ea9a9b9b5^:bla.py

I suppose this is because Fugitive depends on autocommands to magically load the the diff if it detects the special filename.

I have no solution for this, other than removing YCM from my vim runtime environment and restarting Vim. I'd be very much in favour for a GLOBAL :YcmDisable or :YcmShutdown (the :YcmRestartServer already exists).

@vheon
Copy link
Contributor

vheon commented Apr 26, 2016

@sehe for your particular use case what you can do is to set manually the b:ycm_largefile to 1. So something like:

autocmd BufReadPre fugitive:///* let b:ycm_largefile = 1

I know is a hack but until we figure out something valid is all I can provide...

@sehe
Copy link

sehe commented Apr 26, 2016

@vheon That's clever. Using the autocommands in our favour.

Sadly, it doesn't work, I just tested it. I can interrupt the long running operation (after several minutes), but then YCM is stuck in an error state spewing error messages all the time, so I have to kill -9 vim anyways.

(Running without YCM has slowness for this large diff, but interrupting makes the fugitive buffer responsive and functional, showing that YCM /can/ cope)

@svandex
Copy link

svandex commented Oct 21, 2017

@Valloric make :YcmSuspend and :YcmResumecommand?

@kgfly
Copy link

kgfly commented May 27, 2018

:YcmSuspend and :YcmResumecommand should be useful

For some projects, I just want to turn off YCM. While in other prjs, keep it on.

I would like to turn off/on in .vimrc in runtime.

@puremourning puremourning added the PR Welcome A good quality PR for this feature would be considered. label Jan 4, 2020
@puremourning
Copy link
Member

I can't see us working on this any time soon, unless someone from the community contributes a PR and tests.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
PR Welcome A good quality PR for this feature would be considered.
Projects
None yet
Development

No branches or pull requests

8 participants