Option to set min length for suggestions

Only works with the identifier completer. Fixes #387.
This commit is contained in:
Strahinja Val Markovic 2013-06-29 15:43:10 -07:00
parent 6df01471d8
commit 5496984931
3 changed files with 31 additions and 2 deletions

View File

@ -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

View File

@ -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,

View File

@ -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 ]