1
1
//! This module provides `StaticIndex` which is used for powering
2
2
//! read-only code browsers and emitting LSIF
3
3
4
- use hir:: { db:: HirDatabase , Crate , HirFileIdExt , Module } ;
4
+ use hir:: { db:: HirDatabase , Crate , HirFileIdExt , Module , Semantics } ;
5
5
use ide_db:: {
6
6
base_db:: { FileId , FileRange , SourceDatabaseExt } ,
7
7
defs:: Definition ,
8
+ documentation:: Documentation ,
9
+ famous_defs:: FamousDefs ,
8
10
helpers:: get_definition,
9
11
FxHashMap , FxHashSet , RootDatabase ,
10
12
} ;
11
- use syntax:: { AstNode , SyntaxKind :: * , TextRange , T } ;
13
+ use syntax:: { AstNode , SyntaxKind :: * , SyntaxNode , TextRange , T } ;
12
14
13
15
use crate :: inlay_hints:: InlayFieldsToResolve ;
14
16
use crate :: navigation_target:: UpmappingResult ;
@@ -22,7 +24,7 @@ use crate::{
22
24
23
25
/// A static representation of fully analyzed source code.
24
26
///
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.
26
28
#[ derive( Debug ) ]
27
29
pub struct StaticIndex < ' a > {
28
30
pub files : Vec < StaticIndexedFile > ,
@@ -40,6 +42,7 @@ pub struct ReferenceData {
40
42
41
43
#[ derive( Debug ) ]
42
44
pub struct TokenStaticData {
45
+ pub documentation : Option < Documentation > ,
43
46
pub hover : Option < HoverResult > ,
44
47
pub definition : Option < FileRange > ,
45
48
pub references : Vec < ReferenceData > ,
@@ -103,6 +106,19 @@ fn all_modules(db: &dyn HirDatabase) -> Vec<Module> {
103
106
modules
104
107
}
105
108
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
+
106
122
impl StaticIndex < ' _ > {
107
123
fn add_file ( & mut self , file_id : FileId ) {
108
124
let current_crate = crates_for ( self . db , file_id) . pop ( ) . map ( Into :: into) ;
@@ -169,6 +185,7 @@ impl StaticIndex<'_> {
169
185
* it
170
186
} else {
171
187
let it = self . tokens . insert ( TokenStaticData {
188
+ documentation : documentation_for_definition ( & sema, def, & node) ,
172
189
hover : hover_for_definition ( & sema, file_id, def, & node, & hover_config) ,
173
190
definition : def. try_to_nav ( self . db ) . map ( UpmappingResult :: call_site) . map ( |it| {
174
191
FileRange { file_id : it. file_id , range : it. focus_or_full_range ( ) }
0 commit comments