ycmd's JSON interface now uses 1-based indices

This makes far more sense because editors manipulate user-level errors/warnings
on a 1-based system, not a 0-based one.
This commit is contained in:
Strahinja Val Markovic 2014-05-09 15:57:04 -07:00
parent 81029d9f4e
commit d56ec1ea7a
16 changed files with 129 additions and 129 deletions

View File

@ -137,13 +137,15 @@ class BaseRequest( object ):
def BuildRequestData( start_column = None, def BuildRequestData( start_column = None,
query = None, query = None,
include_buffer_data = True ): include_buffer_data = True ):
if start_column is None:
start_column = 0
line, column = vimsupport.CurrentLineAndColumn() line, column = vimsupport.CurrentLineAndColumn()
filepath = vimsupport.GetCurrentBufferFilepath() filepath = vimsupport.GetCurrentBufferFilepath()
request_data = { request_data = {
'filetypes': vimsupport.CurrentFiletypes(), 'filetypes': vimsupport.CurrentFiletypes(),
'line_num': line, 'line_num': line + 1,
'column_num': column, 'column_num': column + 1,
'start_column': start_column, 'start_column': start_column + 1,
'line_value': vim.current.line, 'line_value': vim.current.line,
'filepath': filepath 'filepath': filepath
} }

View File

@ -66,8 +66,8 @@ class CommandRequest( BaseRequest ):
vim.eval( 'youcompleteme#OpenGoToList()' ) vim.eval( 'youcompleteme#OpenGoToList()' )
else: else:
vimsupport.JumpToLocation( self._response[ 'filepath' ], vimsupport.JumpToLocation( self._response[ 'filepath' ],
self._response[ 'line_num' ] + 1, self._response[ 'line_num' ],
self._response[ 'column_num' ] + 1) self._response[ 'column_num' ] )
@ -87,7 +87,7 @@ def _BuildQfListItem( goto_data_item ):
if 'description' in goto_data_item: if 'description' in goto_data_item:
qf_item[ 'text' ] = ToUtf8IfNeeded( goto_data_item[ 'description' ] ) qf_item[ 'text' ] = ToUtf8IfNeeded( goto_data_item[ 'description' ] )
if 'line_num' in goto_data_item: if 'line_num' in goto_data_item:
qf_item[ 'lnum' ] = goto_data_item[ 'line_num' ] + 1 qf_item[ 'lnum' ] = goto_data_item[ 'line_num' ]
if 'column_num' in goto_data_item: if 'column_num' in goto_data_item:
qf_item[ 'col' ] = goto_data_item[ 'column_num' ] qf_item[ 'col' ] = goto_data_item[ 'column_num' ] - 1
return qf_item return qf_item

View File

@ -160,8 +160,8 @@ class IdentifierCompleter( GeneralCompleter ):
def _PreviousIdentifier( min_num_completion_start_chars, request_data ): def _PreviousIdentifier( min_num_completion_start_chars, request_data ):
line_num = request_data[ 'line_num' ] line_num = request_data[ 'line_num' ] - 1
column_num = request_data[ 'column_num' ] column_num = request_data[ 'column_num' ] - 1
filepath = request_data[ 'filepath' ] filepath = request_data[ 'filepath' ]
contents_per_line = ( contents_per_line = (
request_data[ 'file_data' ][ filepath ][ 'contents' ].split( '\n' ) ) request_data[ 'file_data' ][ filepath ][ 'contents' ].split( '\n' ) )
@ -226,7 +226,7 @@ def _GetCursorIdentifier( request_data ):
identifier_end += 1 identifier_end += 1
return identifier_end + 1 return identifier_end + 1
column_num = request_data[ 'column_num' ] column_num = request_data[ 'column_num' ] - 1
line = request_data[ 'line_value' ] line = request_data[ 'line_value' ]
try: try:

View File

