Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make C# completer consistent with other completers regarding GoToDocu…
Browse files Browse the repository at this point in the history
…mentOutline

All other semantic completers return a list only when more than one item
is in the list. Otherwise return that one item.
bstaletic committed Jan 4, 2024
1 parent d73494d commit aa6f3a9
Showing 4 changed files with 52 additions and 77 deletions.
4 changes: 3 additions & 1 deletion ycmd/completers/cs/cs_completer.py
Original file line number Diff line number Diff line change
@@ -681,7 +681,9 @@ def _GoToDocumentOutline( self, request_data ):
ref_line,
ref[ 'Column' ] ),
line ) )
return goto_locations
if len( goto_locations ) > 1:
return goto_locations
return goto_locations[ 0 ]
else:
raise RuntimeError( 'No symbols found' )

115 changes: 39 additions & 76 deletions ycmd/tests/cs/subcommands_test.py
Original file line number Diff line number Diff line change
@@ -914,83 +914,46 @@ def test_Subcommands_OrganizeImports( self, app ):
@SharedYcmd
def test_Subcommands_GoToDocumentOutline( self, app ):

# we reuse the ImportTest.cs file as it contains a good selection of
# symbols/ symbol types.
filepath = PathToTestFile( 'testy', 'GotoTestCase.cs' )
with WrapOmniSharpServer( app, filepath ):

# the command name and file are the only relevant arguments for this
# subcommand, our current cursor position in the file doesn't matter.
request = BuildRequest( command_arguments = [ 'GoToDocumentOutline' ],
line_num = 11,
column_num = 2,
contents = ReadFile( filepath ),
filetype = 'cs',
filepath = filepath )

response = app.post_json( '/run_completer_command', request ).json

print( 'completer response = ', response )

