Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[READY] Make C# completer consistent with other completers regarding GoToDocumentOutline #1724

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>