<c-space> works again (forces semantic completion)

This commit is contained in:
Strahinja Val Markovic 2013-10-07 13:09:34 -07:00
parent 99b0f018b3
commit ff7fa74fc9
7 changed files with 47 additions and 13 deletions

View File

@ -566,8 +566,7 @@ function! youcompleteme#Complete( findstart, base )
return -2 return -2
endif endif
py request = ycm_state.CreateCompletionRequest() return pyeval( 'ycm_state.CreateCompletionRequest().CompletionStartColumn()' )
return pyeval( 'request.CompletionStartColumn()' )
else else
return s:CompletionsForQuery( a:base ) return s:CompletionsForQuery( a:base )
endif endif
@ -577,8 +576,8 @@ endfunction
function! youcompleteme#OmniComplete( findstart, base ) function! youcompleteme#OmniComplete( findstart, base )
if a:findstart if a:findstart
let s:omnifunc_mode = 1 let s:omnifunc_mode = 1
" TODO: Force semantic mode here (<c-space> needs to work) py request = ycm_state.CreateCompletionRequest( force_semantic = True )
return pyeval( 'ycm_state.CreateCompletionRequest().CompletionStartColumn()' ) return pyeval( 'request.CompletionStartColumn()' )
else else
return s:CompletionsForQuery( a:base ) return s:CompletionsForQuery( a:base )
endif endif

View File

@ -24,11 +24,13 @@ from ycm.client.base_request import ( BaseRequest, BuildRequestData,
class CompletionRequest( BaseRequest ): class CompletionRequest( BaseRequest ):
def __init__( self ): def __init__( self, force_semantic = False ):
super( CompletionRequest, self ).__init__() super( CompletionRequest, self ).__init__()
self._completion_start_column = base.CompletionStartColumn() self._completion_start_column = base.CompletionStartColumn()
self._request_data = BuildRequestData( self._completion_start_column ) self._request_data = BuildRequestData( self._completion_start_column )
if force_semantic:
self._request_data[ 'force_semantic' ] = True
def CompletionStartColumn( self ): def CompletionStartColumn( self ):

View File

@ -19,7 +19,7 @@
import abc import abc
import ycm_core import ycm_core
from ycm.utils import ToUtf8IfNeeded from ycm.utils import ToUtf8IfNeeded, ForceSemanticCompletion
from ycm.completers.completer_utils import TriggersForFiletype from ycm.completers.completer_utils import TriggersForFiletype
NO_USER_COMMANDS = 'This completer does not define any commands.' NO_USER_COMMANDS = 'This completer does not define any commands.'
@ -149,7 +149,8 @@ class Completer( object ):
# It's highly likely you DON'T want to override this function but the *Inner # It's highly likely you DON'T want to override this function but the *Inner
# version of it. # version of it.
def ComputeCandidates( self, request_data ): def ComputeCandidates( self, request_data ):
if not self.ShouldUseNow( request_data ): if ( not ForceSemanticCompletion( request_data ) and
not self.ShouldUseNow( request_data ) ):
return [] return []
if ( request_data[ 'query' ] and if ( request_data[ 'query' ] and

View File

@ -20,6 +20,7 @@
import imp import imp
import os import os
from ycm import extra_conf_store from ycm import extra_conf_store
from ycm.utils import ForceSemanticCompletion
from ycm.completers.general.general_completer_store import GeneralCompleterStore from ycm.completers.general.general_completer_store import GeneralCompleterStore
@ -85,6 +86,7 @@ class ServerState( object ):
except: except:
return False return False
def FiletypeCompletionUsable( self, filetypes ): def FiletypeCompletionUsable( self, filetypes ):
return ( self.CurrentFiletypeCompletionEnabled( filetypes ) and return ( self.CurrentFiletypeCompletionEnabled( filetypes ) and
self.FiletypeCompletionAvailable( filetypes ) ) self.FiletypeCompletionAvailable( filetypes ) )
@ -97,7 +99,9 @@ class ServerState( object ):
def ShouldUseFiletypeCompleter( self, request_data ): def ShouldUseFiletypeCompleter( self, request_data ):
filetypes = request_data[ 'filetypes' ] filetypes = request_data[ 'filetypes' ]
if self.FiletypeCompletionUsable( filetypes ): if self.FiletypeCompletionUsable( filetypes ):
return self.GetFiletypeCompleter( filetypes ).ShouldUseNow( request_data ) return ( ForceSemanticCompletion( request_data ) or
self.GetFiletypeCompleter( filetypes ).ShouldUseNow(
request_data ) )
return False return False

View File

@ -30,16 +30,23 @@ bottle.debug( True )
# TODO: Split this file into multiple files. # TODO: Split this file into multiple files.
# 'contents' should be just one line of text # 'contents' should be just one line of text
def RequestDataForFileWithContents( filename, contents = None ): def RequestDataForFileWithContents( filename,
contents = None,
filetype = None ):
real_contents = contents if contents else '' real_contents = contents if contents else ''
filetype_to_use = filetype or 'foo'
return { return {
'filetypes': ['foo'], 'query': '',
'line_num': 0,
'column_num': 0,
'start_column': 0,
'filetypes': [ filetype_to_use ],
'filepath': filename, 'filepath': filename,
'line_value': real_contents, 'line_value': real_contents,
'file_data': { 'file_data': {
filename: { filename: {
'contents': real_contents, 'contents': real_contents,
'filetypes': ['foo'] 'filetypes': [ filetype_to_use ]
} }
} }
} }
@ -120,6 +127,22 @@ int main()
CompletionEntryMatcher( 'y' ) ) ) CompletionEntryMatcher( 'y' ) ) )
@with_setup( Setup )
def GetCompletions_ForceSemantic_Works_test():
app = TestApp( ycmd.app )
completion_data = RequestDataForFileWithContents( 'foo.py',
filetype = 'python' )
completion_data.update( {
'force_semantic': True,
} )
results = app.post_json( '/completions', completion_data ).json
assert_that( results, has_items( CompletionEntryMatcher( 'abs' ),
CompletionEntryMatcher( 'open' ),
CompletionEntryMatcher( 'bool' ) ) )
@with_setup( Setup ) @with_setup( Setup )
def GetCompletions_IdentifierCompleter_SyntaxKeywordsAdded_test(): def GetCompletions_IdentifierCompleter_SyntaxKeywordsAdded_test():
app = TestApp( ycmd.app ) app = TestApp( ycmd.app )

View File

@ -77,3 +77,8 @@ def Memoize( obj ):
cache[ key ] = obj( *args, **kwargs ) cache[ key ] = obj( *args, **kwargs )
return cache[ key ] return cache[ key ]
return memoizer return memoizer
def ForceSemanticCompletion( request_data ):
return ( 'force_semantic' in request_data and
bool( request_data[ 'force_semantic' ] ) )

View File

@ -89,11 +89,11 @@ class YouCompleteMe( object ):
shell = True ) shell = True )
def CreateCompletionRequest( self ): def CreateCompletionRequest( self, force_semantic = False ):
# We have to store a reference to the newly created CompletionRequest # We have to store a reference to the newly created CompletionRequest
# because VimScript can't store a reference to a Python object across # because VimScript can't store a reference to a Python object across
# function calls... Thus we need to keep this request somewhere. # function calls... Thus we need to keep this request somewhere.
self._latest_completion_request = CompletionRequest() self._latest_completion_request = CompletionRequest( force_semantic )
return self._latest_completion_request return self._latest_completion_request