Skip to content

Commit b89ab49

Browse files
authored
Merge pull request #1623 from mokchira/switch-source-header
Switch source header
2 parents c65849a + 7dfda1c commit b89ab49

File tree

11 files changed

+76
-6
lines changed

11 files changed

+76
-6
lines changed

docs/bundle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5476,6 +5476,20 @@ <h3 class="panel-title"><a name="/definitions/SubcommandResponse"></a>Subcommand
54765476

54775477
</div>
54785478
</dd>
5479+
<dt data-property-name="file_only">
5480+
<span class="json-property-name">file_only:</span>
5481+
5482+
<span class="json-property-type">boolean</span>
5483+
<span class="json-property-range" title="Value limits"></span>
5484+
5485+
</dt>
5486+
<dd>
5487+
<p>If present, the line_num and column_num can be ignored.</p>
5488+
5489+
<div class="json-inner-schema">
5490+
5491+
</div>
5492+
</dd>
54795493
<dt data-property-name="extra_data">
54805494
<span class="json-property-name">extra_data:</span>
54815495

docs/main.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/openapi.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,10 @@ definitions:
372372
$ref: "#/definitions/LineNumber"
373373
column_num:
374374
$ref: "#/definitions/ColumnNumber"
375+
file_only:
376+
type: boolean
377+
description: |-
378+
If present, the line_num and column_num can be ignored.
375379
extra_data:
376380
type: object
377381
description: |-

ycmd/completers/cpp/clangd_completer.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ def GetCustomSubcommands( self ):
301301
'GetDocImprecise': (
302302
lambda self, request_data, args: self.GetDoc( request_data )
303303
),
304+
'GoToAlternateFile': (
305+
lambda self, request_data, args: self.GoToAlternateFile( request_data )
306+
),
304307
# To handle the commands below we need extensions to LSP. One way to
305308
# provide those could be to use workspace/executeCommand requset.
306309
# 'GetParent': (
@@ -309,6 +312,27 @@ def GetCustomSubcommands( self ):
309312
}
310313

311314

315+
def GoToAlternateFile( self, request_data ):
316+
request_id = self.GetConnection().NextRequestId()
317+
uri = lsp.FilePathToUri( request_data[ 'filepath' ] )
318+
request = lsp.BuildRequest( request_id,
319+
"textDocument/switchSourceHeader",
320+
{ "uri": uri } )
321+
response = self.GetConnection().GetResponse(
322+
request_id,
323+
request,
324+
language_server_completer.REQUEST_TIMEOUT_COMMAND )
325+
filepath = lsp.UriToFilePath( response[ 'result' ] )
326+
# We don't have a specific location in the file we need to go to so
327+
# we just arbitrarily choose line 1, column 1. The client can choose
328+
# to ignore them.
329+
return responses.BuildGoToResponse( filepath,
330+
1,
331+
1,
332+
description = filepath,
333+
file_only = True )
334+
335+
312336
def ShouldCompleteIncludeStatement( self, request_data ):
313337
column_codepoint = request_data[ 'column_codepoint' ] - 1
314338
current_line = request_data[ 'line_value' ]

ycmd/responses.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,26 @@ def __init__( self ):
6767

6868

6969
# column_num is a byte offset
70-
def BuildGoToResponse( filepath, line_num, column_num, description = None ):
70+
def BuildGoToResponse( filepath,
71+
line_num,
72+
column_num,
73+
description = None,
74+
file_only = False ):
7175
return BuildGoToResponseFromLocation(
7276
Location( line = line_num,
7377
column = column_num,
7478
filename = filepath ),
75-
description )
79+
description, file_only )
7680

7781

78-
def BuildGoToResponseFromLocation( location, description = None ):
82+
def BuildGoToResponseFromLocation( location,
83+
description = None,
84+
file_only = False ):
7985
"""Build a GoTo response from a responses.Location object."""
8086
response = BuildLocationData( location )
8187
if description:
8288
response[ 'description' ] = description
89+
response[ 'file_only' ] = file_only
8390
return response
8491

8592

ycmd/tests/clang/subcommands_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def RunGoToTest_all( app, filename, command, test ):
5656
}
5757
common_response = {
5858
'filepath': os.path.abspath( PathToTestFile( filename ) ),
59+
'file_only': False,
5960
}
6061

6162
if 'extra_conf' in test:
@@ -103,6 +104,7 @@ def RunGoToIncludeTest( app, command, test ):
103104
'filepath' : PathToTestFile( 'test-include', test[ 'response' ] ),
104105
'line_num' : 1,
105106
'column_num' : 1,
107+
'file_only' : False,
106108
}
107109

108110
actual_response = app.post_json( '/run_completer_command', goto_data ).json

ycmd/tests/clangd/subcommands_test.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,8 @@ def test_Subcommands_DefinedSubcommands( self, app ):
594594
'GoToSymbol',
595595
'GoToType',
596596
'RefactorRename',
597-
'RestartServer' ] ) )
597+
'RestartServer',
598+
'GoToAlternateFile' ] ) )
598599
},
599600
'route': '/defined_subcommands',
600601
} )
@@ -757,6 +758,16 @@ def test_Subcommands_GoToInclude( self, app ):
757758
with self.subTest( test = test, cmd = cmd ):
758759
RunGoToTest_all( app, 'test-include', cmd, test )
759760

761+
@SharedYcmd
762+
def test_Subcommands_GoToAlternateFile( self, app ):
763+
for test in [
764+
{ 'req': ( 'go-to-alternate-file/a.cpp', 1, 1 ),
765+
'res': ( 'go-to-alternate-file/a.h', 1, 1 ) },
766+
{ 'req': ( 'go-to-alternate-file/a.h', 1, 1 ),
767+
'res': ( 'go-to-alternate-file/a.cpp', 1, 1 ) },
768+
]:
769+
with self.subTest( test = test ):
770+
RunGoToTest_all( app, '', 'GoToAlternateFile', test )
760771

761772
@SharedYcmd
762773
def test_Subcommands_GoToReferences( self, app ):
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "a.h"
2+
3+
void foo()
4+
{
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void foo();

0 commit comments

Comments
 (0)