From aeb2c5c227632bc5a8d8ffe9acf1623ad51f1f85 Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Mon, 2 Dec 2013 16:36:53 -0800 Subject: [PATCH] Adding the g:ycm_auto_trigger option Toggling this option off turns off the identifier completer and the semantic triggers. Fixes #597 --- README.md | 15 +++++++++ autoload/youcompleteme.vim | 5 ++- python/ycm/completers/completer.py | 6 ++-- python/ycm/server/default_settings.json | 1 + .../ycm/server/tests/get_completions_test.py | 32 ++++++++++++++++++- 5 files changed, 55 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2ed23cbb..749e9ac0 100644 --- a/README.md +++ b/README.md @@ -678,6 +678,21 @@ Default: `0` let g:ycm_min_num_identifier_candidate_chars = 0 +### The `g:ycm_auto_trigger` option + +When set to `0`, this option turns off YCM's identifier completer (the +as-you-type popup) _and_ the semantic triggers (the popup you'd get after typing +`.` or `->` in say C++). The Syntastic integration remains working and you can +still force semantic completion with the `` shortcut. + +If you want to just turn off the identifier completer but keep the semantic +triggers, you should set `g:ycm_min_num_of_chars_for_completion` to a high +number like `99`. + +Default: `1` + + let g:ycm_auto_trigger = 1 + ### The `g:ycm_filetype_whitelist` option This option controls for which Vim filetypes (see `:h filetype`) should YCM be diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index e3ef2945..007d6afc 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -366,7 +366,10 @@ function! s:OnCursorMovedInsertMode() if g:ycm_autoclose_preview_window_after_completion call s:ClosePreviewWindowIfNeeded() endif - call s:InvokeCompletion() + + if g:ycm_auto_trigger + call s:InvokeCompletion() + endif endfunction diff --git a/python/ycm/completers/completer.py b/python/ycm/completers/completer.py index 6dfa3339..5dd1c7ed 100644 --- a/python/ycm/completers/completer.py +++ b/python/ycm/completers/completer.py @@ -18,6 +18,7 @@ # along with YouCompleteMe. If not, see . import abc +from collections import defaultdict from ycm.utils import ToUtf8IfNeeded, ForceSemanticCompletion, RunningInsideVim if RunningInsideVim(): @@ -100,8 +101,9 @@ class Completer( object ): def __init__( self, user_options ): self.user_options = user_options self.min_num_chars = user_options[ 'min_num_of_chars_for_completion' ] - self.triggers_for_filetype = TriggersForFiletype( - user_options[ 'semantic_triggers' ] ) + self.triggers_for_filetype = ( + TriggersForFiletype( user_options[ 'semantic_triggers' ] ) + if user_options[ 'auto_trigger' ] else defaultdict( set ) ) self.completions_future = None self._completions_cache = None diff --git a/python/ycm/server/default_settings.json b/python/ycm/server/default_settings.json index 327cb399..b7c3950c 100644 --- a/python/ycm/server/default_settings.json +++ b/python/ycm/server/default_settings.json @@ -1,5 +1,6 @@ { "filepath_completion_use_working_dir": 0, + "auto_trigger": 1, "min_num_of_chars_for_completion": 2, "min_num_identifier_candidate_chars": 0, "semantic_triggers": {}, diff --git a/python/ycm/server/tests/get_completions_test.py b/python/ycm/server/tests/get_completions_test.py index 7751b3f7..4bfbee0f 100644 --- a/python/ycm/server/tests/get_completions_test.py +++ b/python/ycm/server/tests/get_completions_test.py @@ -26,7 +26,7 @@ from .test_utils import ( Setup, BuildRequest, PathToTestFile, from webtest import TestApp from nose.tools import eq_, with_setup from hamcrest import ( assert_that, has_item, has_items, has_entry, - contains_inanyorder ) + contains_inanyorder, empty ) from ..responses import BuildCompletionData, UnknownExtraConf from .. import handlers import bottle @@ -127,6 +127,36 @@ int main() CompletionEntryMatcher( 'x' ), CompletionEntryMatcher( 'y' ) ) ) +@with_setup( Setup ) +def GetCompletions_ClangCompleter_NoCompletionsWhenAutoTriggerOff_test(): + ChangeSpecificOptions( { 'auto_trigger': False } ) + app = TestApp( handlers.app ) + contents = """ +struct Foo { + int x; + int y; + char c; +}; + +int main() +{ + Foo foo; + foo. +} +""" + + # 0-based line and column! + completion_data = BuildRequest( filepath = '/foo.cpp', + filetype = 'cpp', + contents = contents, + line_num = 10, + column_num = 6, + start_column = 6, + compilation_flags = ['-x', 'c++'] ) + + results = app.post_json( '/completions', completion_data ).json + assert_that( results, empty() ) + @with_setup( Setup ) def GetCompletions_ClangCompleter_UnknownExtraConfException_test():