Skip to content

Commit 5ba30b3

Browse files
mibu138mergify[bot]
authored andcommitted
Updated BuildGoToResponse to take an optional fourth parameter, file_only,
which indicates whether or not the client only needs to go to the file and can ignore the line and column number. Modified the SwitchSourceHeader call to specify True for that. Currently is the only command for the clangd completer that makes use of it. Also added SwitchSourceHeader item to the list in subcommands test for clangd.
1 parent 743b6f3 commit 5ba30b3

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

ycmd/completers/cpp/clangd_completer.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,14 @@ def SwitchSourceHeader( self, request_data ):
316316
uri = lsp.FilePathToUri( request_data[ 'filepath' ] )
317317
request = lsp.BuildRequest( request_id, "textDocument/switchSourceHeader",
318318
{ "uri": uri } )
319-
response = self.GetConnection().GetResponse( request_id, request, 30 )
319+
response = self.GetConnection().GetResponse( request_id, request,
320+
language_server_completer.REQUEST_TIMEOUT_COMMAND )
320321
filepath = lsp.UriToFilePath( response[ 'result' ] )
321-
return responses.BuildGoToResponse( filepath, 1, 1, "switch" )
322+
# We don't have a specific location in the file we need to go to so
323+
# we just arbitrarily choose line 1, column 1. The client can choose
324+
# to ignore them.
325+
return responses.BuildGoToResponse( filepath, 1, 1, description = filepath,
326+
file_only = True )
322327

323328

324329
def ShouldCompleteIncludeStatement( self, request_data ):

ycmd/responses.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,22 @@ 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, line_num, column_num, description = None,
71+
file_only = False ):
7172
return BuildGoToResponseFromLocation(
7273
Location( line = line_num,
7374
column = column_num,
7475
filename = filepath ),
75-
description )
76+
description, file_only )
7677

7778

78-
def BuildGoToResponseFromLocation( location, description = None ):
79+
def BuildGoToResponseFromLocation( location, description = None,
80+
file_only = False ):
7981
"""Build a GoTo response from a responses.Location object."""
8082
response = BuildLocationData( location )
8183
if description:
8284
response[ 'description' ] = description
85+
response[ 'file_only' ] = file_only
8386
return response
8487

8588

ycmd/tests/clangd/subcommands_test.py

Lines changed: 2 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+
'SwitchSourceHeader' ] ) )
598599
},
599600
'route': '/defined_subcommands',
600601
} )

0 commit comments

Comments
 (0)