@@ -128,4 +128,52 @@ print(foo)
128128 }
129129 ) ;
130130 }
131+
132+ #[ test]
133+ fn test_goto_definition_comment_section ( ) {
134+ // Reset the indexer on exit
135+ let _guard = indexer:: IndexerGuard ;
136+
137+ let code = r#"
138+ # foo ----
139+ foo <- 1
140+ print(foo)
141+ "# ;
142+ let doc = Document :: new ( code, None ) ;
143+ let path = PathBuf :: from ( "/foo/section_test.R" ) ;
144+ indexer:: update ( & doc, & path) . unwrap ( ) ;
145+
146+ let params = lsp_types:: GotoDefinitionParams {
147+ text_document_position_params : lsp_types:: TextDocumentPositionParams {
148+ text_document : lsp_types:: TextDocumentIdentifier {
149+ uri : lsp_types:: Url :: from_file_path ( & path) . unwrap ( ) ,
150+ } ,
151+ position : lsp_types:: Position :: new ( 3 , 7 ) ,
152+ } ,
153+ work_done_progress_params : Default :: default ( ) ,
154+ partial_result_params : Default :: default ( ) ,
155+ } ;
156+
157+ assert_matches ! (
158+ goto_definition( & doc, params) . unwrap( ) ,
159+ Some ( lsp_types:: GotoDefinitionResponse :: Link ( ref links) ) => {
160+ assert!( !links. is_empty( ) ) ;
161+
162+ let link = & links[ 0 ] ;
163+ assert_eq!(
164+ link. target_uri,
165+ lsp_types:: Url :: from_file_path( & path) . unwrap( )
166+ ) ;
167+
168+ // The section should is not the target, the variable has priority
169+ assert_eq!(
170+ links[ 0 ] . target_range,
171+ lsp_types:: Range {
172+ start: lsp_types:: Position :: new( 2 , 0 ) ,
173+ end: lsp_types:: Position :: new( 2 , 3 ) ,
174+ }
175+ ) ;
176+ }
177+ ) ;
178+ }
131179}
0 commit comments