@@ -189,6 +189,13 @@ impl flags::Scip {
189189 symbol_roles |= scip_types:: SymbolRole :: Definition as i32 ;
190190 }
191191
192+ let enclosing_range = match token. definition_body {
193+ Some ( def_body) if def_body. file_id == file_id => {
194+ text_range_to_scip_range ( & line_index, def_body. range )
195+ }
196+ _ => Vec :: new ( ) ,
197+ } ;
198+
192199 occurrences. push ( scip_types:: Occurrence {
193200 range : text_range_to_scip_range ( & line_index, text_range) ,
194201 symbol,
@@ -197,7 +204,7 @@ impl flags::Scip {
197204 syntax_kind : Default :: default ( ) ,
198205 diagnostics : Vec :: new ( ) ,
199206 special_fields : Default :: default ( ) ,
200- enclosing_range : Vec :: new ( ) ,
207+ enclosing_range,
201208 } ) ;
202209 }
203210
@@ -508,6 +515,7 @@ fn moniker_descriptors(identifier: &MonikerIdentifier) -> Vec<scip_types::Descri
508515#[ cfg( test) ]
509516mod test {
510517 use super :: * ;
518+ use hir:: FileRangeWrapper ;
511519 use ide:: { FilePosition , TextSize } ;
512520 use test_fixture:: ChangeFixture ;
513521 use vfs:: VfsPath ;
@@ -887,4 +895,32 @@ pub mod example_mod {
887895
888896 assert_eq ! ( token. documentation. as_ref( ) . map( |d| d. as_str( ) ) , Some ( "foo" ) ) ;
889897 }
898+
899+ #[ test]
900+ fn function_has_enclosing_range ( ) {
901+ let s = "fn foo() {}" ;
902+
903+ let mut host = AnalysisHost :: default ( ) ;
904+ let change_fixture = ChangeFixture :: parse ( host. raw_database ( ) , s) ;
905+ host. raw_database_mut ( ) . apply_change ( change_fixture. change ) ;
906+
907+ let analysis = host. analysis ( ) ;
908+ let si = StaticIndex :: compute (
909+ & analysis,
910+ VendoredLibrariesConfig :: Included {
911+ workspace_root : & VfsPath :: new_virtual_path ( "/workspace" . to_owned ( ) ) ,
912+ } ,
913+ ) ;
914+
915+ let file = si. files . first ( ) . unwrap ( ) ;
916+ let ( _, token_id) = file. tokens . get ( 1 ) . unwrap ( ) ; // first token is file module, second is `foo`
917+ let token = si. tokens . get ( * token_id) . unwrap ( ) ;
918+
919+ let expected_range = FileRangeWrapper {
920+ file_id : FileId :: from_raw ( 0 ) ,
921+ range : TextRange :: new ( 0 . into ( ) , 11 . into ( ) ) ,
922+ } ;
923+
924+ assert_eq ! ( token. definition_body, Some ( expected_range) ) ;
925+ }
890926}
0 commit comments