@@ -10,7 +10,6 @@ use tower_lsp::lsp_types::GotoDefinitionParams;
1010use tower_lsp:: lsp_types:: GotoDefinitionResponse ;
1111use tower_lsp:: lsp_types:: LocationLink ;
1212use tower_lsp:: lsp_types:: Range ;
13- use tower_lsp:: lsp_types:: Url ;
1413
1514use crate :: lsp:: documents:: Document ;
1615use crate :: lsp:: encoding:: convert_point_to_position;
@@ -46,19 +45,16 @@ pub fn goto_definition<'a>(
4645 if node. is_identifier ( ) {
4746 let symbol = document. contents . node_slice ( & node) ?. to_string ( ) ;
4847
48+ // First search in current file, then in all files
4949 let uri = & params. text_document_position_params . text_document . uri ;
50- let info = if let Ok ( preferred_path) = uri. to_file_path ( ) {
51- // First search in current file, then in all files
52- indexer:: find_in_file ( symbol. as_str ( ) , & preferred_path)
53- . or_else ( || indexer:: find ( symbol. as_str ( ) ) )
54- } else {
55- indexer:: find ( symbol. as_str ( ) )
56- } ;
50+ let info =
51+ indexer:: find_in_file ( symbol. as_str ( ) , uri) . or_else ( || indexer:: find ( symbol. as_str ( ) ) ) ;
5752
58- if let Some ( ( path, entry) ) = info {
53+ if let Some ( ( file_id, entry) ) = info {
54+ let target_uri = file_id. as_uri ( ) . clone ( ) ;
5955 let link = LocationLink {
6056 origin_selection_range : None ,
61- target_uri : Url :: from_file_path ( path ) . unwrap ( ) ,
57+ target_uri,
6258 target_range : entry. range ,
6359 target_selection_range : entry. range ,
6460 } ;
@@ -105,9 +101,9 @@ foo <- 42
105101print(foo)
106102"# ;
107103 let doc = Document :: new ( code, None ) ;
108- let ( path , uri) = test_path ( "test.R" ) ;
104+ let uri = test_path ( "test.R" ) ;
109105
110- indexer:: update ( & doc, & path ) . unwrap ( ) ;
106+ indexer:: update ( & doc, & uri ) . unwrap ( ) ;
111107
112108 let params = GotoDefinitionParams {
113109 text_document_position_params : lsp_types:: TextDocumentPositionParams {
@@ -142,9 +138,9 @@ foo <- 1
142138print(foo)
143139"# ;
144140 let doc = Document :: new ( code, None ) ;
145- let ( path , uri) = test_path ( "test.R" ) ;
141+ let uri = test_path ( "test.R" ) ;
146142
147- indexer:: update ( & doc, & path ) . unwrap ( ) ;
143+ indexer:: update ( & doc, & uri ) . unwrap ( ) ;
148144
149145 let params = lsp_types:: GotoDefinitionParams {
150146 text_document_position_params : lsp_types:: TextDocumentPositionParams {
@@ -187,11 +183,11 @@ foo
187183 let doc1 = Document :: new ( code1, None ) ;
188184 let doc2 = Document :: new ( code2, None ) ;
189185
190- let ( path1 , uri1) = test_path ( "file1.R" ) ;
191- let ( path2 , uri2) = test_path ( "file2.R" ) ;
186+ let uri1 = test_path ( "file1.R" ) ;
187+ let uri2 = test_path ( "file2.R" ) ;
192188
193- indexer:: update ( & doc1, & path1 ) . unwrap ( ) ;
194- indexer:: update ( & doc2, & path2 ) . unwrap ( ) ;
189+ indexer:: update ( & doc1, & uri1 ) . unwrap ( ) ;
190+ indexer:: update ( & doc2, & uri2 ) . unwrap ( ) ;
195191
196192 // Go to definition for foo in file1
197193 let params1 = GotoDefinitionParams {
@@ -244,11 +240,11 @@ foo
244240 let doc2 = Document :: new ( code2, None ) ;
245241
246242 // Use test_path for cross-platform compatibility
247- let ( path1 , uri1) = crate :: lsp :: util :: test_path ( "file1.R" ) ;
248- let ( path2 , uri2) = crate :: lsp :: util :: test_path ( "file2.R" ) ;
243+ let uri1 = test_path ( "file1.R" ) ;
244+ let uri2 = test_path ( "file2.R" ) ;
249245
250- indexer:: update ( & doc1, & path1 ) . unwrap ( ) ;
251- indexer:: update ( & doc2, & path2 ) . unwrap ( ) ;
246+ indexer:: update ( & doc1, & uri1 ) . unwrap ( ) ;
247+ indexer:: update ( & doc2, & uri2 ) . unwrap ( ) ;
252248
253249 // Go to definition for foo in file2 (should jump to file1)
254250 let params2 = GotoDefinitionParams {
0 commit comments