Skip to content

Commit

Permalink
Merge pull request #1724 from bstaletic/cs-consistency
Browse files Browse the repository at this point in the history
[READY] Make C# completer consistent with other completers regarding GoToDocumentOutline
  • Loading branch information
mergify[bot] authored Jan 4, 2024
2 parents d73494d + cb16efa commit b34008a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 45 deletions.
4 changes: 3 additions & 1 deletion ycmd/completers/cs/cs_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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' )

Expand Down
68 changes: 24 additions & 44 deletions ycmd/tests/cs/subcommands_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,25 +914,13 @@ 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( 'testy', 'Empty.cs' ),
ErrorMatcher( RuntimeError, 'No symbols found' ) ),
( PathToTestFile( 'testy', 'SingleEntity.cs' ),
LocationMatcher(
PathToTestFile( 'testy', 'SingleEntity.cs' ), 6, 8 ) ),
( PathToTestFile( 'testy', 'GotoTestCase.cs' ),
has_items(
LocationMatcher(
PathToTestFile( 'testy', 'GotoTestCase.cs' ), 6, 8 ),
Expand Down Expand Up @@ -967,30 +955,22 @@ def test_Subcommands_GoToDocumentOutline( self, app ):
LocationMatcher(
PathToTestFile( 'testy', 'GotoTestCase.cs' ), 44, 15 ),
LocationMatcher(
PathToTestFile( 'testy', 'GotoTestCase.cs' ), 49, 15 ),
)
)

@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
PathToTestFile( 'testy', 'GotoTestCase.cs' ), 49, 15 ) ) )
]:
with self.subTest( filepath = filepath, expected = expected ):
with WrapOmniSharpServer( app, filepath ):

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
Expand Up @@ -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 b34008a

Please sign in to comment.