assert_that( response,
for filepath, expected in [
( PathToTestFile( 'test', 'Empty.cs' ),
ErrorMatcher( RuntimeError, 'No symbols found' ) ),
( PathToTestFile( 'test', 'SingleEntity.cs' ),
LocationMatcher( PathToTestFile( 'testy', 'SingleEntity.cs' ), 6, 8 ) ),
( PathToTestFile( 'test', 'GotoTestCase.cs' ),
has_items(
LocationMatcher(
PathToTestFile( 'testy', 'GotoTestCase.cs' ), 6, 8 ),
LocationMatcher(
PathToTestFile( 'testy', 'GotoTestCase.cs' ), 26, 12 ),
LocationMatcher(
PathToTestFile( 'testy', 'GotoTestCase.cs' ), 30, 8 ),
LocationMatcher(
PathToTestFile( 'testy', 'GotoTestCase.cs' ), 35, 12 ),
LocationMatcher(
PathToTestFile( 'testy', 'GotoTestCase.cs' ), 39, 12 ),
LocationMatcher(
PathToTestFile( 'testy', 'GotoTestCase.cs' ), 43, 8 ),
LocationMatcher(
PathToTestFile( 'testy', 'GotoTestCase.cs' ), 48, 8 ),
LocationMatcher(
PathToTestFile( 'testy', 'GotoTestCase.cs' ), 8, 15 ),
LocationMatcher(
PathToTestFile( 'testy', 'GotoTestCase.cs' ), 13, 15 ),
LocationMatcher(
PathToTestFile( 'testy', 'GotoTestCase.cs' ), 17, 15 ),
LocationMatcher(
PathToTestFile( 'testy', 'GotoTestCase.cs' ), 21, 15 ),
LocationMatcher(
PathToTestFile( 'testy', 'GotoTestCase.cs' ), 27, 8 ),
LocationMatcher(
PathToTestFile( 'testy', 'GotoTestCase.cs' ), 31, 15 ),
LocationMatcher(
PathToTestFile( 'testy', 'GotoTestCase.cs' ), 36, 8 ),
LocationMatcher(
PathToTestFile( 'testy', 'GotoTestCase.cs' ), 40, 8 ),
LocationMatcher(
PathToTestFile( 'testy', 'GotoTestCase.cs' ), 44, 15 ),
LocationMatcher(
PathToTestFile( 'testy', 'GotoTestCase.cs' ), 49, 15 ),
)
LocationMatcher( PathToTestFile( 'testy', 'GotoTestCase.cs' ), 6, 8 ),
LocationMatcher( PathToTestFile( 'testy', 'GotoTestCase.cs' ), 26, 12 ),
LocationMatcher( PathToTestFile( 'testy', 'GotoTestCase.cs' ), 30, 8 ),
LocationMatcher( PathToTestFile( 'testy', 'GotoTestCase.cs' ), 35, 12 ),
LocationMatcher( PathToTestFile( 'testy', 'GotoTestCase.cs' ), 39, 12 ),
LocationMatcher( PathToTestFile( 'testy', 'GotoTestCase.cs' ), 43, 8 ),
LocationMatcher( PathToTestFile( 'testy', 'GotoTestCase.cs' ), 48, 8 ),
LocationMatcher( PathToTestFile( 'testy', 'GotoTestCase.cs' ), 8, 15 ),
LocationMatcher( PathToTestFile( 'testy', 'GotoTestCase.cs' ), 13, 15 ),
LocationMatcher( PathToTestFile( 'testy', 'GotoTestCase.cs' ), 17, 15 ),
LocationMatcher( PathToTestFile( 'testy', 'GotoTestCase.cs' ), 21, 15 ),
LocationMatcher( PathToTestFile( 'testy', 'GotoTestCase.cs' ), 27, 8 ),
LocationMatcher( PathToTestFile( 'testy', 'GotoTestCase.cs' ), 31, 15 ),
LocationMatcher( PathToTestFile( 'testy', 'GotoTestCase.cs' ), 36, 8 ),
LocationMatcher( PathToTestFile( 'testy', 'GotoTestCase.cs' ), 40, 8 ),
LocationMatcher( PathToTestFile( 'testy', 'GotoTestCase.cs' ), 44, 15 ),
LocationMatcher( PathToTestFile( 'testy', 'GotoTestCase.cs' ), 49, 15 ) )
)
]:
with self.subTest( filepath = filepath, expected = expected ):
with WrapOmniSharpServer( app, filepath ):

@SharedYcmd
def test_Subcommands_GoToDocumentOutline_Empty( self, app ):

filepath = PathToTestFile( 'testy', 'Empty.cs' )
with WrapOmniSharpServer( app, filepath ):

# the command name and file are the only relevant arguments for this
# subcommand. our current cursor position in the file doesn't matter.
request = BuildRequest( command_arguments = [ 'GoToDocumentOutline' ],
line_num = 0,
column_num = 0,
contents = ReadFile( filepath ),
filetype = 'cs',
filepath = filepath )

response = app.post_json( '/run_completer_command',
request,
expect_errors = True ).json

print( 'completer response = ', response )
# the command name and file are the only relevant arguments for this
# subcommand. our current cursor position in the file doesn't matter.
request = BuildRequest( command_arguments = [ 'GoToDocumentOutline' ],
line_num = 0,
column_num = 0,
contents = ReadFile( filepath ),
filetype = 'cs',
filepath = filepath )

assert_that( response, ErrorMatcher( RuntimeError,
'No symbols found' ) )
response = app.post_json( '/run_completer_command',
request,
expect_errors = True ).json
print( 'completer response = ', response )
assert_that( response, expected )
9 changes: 9 additions & 0 deletions ycmd/tests/cs/testdata/testy/SingleEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;
using System.Data;

namespace testy
{
class GotoTestCase
{
}
}
1 change: 1 addition & 0 deletions ycmd/tests/cs/testdata/testy/testy.csproj
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ZeroColumnDiagnostic.cs" />
<Compile Include="Empty.cs" />
<Compile Include="SingleEntity.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

0 comments on commit aa6f3a9

Please sign in to comment.