Fix InsertNamespace indent matching
Aso updates the appropriate tests and adds docs to some relevant methods whose behavior might be confusing
This commit is contained in:
parent
26141253a5
commit
0523ad02c0
@ -1537,28 +1537,41 @@ def SelectFromList_Negative_test( vim_eval ):
|
|||||||
@patch( 'ycm.vimsupport.SearchInCurrentBuffer', return_value = 0 )
|
@patch( 'ycm.vimsupport.SearchInCurrentBuffer', return_value = 0 )
|
||||||
@patch( 'vim.current' )
|
@patch( 'vim.current' )
|
||||||
def InsertNamespace_insert_test( vim_current, *args ):
|
def InsertNamespace_insert_test( vim_current, *args ):
|
||||||
contents = [ 'var taco = Math' ]
|
contents = [ '',
|
||||||
|
'namespace Taqueria {',
|
||||||
|
'',
|
||||||
|
' int taco = Math' ]
|
||||||
vim_current.buffer = VimBuffer( '', contents = contents )
|
vim_current.buffer = VimBuffer( '', contents = contents )
|
||||||
|
|
||||||
vimsupport.InsertNamespace( 'System' )
|
vimsupport.InsertNamespace( 'System' )
|
||||||
|
|
||||||
expected_buffer = [ 'using System;',
|
expected_buffer = [ 'using System;',
|
||||||
'var taco = Math' ]
|
'',
|
||||||
|
'namespace Taqueria {',
|
||||||
|
'',
|
||||||
|
' int taco = Math' ]
|
||||||
AssertBuffersAreEqualAsBytes( expected_buffer, vim_current.buffer )
|
AssertBuffersAreEqualAsBytes( expected_buffer, vim_current.buffer )
|
||||||
|
|
||||||
|
|
||||||
@patch( 'ycm.vimsupport.VariableExists', return_value = False )
|
@patch( 'ycm.vimsupport.VariableExists', return_value = False )
|
||||||
@patch( 'ycm.vimsupport.SearchInCurrentBuffer', return_value = 1 )
|
@patch( 'ycm.vimsupport.SearchInCurrentBuffer', return_value = 2 )
|
||||||
@patch( 'vim.current' )
|
@patch( 'vim.current' )
|
||||||
def InsertNamespace_append_test( vim_current, *args ):
|
def InsertNamespace_append_test( vim_current, *args ):
|
||||||
contents = [ 'using System;', '', 'var taco;', 'var salad = new List']
|
contents = [ 'namespace Taqueria {',
|
||||||
|
' using System;',
|
||||||
|
'',
|
||||||
|
' class Tasty {',
|
||||||
|
' int taco;',
|
||||||
|
' List salad = new List']
|
||||||
vim_current.buffer = VimBuffer( '', contents = contents )
|
vim_current.buffer = VimBuffer( '', contents = contents )
|
||||||
|
|
||||||
vimsupport.InsertNamespace( 'System.Collections' )
|
vimsupport.InsertNamespace( 'System.Collections' )
|
||||||
|
|
||||||
expected_buffer = [ 'using System;',
|
expected_buffer = [ 'namespace Taqueria {',
|
||||||
|
' using System;',
|
||||||
' using System.Collections;',
|
' using System.Collections;',
|
||||||
'',
|
'',
|
||||||
'var taco;',
|
' class Tasty {',
|
||||||
'var salad = new List' ]
|
' int taco;',
|
||||||
|
' List salad = new List']
|
||||||
AssertBuffersAreEqualAsBytes( expected_buffer, vim_current.buffer )
|
AssertBuffersAreEqualAsBytes( expected_buffer, vim_current.buffer )
|
||||||
|
@ -846,7 +846,9 @@ def InsertNamespace( namespace ):
|
|||||||
return
|
return
|
||||||
|
|
||||||
pattern = '^\s*using\(\s\+[a-zA-Z0-9]\+\s\+=\)\?\s\+[a-zA-Z0-9.]\+\s*;\s*'
|
pattern = '^\s*using\(\s\+[a-zA-Z0-9]\+\s\+=\)\?\s\+[a-zA-Z0-9.]\+\s*;\s*'
|
||||||
|
existing_indent = ''
|
||||||
line = SearchInCurrentBuffer( pattern )
|
line = SearchInCurrentBuffer( pattern )
|
||||||
|
if line > 0:
|
||||||
existing_line = LineTextInCurrentBuffer( line )
|
existing_line = LineTextInCurrentBuffer( line )
|
||||||
existing_indent = re.sub( r"\S.*", "", existing_line )
|
existing_indent = re.sub( r"\S.*", "", existing_line )
|
||||||
new_line = "{0}using {1};\n\n".format( existing_indent, namespace )
|
new_line = "{0}using {1};\n\n".format( existing_indent, namespace )
|
||||||
@ -856,11 +858,14 @@ def InsertNamespace( namespace ):
|
|||||||
|
|
||||||
|
|
||||||
def SearchInCurrentBuffer( pattern ):
|
def SearchInCurrentBuffer( pattern ):
|
||||||
|
""" Returns the 1-indexed line on which the pattern matches
|
||||||
|
(going UP from the current position) or 0 if not found """
|
||||||
return GetIntValue( "search('{0}', 'Wcnb')".format( EscapeForVim( pattern )))
|
return GetIntValue( "search('{0}', 'Wcnb')".format( EscapeForVim( pattern )))
|
||||||
|
|
||||||
|
|
||||||
def LineTextInCurrentBuffer( line ):
|
def LineTextInCurrentBuffer( line ):
|
||||||
return vim.current.buffer[ line ]
|
""" Returns the text on the 1-indexed line (NOT 0-indexed) """
|
||||||
|
return vim.current.buffer[ line - 1 ]
|
||||||
|
|
||||||
|
|
||||||
def ClosePreviewWindow():
|
def ClosePreviewWindow():
|
||||||
|
Loading…
Reference in New Issue
Block a user