From 8ce07f508c27ca407e909a09b4137cf7e6a1b7b7 Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Wed, 9 Oct 2013 20:20:34 -0700 Subject: [PATCH] again filters the semantic completions Fixes #576. --- python/ycm/completers/completer.py | 15 ++++++++---- python/ycm/server/tests/basic_test.py | 34 ++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/python/ycm/completers/completer.py b/python/ycm/completers/completer.py index ed068b0d..4668076d 100644 --- a/python/ycm/completers/completer.py +++ b/python/ycm/completers/completer.py @@ -153,13 +153,18 @@ class Completer( object ): not self.ShouldUseNow( request_data ) ): return [] - if ( request_data[ 'query' ] and - self._completions_cache and + candidates = self._GetCandidatesFromSubclass( request_data ) + if request_data[ 'query' ]: + candidates = self.FilterAndSortCandidates( candidates, + request_data[ 'query' ] ) + return candidates + + + def _GetCandidatesFromSubclass( self, request_data ): + if ( self._completions_cache and self._completions_cache.CacheValid( request_data[ 'line_num' ], request_data[ 'start_column' ] ) ): - return self.FilterAndSortCandidates( - self._completions_cache.raw_completions, - request_data[ 'query' ] ) + return self._completions_cache.raw_completions else: self._completions_cache = CompletionsCache() self._completions_cache.raw_completions = self.ComputeCandidatesInner( diff --git a/python/ycm/server/tests/basic_test.py b/python/ycm/server/tests/basic_test.py index 0faa9cc3..9618bc7a 100644 --- a/python/ycm/server/tests/basic_test.py +++ b/python/ycm/server/tests/basic_test.py @@ -25,7 +25,7 @@ from .. import ycmd from ..responses import BuildCompletionData, UnknownExtraConf from nose.tools import ok_, eq_, with_setup from hamcrest import ( assert_that, has_items, has_entry, contains, - contains_string, has_entries ) + contains_string, has_entries, contains_inanyorder ) import bottle bottle.debug( True ) @@ -207,6 +207,38 @@ def GetCompletions_ClangCompleter_WorksWhenExtraConfExplicitlyAllowed_test(): CompletionEntryMatcher( 'y' ) ) ) +@with_setup( Setup ) +def GetCompletions_ClangCompleter_ForceSemantic_OnlyFileteredCompletions_test(): + app = TestApp( ycmd.app ) + contents = """ +int main() +{ + int foobar; + int floozar; + int gooboo; + int bleble; + + fooar +} +""" + + # 0-based line and column! + completion_data = BuildRequest( filepath = '/foo.cpp', + filetype = 'cpp', + force_semantic = True, + contents = contents, + line_num = 8, + column_num = 7, + start_column = 7, + query = 'fooar', + compilation_flags = ['-x', 'c++'] ) + + results = app.post_json( '/completions', completion_data ).json + assert_that( results, + contains_inanyorder( CompletionEntryMatcher( 'foobar' ), + CompletionEntryMatcher( 'floozar' ) ) ) + + @with_setup( Setup ) def GetCompletions_ForceSemantic_Works_test(): app = TestApp( ycmd.app )