3333
3434from ycmd import handlers
3535from ycmd .tests .rust import setUpModule , tearDownModule # noqa
36- from ycmd .tests .rust import PathToTestFile , SharedYcmd
36+ from ycmd .tests .rust import ( PathToTestFile ,
37+ SharedYcmd ,
38+ IsolatedYcmd ,
39+ StartRustCompleterServerInDirectory )
3740from ycmd .tests .test_utils import ( BuildRequest ,
3841 ChunkMatcher ,
3942 ErrorMatcher ,
4043 ExpectedFailure ,
4144 LocationMatcher ,
45+ WaitForDiagnosticsToBeReady ,
4246 WithRetry )
4347from ycmd .utils import ReadFile
4448
4751
4852
4953def RunTest ( app , test , contents = None ):
54+ filepath = test [ 'request' ][ 'filepath' ]
5055 if not contents :
51- contents = ReadFile ( test [ 'request' ][ ' filepath' ] )
56+ contents = ReadFile ( filepath )
5257
5358 def CombineRequest ( request , data ):
5459 kw = request
@@ -67,6 +72,10 @@ def CombineRequest( request, data ):
6772 } ),
6873 expect_errors = True )
6974
75+ # rust-analyzer sometimes needs a bit of time after opening a new file.
76+ # Probably to relax after some hard work...
77+ WaitForDiagnosticsToBeReady ( app , filepath , contents , 'rust' )
78+
7079 # We also ignore errors here, but then we check the response code
7180 # ourself. This is to allow testing of requests returning errors.
7281 response = app .post_json (
@@ -88,8 +97,8 @@ def CombineRequest( request, data ):
8897 assert_that ( response .json , test [ 'expect' ][ 'data' ] )
8998
9099
91- def RunGoToTest ( app , command , test ):
92- folder = PathToTestFile ( 'common' , 'src' )
100+ def RunGoToTest ( app , command , test , * , project_root = 'common' ):
101+ folder = PathToTestFile ( project_root , 'src' )
93102 filepath = os .path .join ( folder , test [ 'req' ][ 0 ] )
94103 request = {
95104 'command' : command ,
@@ -531,3 +540,22 @@ def test_Subcommands_FixIt_Basic( self, app ):
531540 } )
532541 },
533542 } )
543+
544+
545+ @IsolatedYcmd ()
546+ def test_Subcommands_GoTo_WorksAfterChangingProject ( self , app ):
547+ filepath = PathToTestFile ( 'macro' , 'src' , 'main.rs' )
548+ StartRustCompleterServerInDirectory ( app , filepath )
549+
550+ for test , root in [
551+ (
552+ { 'req' : ( 'main.rs' , 31 , 24 ), 'res' : ( 'main.rs' , 14 , 9 ) },
553+ 'macro'
554+ ),
555+ (
556+ { 'req' : ( 'main.rs' , 13 , 19 ), 'res' : ( 'test.rs' , 4 , 12 ) },
557+ 'common'
558+ ),
559+ ]:
560+ with self .subTest ( test = test , root = root ):
561+ RunGoToTest ( app , 'GoTo' , test , project_root = root )
0 commit comments