diff --git a/README.md b/README.md index e3fe0a7e..65767a6f 100644 --- a/README.md +++ b/README.md @@ -598,6 +598,21 @@ Default: `2` let g:ycm_min_num_of_chars_for_completion = 2 +### The `g:ycm_min_num_identifier_candidate_chars` option + +This option controls the minimum number of characters that a completion +candidate coming from the identifier completer must have to be shown in the +popup menu. + +A special value of `0` means there is no limit. + +NOTE: This option only applies to the identifier completer; it has no effect on +the various semantic completers. + +Default: `0` + + let g:ycm_min_num_identifier_candidate_chars = 0 + ### The `g:ycm_filetype_whitelist` option This option controls for which Vim filetypes (see `:h filetype`) should YCM be diff --git a/plugin/youcompleteme.vim b/plugin/youcompleteme.vim index 213e7a85..e96a0875 100644 --- a/plugin/youcompleteme.vim +++ b/plugin/youcompleteme.vim @@ -63,6 +63,9 @@ let g:loaded_youcompleteme = 1 let g:ycm_min_num_of_chars_for_completion = \ get( g:, 'ycm_min_num_of_chars_for_completion', 2 ) +let g:ycm_min_num_identifier_candidate_chars = + \ get( g:, 'ycm_min_num_identifier_candidate_chars', 0 ) + let g:ycm_filetype_whitelist = \ get( g:, 'ycm_filetype_whitelist', { \ '*' : 1, diff --git a/python/ycm/completers/all/identifier_completer.py b/python/ycm/completers/all/identifier_completer.py index 1bb29cee..932b4406 100644 --- a/python/ycm/completers/all/identifier_completer.py +++ b/python/ycm/completers/all/identifier_completer.py @@ -27,8 +27,10 @@ from ycm import vimsupport from ycm import utils MAX_IDENTIFIER_COMPLETIONS_RETURNED = 10 -MIN_NUM_CHARS = int( vimsupport.GetVariableValue( +MIN_NUM_COMPLETION_START_CHARS = int( vimsupport.GetVariableValue( "g:ycm_min_num_of_chars_for_completion" ) ) +MIN_NUM_CANDIDATE_SIZE_CHARS = int( vimsupport.GetVariableValue( + "g:ycm_min_num_identifier_candidate_chars" ) ) SYNTAX_FILENAME = 'YCM_PLACEHOLDER_FOR_SYNTAX' @@ -172,6 +174,8 @@ class IdentifierCompleter( GeneralCompleter ): completions = self.completions_future.GetResults()[ : MAX_IDENTIFIER_COMPLETIONS_RETURNED ] + completions = _RemoveSmallCandidates( completions ) + # We will never have duplicates in completions so with 'dup':1 we tell Vim # to add this candidate even if it's a duplicate of an existing one (which # will never happen). This saves us some expensive string matching @@ -204,8 +208,15 @@ def PreviousIdentifier(): while start_column > 0 and utils.IsIdentifierChar( line[ start_column - 1 ] ): start_column -= 1 - if end_column - start_column < MIN_NUM_CHARS: + if end_column - start_column < MIN_NUM_COMPLETION_START_CHARS: return "" return line[ start_column : end_column ] + +def _RemoveSmallCandidates( candidates ): + if MIN_NUM_CANDIDATE_SIZE_CHARS == 0: + return candidates + + return [ x for x in candidates if len( x ) >= MIN_NUM_CANDIDATE_SIZE_CHARS ] +