diff --git a/ycmd/completers/cs/cs_completer.py b/ycmd/completers/cs/cs_completer.py
index f1061782ed..b023ae45b4 100644
--- a/ycmd/completers/cs/cs_completer.py
+++ b/ycmd/completers/cs/cs_completer.py
@@ -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' )
diff --git a/ycmd/tests/cs/subcommands_test.py b/ycmd/tests/cs/subcommands_test.py
index 5f77f45b0b..0f40c91d4a 100644
--- a/ycmd/tests/cs/subcommands_test.py
+++ b/ycmd/tests/cs/subcommands_test.py
@@ -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 ),
@@ -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 )
diff --git a/ycmd/tests/cs/testdata/testy/SingleEntity.cs b/ycmd/tests/cs/testdata/testy/SingleEntity.cs
new file mode 100644
index 0000000000..594f1a8fea
--- /dev/null
+++ b/ycmd/tests/cs/testdata/testy/SingleEntity.cs
@@ -0,0 +1,9 @@
+using System;
+using System.Data;
+
+namespace testy
+{
+ class GotoTestCase
+ {
+ }
+}
diff --git a/ycmd/tests/cs/testdata/testy/testy.csproj b/ycmd/tests/cs/testdata/testy/testy.csproj
index cdbfbe9f5f..6e2787b5ba 100644
--- a/ycmd/tests/cs/testdata/testy/testy.csproj
+++ b/ycmd/tests/cs/testdata/testy/testy.csproj
@@ -49,6 +49,7 @@
+