@ -25,14 +25,14 @@ def GetCursorIdentifier_StartOfLine_test():
eq_( 'foo', eq_( 'foo',
identifier_completer._GetCursorIdentifier( identifier_completer._GetCursorIdentifier(
{ {
'column_num': 0, 'column_num': 1,
'line_value': 'foo' 'line_value': 'foo'
} ) ) } ) )
eq_( 'fooBar', eq_( 'fooBar',
identifier_completer._GetCursorIdentifier( identifier_completer._GetCursorIdentifier(
{ {
'column_num': 0, 'column_num': 1,
'line_value': 'fooBar' 'line_value': 'fooBar'
} ) ) } ) )
@ -41,7 +41,7 @@ def GetCursorIdentifier_EndOfLine_test():
eq_( 'foo', eq_( 'foo',
identifier_completer._GetCursorIdentifier( identifier_completer._GetCursorIdentifier(
{ {
'column_num': 2, 'column_num': 3,
'line_value': 'foo' 'line_value': 'foo'
} ) ) } ) )
@ -50,7 +50,7 @@ def GetCursorIdentifier_PastEndOfLine_test():
eq_( '', eq_( '',
identifier_completer._GetCursorIdentifier( identifier_completer._GetCursorIdentifier(
{ {
'column_num': 10, 'column_num': 11,
'line_value': 'foo' 'line_value': 'foo'
} ) ) } ) )
@ -68,7 +68,7 @@ def GetCursorIdentifier_StartOfLine_StopsAtNonIdentifierChar_test():
eq_( 'foo', eq_( 'foo',
identifier_completer._GetCursorIdentifier( identifier_completer._GetCursorIdentifier(
{ {
'column_num': 0, 'column_num': 1,
'line_value': 'foo(goo)' 'line_value': 'foo(goo)'
} ) ) } ) )
@ -77,7 +77,7 @@ def GetCursorIdentifier_AtNonIdentifier_test():
eq_( 'goo', eq_( 'goo',
identifier_completer._GetCursorIdentifier( identifier_completer._GetCursorIdentifier(
{ {
'column_num': 3, 'column_num': 4,
'line_value': 'foo(goo)' 'line_value': 'foo(goo)'
} ) ) } ) )
@ -86,7 +86,7 @@ def GetCursorIdentifier_WalksForwardForIdentifier_test():
eq_( 'foo', eq_( 'foo',
identifier_completer._GetCursorIdentifier( identifier_completer._GetCursorIdentifier(
{ {
'column_num': 0, 'column_num': 1,
'line_value': ' foo' 'line_value': ' foo'
} ) ) } ) )
@ -95,7 +95,7 @@ def GetCursorIdentifier_FindsNothingForward_test():
eq_( '', eq_( '',
identifier_completer._GetCursorIdentifier( identifier_completer._GetCursorIdentifier(
{ {
'column_num': 4, 'column_num': 5,
'line_value': 'foo ()***()' 'line_value': 'foo ()***()'
} ) ) } ) )
@ -104,7 +104,7 @@ def GetCursorIdentifier_SingleCharIdentifier_test():
eq_( 'f', eq_( 'f',
identifier_completer._GetCursorIdentifier( identifier_completer._GetCursorIdentifier(
{ {
'column_num': 0, 'column_num': 1,
'line_value': ' f ' 'line_value': ' f '
} ) ) } ) )
@ -113,7 +113,7 @@ def GetCursorIdentifier_StartsInMiddleOfIdentifier_test():
eq_( 'foobar', eq_( 'foobar',
identifier_completer._GetCursorIdentifier( identifier_completer._GetCursorIdentifier(
{ {
'column_num': 3, 'column_num': 4,
'line_value': 'foobar' 'line_value': 'foobar'
} ) ) } ) )
@ -122,6 +122,6 @@ def GetCursorIdentifier_LineEmpty_test():
eq_( '', eq_( '',
identifier_completer._GetCursorIdentifier( identifier_completer._GetCursorIdentifier(
{ {
'column_num': 11, 'column_num': 12,
'line_value': '' 'line_value': ''
} ) ) } ) )

View File

@ -133,7 +133,7 @@ class Completer( object ):
def ShouldUseNowInner( self, request_data ): def ShouldUseNowInner( self, request_data ):
current_line = request_data[ 'line_value' ] current_line = request_data[ 'line_value' ]
start_column = request_data[ 'start_column' ] start_column = request_data[ 'start_column' ] - 1
line_length = len( current_line ) line_length = len( current_line )
if not line_length or start_column - 1 >= line_length: if not line_length or start_column - 1 >= line_length:
return False return False

View File

