11//! This module provides `StaticIndex` which is used for powering
22//! read-only code browsers and emitting LSIF
33
4- use hir:: { db:: HirDatabase , Crate , HirFileIdExt , Module } ;
4+ use hir:: { db:: HirDatabase , Crate , HirFileIdExt , Module , Semantics } ;
55use ide_db:: {
66 base_db:: { FileId , FileRange , SourceDatabaseExt } ,
77 defs:: Definition ,
8+ documentation:: Documentation ,
9+ famous_defs:: FamousDefs ,
810 helpers:: get_definition,
911 FxHashMap , FxHashSet , RootDatabase ,
1012} ;
11- use syntax:: { AstNode , SyntaxKind :: * , TextRange , T } ;
13+ use syntax:: { AstNode , SyntaxKind :: * , SyntaxNode , TextRange , T } ;
1214
1315use crate :: inlay_hints:: InlayFieldsToResolve ;
1416use crate :: navigation_target:: UpmappingResult ;
@@ -22,7 +24,7 @@ use crate::{
2224
2325/// A static representation of fully analyzed source code.
2426///
25- /// The intended use-case is powering read-only code browsers and emitting LSIF
27+ /// The intended use-case is powering read-only code browsers and emitting LSIF/SCIP.
2628#[ derive( Debug ) ]
2729pub struct StaticIndex < ' a > {
2830 pub files : Vec < StaticIndexedFile > ,
@@ -40,6 +42,7 @@ pub struct ReferenceData {
4042
4143#[ derive( Debug ) ]
4244pub struct TokenStaticData {
45+ pub documentation : Option < Documentation > ,
4346 pub hover : Option < HoverResult > ,
4447 pub definition : Option < FileRange > ,
4548 pub references : Vec < ReferenceData > ,
@@ -103,6 +106,19 @@ fn all_modules(db: &dyn HirDatabase) -> Vec<Module> {
103106 modules
104107}
105108
109+ fn documentation_for_definition (
110+ sema : & Semantics < ' _ , RootDatabase > ,
111+ def : Definition ,
112+ scope_node : & SyntaxNode ,
113+ ) -> Option < Documentation > {
114+ let famous_defs = match & def {
115+ Definition :: BuiltinType ( _) => Some ( FamousDefs ( sema, sema. scope ( scope_node) ?. krate ( ) ) ) ,
116+ _ => None ,
117+ } ;
118+
119+ def. docs ( sema. db , famous_defs. as_ref ( ) )
120+ }
121+
106122impl StaticIndex < ' _ > {
107123 fn add_file ( & mut self , file_id : FileId ) {
108124 let current_crate = crates_for ( self . db , file_id) . pop ( ) . map ( Into :: into) ;
@@ -169,6 +185,7 @@ impl StaticIndex<'_> {
169185 * it
170186 } else {
171187 let it = self . tokens . insert ( TokenStaticData {
188+ documentation : documentation_for_definition ( & sema, def, & node) ,
172189 hover : hover_for_definition ( & sema, file_id, def, & node, & hover_config) ,
173190 definition : def. try_to_nav ( self . db ) . map ( UpmappingResult :: call_site) . map ( |it| {
174191 FileRange { file_id : it. file_id , range : it. focus_or_full_range ( ) }
0 commit comments