@@ -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' ]
0 commit comments