16
16
*/
17
17
18
18
use lsp_types:: CompletionItem ;
19
- use lsp_types:: CompletionItemKind ;
20
19
use lsp_types:: Documentation ;
21
20
use lsp_types:: MarkupContent ;
22
21
use lsp_types:: MarkupKind ;
23
- use starlark:: codemap:: FileSpan ;
24
22
use starlark:: collections:: SmallMap ;
25
23
use starlark:: docs:: markdown:: render_doc_item;
26
24
use starlark:: docs:: DocItem ;
27
25
use starlark:: syntax:: AstModule ;
28
26
use starlark_syntax:: syntax:: ast:: AstAssignIdent ;
29
- use starlark_syntax:: syntax:: ast:: Expr ;
30
27
use starlark_syntax:: syntax:: ast:: Stmt ;
31
28
use starlark_syntax:: syntax:: module:: AstModuleFields ;
32
29
use starlark_syntax:: syntax:: top_level_stmts:: top_level_stmts;
33
30
34
31
use crate :: docs:: get_doc_item_for_assign;
35
32
use crate :: docs:: get_doc_item_for_def;
36
-
37
- /// The type of an exported symbol.
38
- /// If unknown, will use `Any`.
39
- #[ derive( Debug , PartialEq , Eq , Clone , Hash ) ]
40
- pub ( crate ) enum SymbolKind {
41
- /// Any kind of symbol.
42
- Any ,
43
- /// The symbol represents something that can be called, for example
44
- /// a `def` or a variable assigned to a `lambda`.
45
- Function { argument_names : Vec < String > } ,
46
- }
47
-
48
- impl SymbolKind {
49
- pub ( crate ) fn from_expr ( x : & Expr ) -> Self {
50
- match x {
51
- Expr :: Lambda ( lambda) => Self :: Function {
52
- argument_names : lambda
53
- . params
54
- . iter ( )
55
- . filter_map ( |param| param. split ( ) . 0 . map ( |name| name. to_string ( ) ) )
56
- . collect ( ) ,
57
- } ,
58
- _ => Self :: Any ,
59
- }
60
- }
61
- }
62
-
63
- impl From < SymbolKind > for CompletionItemKind {
64
- fn from ( value : SymbolKind ) -> Self {
65
- match value {
66
- SymbolKind :: Any => CompletionItemKind :: CONSTANT ,
67
- SymbolKind :: Function { .. } => CompletionItemKind :: FUNCTION ,
68
- }
69
- }
70
- }
71
-
72
- /// A symbol. Returned from [`AstModule::exported_symbols`].
73
- #[ derive( Debug , PartialEq , Clone ) ]
74
- pub ( crate ) struct Symbol {
75
- /// The name of the symbol.
76
- pub ( crate ) name : String ,
77
- /// The location of its definition.
78
- pub ( crate ) span : FileSpan ,
79
- /// The type of symbol it represents.
80
- pub ( crate ) kind : SymbolKind ,
81
- /// The documentation for this symbol.
82
- pub ( crate ) docs : Option < DocItem > ,
83
- }
33
+ use crate :: symbols:: Symbol ;
34
+ use crate :: symbols:: SymbolKind ;
84
35
85
36
impl From < Symbol > for CompletionItem {
86
37
fn from ( value : Symbol ) -> Self {
87
- let documentation = value. docs . map ( |docs | {
38
+ let documentation = value. doc . map ( |doc | {
88
39
Documentation :: MarkupContent ( MarkupContent {
89
40
kind : MarkupKind :: Markdown ,
90
- value : render_doc_item ( & value. name , & docs ) ,
41
+ value : render_doc_item ( & value. name , & doc ) ,
91
42
} )
92
43
} ) ;
93
44
Self {
@@ -121,9 +72,11 @@ impl AstModuleExportedSymbols for AstModule {
121
72
if !name. ident . starts_with ( '_' ) {
122
73
result. entry ( & name. ident ) . or_insert ( Symbol {
123
74
name : name. ident . clone ( ) ,
124
- span : me. file_span ( name. span ) ,
75
+ detail : None ,
76
+ span : name. span ,
125
77
kind,
126
- docs : resolve_docs ( ) ,
78
+ doc : resolve_docs ( ) ,
79
+ param : None ,
127
80
} ) ;
128
81
}
129
82
}
@@ -143,7 +96,7 @@ impl AstModuleExportedSymbols for AstModule {
143
96
}
144
97
Stmt :: AssignModify ( dest, _, _) => {
145
98
dest. visit_lvalue ( |name| {
146
- add ( self , & mut result, name, SymbolKind :: Any , || {
99
+ add ( self , & mut result, name, SymbolKind :: Variable , || {
147
100
last_node
148
101
. and_then ( |last| get_doc_item_for_assign ( last, dest) )
149
102
. map ( DocItem :: Property )
@@ -155,7 +108,7 @@ impl AstModuleExportedSymbols for AstModule {
155
108
self ,
156
109
& mut result,
157
110
& def. name ,
158
- SymbolKind :: Function {
111
+ SymbolKind :: Method {
159
112
argument_names : def
160
113
. params
161
114
. iter ( )
@@ -197,7 +150,7 @@ d = 2
197
150
) ;
198
151
let res = modu. exported_symbols ( ) ;
199
152
assert_eq ! (
200
- res. map( |symbol| format!( "{} {}" , symbol. span, symbol. name) ) ,
153
+ res. map( |symbol| format!( "{} {}" , modu . file_span ( symbol. span) , symbol. name) ) ,
201
154
& [ "X:3:5-6 b" , "X:4:1-2 d" ]
202
155
) ;
203
156
}
0 commit comments