@ -85,8 +85,8 @@ class ClangCompleter( Completer ):
raise RuntimeError( NO_COMPILE_FLAGS_MESSAGE ) raise RuntimeError( NO_COMPILE_FLAGS_MESSAGE )
files = self.GetUnsavedFilesVector( request_data ) files = self.GetUnsavedFilesVector( request_data )
line = request_data[ 'line_num' ] + 1 line = request_data[ 'line_num' ]
column = request_data[ 'start_column' ] + 1 column = request_data[ 'start_column' ]
results = self._completer.CandidatesForLocationInFile( results = self._completer.CandidatesForLocationInFile(
ToUtf8IfNeeded( filename ), ToUtf8IfNeeded( filename ),
line, line,
@ -136,8 +136,8 @@ class ClangCompleter( Completer ):
raise ValueError( NO_COMPILE_FLAGS_MESSAGE ) raise ValueError( NO_COMPILE_FLAGS_MESSAGE )
files = self.GetUnsavedFilesVector( request_data ) files = self.GetUnsavedFilesVector( request_data )
line = request_data[ 'line_num' ] + 1 line = request_data[ 'line_num' ]
column = request_data[ 'column_num' ] + 1 column = request_data[ 'column_num' ]
return getattr( self._completer, goto_function )( return getattr( self._completer, goto_function )(
ToUtf8IfNeeded( filename ), ToUtf8IfNeeded( filename ),
line, line,
@ -217,8 +217,8 @@ class ClangCompleter( Completer ):
def GetDetailedDiagnostic( self, request_data ): def GetDetailedDiagnostic( self, request_data ):
current_line = request_data[ 'line_num' ] + 1 current_line = request_data[ 'line_num' ]
current_column = request_data[ 'column_num' ] + 1 current_column = request_data[ 'column_num' ]
current_file = request_data[ 'filepath' ] current_file = request_data[ 'filepath' ]
if not self._diagnostic_store: if not self._diagnostic_store:
@ -304,7 +304,7 @@ def _FilterDiagnostics( diagnostics ):
def _ResponseForLocation( location ): def _ResponseForLocation( location ):
return responses.BuildGoToResponse( location.filename_, return responses.BuildGoToResponse( location.filename_,
location.line_number_ - 1, location.line_number_,
location.column_number_ - 1) location.column_number_ )

View File

@ -157,8 +157,8 @@ class CsharpCompleter( Completer ):
def GetDetailedDiagnostic( self, request_data ): def GetDetailedDiagnostic( self, request_data ):
current_line = request_data[ 'line_num' ] + 1 current_line = request_data[ 'line_num' ]
current_column = request_data[ 'column_num' ] + 1 current_column = request_data[ 'column_num' ]
current_file = request_data[ 'filepath' ] current_file = request_data[ 'filepath' ]
if not self._diagnostic_store: if not self._diagnostic_store:
@ -301,8 +301,8 @@ class CsharpCompleter( Completer ):
self._DefaultParameters( request_data ) ) self._DefaultParameters( request_data ) )
if definition[ 'FileName' ] != None: if definition[ 'FileName' ] != None:
return responses.BuildGoToResponse( definition[ 'FileName' ], return responses.BuildGoToResponse( definition[ 'FileName' ],
definition[ 'Line' ] - 1, definition[ 'Line' ],
definition[ 'Column' ] - 1 ) definition[ 'Column' ] )
else: else:
raise RuntimeError( 'Can\'t jump to definition' ) raise RuntimeError( 'Can\'t jump to definition' )
@ -310,11 +310,11 @@ class CsharpCompleter( Completer ):
def _DefaultParameters( self, request_data ): def _DefaultParameters( self, request_data ):
""" Some very common request parameters """ """ Some very common request parameters """
parameters = {} parameters = {}
parameters[ 'line' ] = request_data[ 'line_num' ] + 1 parameters[ 'line' ] = request_data[ 'line_num' ]
parameters[ 'column' ] = request_data[ 'column_num' ] + 1 parameters[ 'column' ] = request_data[ 'column_num' ]
filepath = request_data[ 'filepath' ] filepath = request_data[ 'filepath' ]
parameters[ 'buffer' ] = request_data[ 'file_data' ][ filepath ][ parameters[ 'buffer' ] = (
'contents' ] request_data[ 'file_data' ][ filepath ][ 'contents' ] )
parameters[ 'filename' ] = filepath parameters[ 'filename' ] = filepath
return parameters return parameters

View File

@ -57,7 +57,7 @@ class FilenameCompleter( Completer ):
def AtIncludeStatementStart( self, request_data ): def AtIncludeStatementStart( self, request_data ):
start_column = request_data[ 'start_column' ] start_column = request_data[ 'start_column' ] - 1
current_line = request_data[ 'line_value' ] current_line = request_data[ 'line_value' ]
filepath = ToUtf8IfNeeded( request_data[ 'filepath' ] ) filepath = ToUtf8IfNeeded( request_data[ 'filepath' ] )
filetypes = request_data[ 'file_data' ][ filepath ][ 'filetypes' ] filetypes = request_data[ 'file_data' ][ filepath ][ 'filetypes' ]
@ -67,7 +67,7 @@ class FilenameCompleter( Completer ):
def ShouldUseNowInner( self, request_data ): def ShouldUseNowInner( self, request_data ):
start_column = request_data[ 'start_column' ] start_column = request_data[ 'start_column' ] - 1
current_line = request_data[ 'line_value' ] current_line = request_data[ 'line_value' ]
return ( start_column and ( current_line[ start_column - 1 ] == '/' or return ( start_column and ( current_line[ start_column - 1 ] == '/' or
self.AtIncludeStatementStart( request_data ) ) ) self.AtIncludeStatementStart( request_data ) ) )
@ -79,7 +79,7 @@ class FilenameCompleter( Completer ):
def ComputeCandidatesInner( self, request_data ): def ComputeCandidatesInner( self, request_data ):
current_line = request_data[ 'line_value' ] current_line = request_data[ 'line_value' ]
start_column = request_data[ 'start_column' ] start_column = request_data[ 'start_column' ] - 1
filepath = ToUtf8IfNeeded( request_data[ 'filepath' ] ) filepath = ToUtf8IfNeeded( request_data[ 'filepath' ] )
filetypes = request_data[ 'file_data' ][ filepath ][ 'filetypes' ] filetypes = request_data[ 'file_data' ][ filepath ][ 'filetypes' ]
line = current_line[ :start_column ] line = current_line[ :start_column ]

View File

@ -40,7 +40,7 @@ request_data = {
} }
def GetCompletionData( request_data ): def GetCompletionData( request_data ):
request_data[ 'start_column' ] = len( request_data[ 'line_value' ] ) request_data[ 'start_column' ] = len( request_data[ 'line_value' ] ) + 1
candidates = fnc.ComputeCandidatesInner( request_data ) candidates = fnc.ComputeCandidatesInner( request_data )
return [ ( c[ 'insertion_text' ], c[ 'extra_menu_info' ] ) for c in candidates ] return [ ( c[ 'insertion_text' ], c[ 'extra_menu_info' ] ) for c in candidates ]

View File

@ -48,9 +48,9 @@ class JediCompleter( Completer ):
def _GetJediScript( self, request_data ): def _GetJediScript( self, request_data ):
filename = request_data[ 'filepath' ] filename = request_data[ 'filepath' ]
contents = request_data[ 'file_data' ][ filename ][ 'contents' ] contents = request_data[ 'file_data' ][ filename ][ 'contents' ]
# Jedi expects lines to start at 1, not 0 line = request_data[ 'line_num' ]
line = request_data[ 'line_num' ] + 1 # Jedi expects columns to start at 0, not 1
column = request_data[ 'column_num' ] column = request_data[ 'column_num' ] - 1
return jedi.Script( contents, line, column, filename ) return jedi.Script( contents, line, column, filename )
@ -134,8 +134,8 @@ class JediCompleter( Completer ):
raise RuntimeError( 'Builtin modules cannot be displayed.' ) raise RuntimeError( 'Builtin modules cannot be displayed.' )
else: else:
return responses.BuildGoToResponse( definition.module_path, return responses.BuildGoToResponse( definition.module_path,
definition.line - 1, definition.line,
definition.column ) definition.column + 1 )
else: else:
# multiple definitions # multiple definitions
defs = [] defs = []
@ -146,8 +146,8 @@ class JediCompleter( Completer ):
else: else:
defs.append( defs.append(
responses.BuildGoToResponse( definition.module_path, responses.BuildGoToResponse( definition.module_path,
definition.line - 1, definition.line,
definition.column, definition.column + 1,
definition.description ) ) definition.description ) )
return defs return defs

View File

@ -83,22 +83,22 @@ def _UpdateSquiggles( buffer_number_to_line_to_diags ):
if location_extent[ 'start' ][ 'line_num' ] < 0: if location_extent[ 'start' ][ 'line_num' ] < 0:
location = diag[ 'location' ] location = diag[ 'location' ]
vimsupport.AddDiagnosticSyntaxMatch( vimsupport.AddDiagnosticSyntaxMatch(
location[ 'line_num' ] + 1, location[ 'line_num' ],
location[ 'column_num' ] + 1 ) location[ 'column_num' ] )
else: else:
vimsupport.AddDiagnosticSyntaxMatch( vimsupport.AddDiagnosticSyntaxMatch(
location_extent[ 'start' ][ 'line_num' ] + 1, location_extent[ 'start' ][ 'line_num' ],
location_extent[ 'start' ][ 'column_num' ] + 1, location_extent[ 'start' ][ 'column_num' ],
location_extent[ 'end' ][ 'line_num' ] + 1, location_extent[ 'end' ][ 'line_num' ],
location_extent[ 'end' ][ 'column_num' ] + 1, location_extent[ 'end' ][ 'column_num' ],
is_error = is_error ) is_error = is_error )
for diag_range in diag[ 'ranges' ]: for diag_range in diag[ 'ranges' ]:
vimsupport.AddDiagnosticSyntaxMatch( vimsupport.AddDiagnosticSyntaxMatch(
diag_range[ 'start' ][ 'line_num' ] + 1, diag_range[ 'start' ][ 'line_num' ],
diag_range[ 'start' ][ 'column_num' ] + 1, diag_range[ 'start' ][ 'column_num' ],
diag_range[ 'end' ][ 'line_num' ] + 1, diag_range[ 'end' ][ 'line_num' ],
diag_range[ 'end' ][ 'column_num' ] + 1, diag_range[ 'end' ][ 'column_num' ],
is_error = is_error ) is_error = is_error )
@ -125,7 +125,7 @@ def _ConvertDiagListToDict( diag_list ):
location = diag[ 'location' ] location = diag[ 'location' ]
buffer_number = vimsupport.GetBufferNumberForFilename( buffer_number = vimsupport.GetBufferNumberForFilename(
location[ 'filepath' ] ) location[ 'filepath' ] )
line_number = location[ 'line_num' ] + 1 line_number = location[ 'line_num' ]
buffer_to_line_to_diags[ buffer_number ][ line_number ].append( diag ) buffer_to_line_to_diags[ buffer_number ][ line_number ].append( diag )
for line_to_diags in buffer_to_line_to_diags.itervalues(): for line_to_diags in buffer_to_line_to_diags.itervalues():

View File

@ -110,8 +110,8 @@ def BuildDiagnosticData( diagnostic ):
def BuildLocationData( location ): def BuildLocationData( location ):
return { return {
'line_num': location.line_number_ - 1, 'line_num': location.line_number_,
'column_num': location.column_number_ - 1, 'column_num': location.column_number_,
'filepath': location.filename_, 'filepath': location.filename_,
} }

View File

@ -55,26 +55,26 @@ void foo() {
'text': contains_string( 'cannot initialize' ), 'text': contains_string( 'cannot initialize' ),
'ranges': contains( has_entries( { 'ranges': contains( has_entries( {
'start': has_entries( { 'start': has_entries( {
'line_num': 2, 'line_num': 3,
'column_num': 15, 'column_num': 16,
} ), } ),
'end': has_entries( { 'end': has_entries( {
'line_num': 2, 'line_num': 3,
'column_num': 20, 'column_num': 21,
} ), } ),
} ) ), } ) ),
'location': has_entries( { 'location': has_entries( {
'line_num': 2, 'line_num': 3,
'column_num': 9 'column_num': 10
} ), } ),
'location_extent': has_entries( { 'location_extent': has_entries( {
'start': has_entries( { 'start': has_entries( {
'line_num': 2, 'line_num': 3,
'column_num': 9, 'column_num': 10,
} ), } ),
'end': has_entries( { 'end': has_entries( {
'line_num': 2, 'line_num': 3,
'column_num': 12, 'column_num': 13,
} ), } ),
} ) } )
} ) ) ) } ) ) )
@ -102,12 +102,12 @@ void foo() {
has_entries( { has_entries( {
'location_extent': has_entries( { 'location_extent': has_entries( {
'start': has_entries( { 'start': has_entries( {
'line_num': 2, 'line_num': 3,
'column_num': 2, 'column_num': 3,
} ), } ),
'end': has_entries( { 'end': has_entries( {
'line_num': 2, 'line_num': 3,
'column_num': 5, 'column_num': 6,
} ), } ),
} ) } )
} ) ) ) } ) ) )
@ -163,17 +163,17 @@ def Diagnostics_CsCompleter_ZeroBasedLineAndColumn_test():
'text': contains_string( 'text': contains_string(
"Unexpected symbol `}'', expecting identifier" ), "Unexpected symbol `}'', expecting identifier" ),
'location': has_entries( { 'location': has_entries( {
'line_num': 9, 'line_num': 10,
'column_num': 1 'column_num': 2
} ), } ),
'location_extent': has_entries( { 'location_extent': has_entries( {
'start': has_entries( { 'start': has_entries( {
'line_num': 9, 'line_num': 10,
'column_num': 1, 'column_num': 2,
} ), } ),
'end': has_entries( { 'end': has_entries( {
'line_num': 9, 'line_num': 10,
'column_num': 1, 'column_num': 2,
} ), } ),
} ) } )
} ) ) ) } ) ) )
@ -194,7 +194,7 @@ struct Foo {
""" """
diag_data = BuildRequest( compilation_flags = ['-x', 'c++'], diag_data = BuildRequest( compilation_flags = ['-x', 'c++'],
line_num = 2, line_num = 3,
contents = contents, contents = contents,
filetype = 'cpp' ) filetype = 'cpp' )
@ -226,9 +226,9 @@ def GetDetailedDiagnostic_CsCompleter_Works_test():
diag_data = BuildRequest( filepath = filepath, diag_data = BuildRequest( filepath = filepath,
filetype = 'cs', filetype = 'cs',
contents = contents, contents = contents,
line_num = 9, line_num = 10,
column_num = 1, column_num = 2,
start_column = 1 ) start_column = 2 )
results = app.post_json( '/detailed_diagnostic', diag_data ).json results = app.post_json( '/detailed_diagnostic', diag_data ).json
assert_that( results, assert_that( results,
@ -244,7 +244,7 @@ def GetDetailedDiagnostic_CsCompleter_Works_test():
def GetDetailedDiagnostic_JediCompleter_DoesntWork_test(): def GetDetailedDiagnostic_JediCompleter_DoesntWork_test():
app = TestApp( handlers.app ) app = TestApp( handlers.app )
diag_data = BuildRequest( contents = "foo = 5", diag_data = BuildRequest( contents = "foo = 5",
line_num = 1, line_num = 2,
filetype = 'python' ) filetype = 'python' )
response = app.post_json( '/detailed_diagnostic', response = app.post_json( '/detailed_diagnostic',
diag_data, diag_data,

View File

@ -50,7 +50,7 @@ def GetCompletions_IdentifierCompleter_Works_test():
completion_data = BuildRequest( contents = 'oo foo foogoo ba', completion_data = BuildRequest( contents = 'oo foo foogoo ba',
query = 'oo', query = 'oo',
column_num = 2 ) column_num = 3 )
eq_( [ BuildCompletionData( 'foo' ), eq_( [ BuildCompletionData( 'foo' ),
BuildCompletionData( 'foogoo' ) ], BuildCompletionData( 'foogoo' ) ],
@ -73,9 +73,9 @@ def GetCompletions_CsCompleter_Works_test():
completion_data = BuildRequest( filepath = filepath, completion_data = BuildRequest( filepath = filepath,
filetype = 'cs', filetype = 'cs',
contents = contents, contents = contents,
line_num = 8, line_num = 9,
column_num = 11, column_num = 12,
start_column = 11 ) start_column = 12 )
results = app.post_json( '/completions', completion_data ).json results = app.post_json( '/completions', completion_data ).json
assert_that( results, has_items( CompletionEntryMatcher( 'CursorLeft' ), assert_that( results, has_items( CompletionEntryMatcher( 'CursorLeft' ),
@ -172,9 +172,9 @@ int main()
completion_data = BuildRequest( filepath = '/foo.cpp', completion_data = BuildRequest( filepath = '/foo.cpp',
filetype = 'cpp', filetype = 'cpp',
contents = contents, contents = contents,
line_num = 10, line_num = 11,
column_num = 6, column_num = 7,
start_column = 6, start_column = 7,
compilation_flags = ['-x', 'c++'] ) compilation_flags = ['-x', 'c++'] )
results = app.post_json( '/completions', completion_data ).json results = app.post_json( '/completions', completion_data ).json
@ -204,9 +204,9 @@ int main()
completion_data = BuildRequest( filepath = '/foo.cpp', completion_data = BuildRequest( filepath = '/foo.cpp',
filetype = 'cpp', filetype = 'cpp',
contents = contents, contents = contents,
line_num = 10, line_num = 11,
column_num = 6, column_num = 7,
start_column = 6, start_column = 7,
compilation_flags = ['-x', 'c++'] ) compilation_flags = ['-x', 'c++'] )
results = app.post_json( '/completions', completion_data ).json results = app.post_json( '/completions', completion_data ).json
@ -220,9 +220,9 @@ def GetCompletions_ClangCompleter_UnknownExtraConfException_test():
completion_data = BuildRequest( filepath = filepath, completion_data = BuildRequest( filepath = filepath,
filetype = 'cpp', filetype = 'cpp',
contents = open( filepath ).read(), contents = open( filepath ).read(),
line_num = 10, line_num = 11,
column_num = 6, column_num = 7,
start_column = 6, start_column = 7,
force_semantic = True ) force_semantic = True )
response = app.post_json( '/completions', response = app.post_json( '/completions',
@ -257,9 +257,9 @@ def GetCompletions_ClangCompleter_WorksWhenExtraConfExplicitlyAllowed_test():
completion_data = BuildRequest( filepath = filepath, completion_data = BuildRequest( filepath = filepath,
filetype = 'cpp', filetype = 'cpp',
contents = open( filepath ).read(), contents = open( filepath ).read(),
line_num = 10, line_num = 11,
column_num = 6, column_num = 7,
start_column = 6 ) start_column = 7 )
results = app.post_json( '/completions', completion_data ).json results = app.post_json( '/completions', completion_data ).json
assert_that( results, has_items( CompletionEntryMatcher( 'c' ), assert_that( results, has_items( CompletionEntryMatcher( 'c' ),
@ -278,9 +278,9 @@ def GetCompletions_ClangCompleter_ExceptionWhenNoFlagsFromExtraConf_test():
completion_data = BuildRequest( filepath = filepath, completion_data = BuildRequest( filepath = filepath,
filetype = 'cpp', filetype = 'cpp',
contents = open( filepath ).read(), contents = open( filepath ).read(),
line_num = 10, line_num = 11,
column_num = 6, column_num = 7,
start_column = 6 ) start_column = 7 )
response = app.post_json( '/completions', response = app.post_json( '/completions',
completion_data, completion_data,
@ -311,9 +311,9 @@ int main()
filetype = 'cpp', filetype = 'cpp',
force_semantic = True, force_semantic = True,
contents = contents, contents = contents,
line_num = 8, line_num = 9,
column_num = 7, column_num = 8,
start_column = 7, start_column = 8,
query = 'fooar', query = 'fooar',
compilation_flags = ['-x', 'c++'] ) compilation_flags = ['-x', 'c++'] )
@ -347,9 +347,9 @@ def GetCompletions_ClangCompleter_ClientDataGivenToExtraConf_test():
completion_data = BuildRequest( filepath = filepath, completion_data = BuildRequest( filepath = filepath,
filetype = 'cpp', filetype = 'cpp',
contents = open( filepath ).read(), contents = open( filepath ).read(),
line_num = 8, line_num = 9,
column_num = 6, column_num = 7,
start_column = 6, start_column = 7,
extra_conf_data = { extra_conf_data = {
'flags': ['-x', 'c++'] 'flags': ['-x', 'c++']
}) })
@ -368,7 +368,7 @@ def GetCompletions_IdentifierCompleter_SyntaxKeywordsAdded_test():
completion_data = BuildRequest( contents = 'oo ', completion_data = BuildRequest( contents = 'oo ',
query = 'oo', query = 'oo',
column_num = 2 ) column_num = 3 )
eq_( [ BuildCompletionData( 'foo' ), eq_( [ BuildCompletionData( 'foo' ),
BuildCompletionData( 'zoo' ) ], BuildCompletionData( 'zoo' ) ],
@ -389,7 +389,7 @@ def GetCompletions_UltiSnipsCompleter_Works_test():
completion_data = BuildRequest( contents = 'oo ', completion_data = BuildRequest( contents = 'oo ',
query = 'oo', query = 'oo',
column_num = 2 ) column_num = 3 )
eq_( [ BuildCompletionData( 'foo', '<snip> bar' ), eq_( [ BuildCompletionData( 'foo', '<snip> bar' ),
BuildCompletionData( 'zoo', '<snip> goo' ) ], BuildCompletionData( 'zoo', '<snip> goo' ) ],
@ -412,7 +412,7 @@ def GetCompletions_UltiSnipsCompleter_UnusedWhenOffWithOption_test():
completion_data = BuildRequest( contents = 'oo ', completion_data = BuildRequest( contents = 'oo ',
query = 'oo', query = 'oo',
column_num = 2 ) column_num = 3 )
eq_( [], app.post_json( '/completions', completion_data ).json ) eq_( [], app.post_json( '/completions', completion_data ).json )

View File

@ -40,16 +40,15 @@ foo()
goto_data = BuildRequest( completer_target = 'filetype_default', goto_data = BuildRequest( completer_target = 'filetype_default',
command_arguments = ['GoToDefinition'], command_arguments = ['GoToDefinition'],
line_num = 4, line_num = 5,
contents = contents, contents = contents,
filetype = 'python', filetype = 'python',
filepath = '/foo.py' ) filepath = '/foo.py' )
# 0-based line and column!
eq_( { eq_( {
'filepath': '/foo.py', 'filepath': '/foo.py',
'line_num': 1, 'line_num': 2,
'column_num': 4 'column_num': 5
}, },
app.post_json( '/run_completer_command', goto_data ).json ) app.post_json( '/run_completer_command', goto_data ).json )
@ -74,16 +73,15 @@ int main()
goto_data = BuildRequest( completer_target = 'filetype_default', goto_data = BuildRequest( completer_target = 'filetype_default',
command_arguments = ['GoToDefinition'], command_arguments = ['GoToDefinition'],
compilation_flags = ['-x', 'c++'], compilation_flags = ['-x', 'c++'],
line_num = 9, line_num = 10,
column_num = 2, column_num = 3,
contents = contents, contents = contents,
filetype = 'cpp' ) filetype = 'cpp' )
# 0-based line and column!
eq_( { eq_( {
'filepath': '/foo', 'filepath': '/foo',
'line_num': 1, 'line_num': 2,
'column_num': 7 'column_num': 8
}, },
app.post_json( '/run_completer_command', goto_data ).json ) app.post_json( '/run_completer_command', goto_data ).json )

View File

@ -29,9 +29,9 @@ def BuildRequest( **kwargs ):
request = { request = {
'query': '', 'query': '',
'line_num': 0, 'line_num': 1,
'column_num': 0, 'column_num': 1,
'start_column': 0, 'start_column': 1,
'filetypes': [ filetype ], 'filetypes': [ filetype ],
'filepath': filepath, 'filepath': filepath,
'line_value': contents, 'line_value': contents,
@ -51,8 +51,8 @@ def BuildRequest( **kwargs ):
if key == 'line_num': if key == 'line_num':
lines = contents.splitlines() lines = contents.splitlines()
if len( lines ) > 1: if len( lines ) > 1:
# NOTE: assumes 0-based line_num # NOTE: assumes 1-based line_num
request[ 'line_value' ] = lines[ value ] request[ 'line_value' ] = lines[ value - 1 ]
return request return request