@@ -2,8 +2,8 @@ use std::collections::HashSet;
2
2
3
3
use emmylua_code_analysis:: { DiagnosticCode , LuaTypeAttribute } ;
4
4
use emmylua_parser:: {
5
- LuaAst , LuaAstNode , LuaClosureExpr , LuaComment , LuaDocAttribute , LuaSyntaxKind , LuaSyntaxToken ,
6
- LuaTokenKind ,
5
+ LuaAst , LuaAstNode , LuaClosureExpr , LuaComment , LuaDocAttribute , LuaDocTag , LuaSyntaxKind ,
6
+ LuaSyntaxToken , LuaTokenKind ,
7
7
} ;
8
8
use lsp_types:: CompletionItem ;
9
9
@@ -29,8 +29,8 @@ pub fn add_completion(builder: &mut CompletionBuilder) -> Option<()> {
29
29
DocCompletionExpected :: DiagnosticCode => {
30
30
add_tag_diagnostic_code_completion ( builder) ;
31
31
}
32
- DocCompletionExpected :: ClassAttr => {
33
- add_tag_class_attr_completion ( builder) ;
32
+ DocCompletionExpected :: ClassAttr ( node ) => {
33
+ add_tag_class_attr_completion ( builder, node ) ;
34
34
}
35
35
DocCompletionExpected :: Namespace => {
36
36
add_tag_namespace_completion ( builder) ;
@@ -84,7 +84,10 @@ fn get_doc_completion_expected(trigger_token: &LuaSyntaxToken) -> Option<DocComp
84
84
LuaSyntaxKind :: DocDiagnosticCodeList => {
85
85
Some ( DocCompletionExpected :: DiagnosticCode )
86
86
}
87
- LuaSyntaxKind :: DocAttribute => Some ( DocCompletionExpected :: ClassAttr ) ,
87
+ LuaSyntaxKind :: DocAttribute => {
88
+ let attr = LuaDocAttribute :: cast ( parent. clone ( ) . into ( ) ) ?;
89
+ Some ( DocCompletionExpected :: ClassAttr ( attr) )
90
+ }
88
91
_ => None ,
89
92
}
90
93
}
@@ -102,28 +105,34 @@ fn get_doc_completion_expected(trigger_token: &LuaSyntaxToken) -> Option<DocComp
102
105
let parent = trigger_token. parent ( ) ?;
103
106
match parent. kind ( ) . into ( ) {
104
107
LuaSyntaxKind :: DocDiagnosticCodeList => Some ( DocCompletionExpected :: DiagnosticCode ) ,
105
- LuaSyntaxKind :: DocAttribute => Some ( DocCompletionExpected :: ClassAttr ) ,
108
+ LuaSyntaxKind :: DocAttribute => {
109
+ let attr = LuaDocAttribute :: cast ( parent. clone ( ) . into ( ) ) ?;
110
+ Some ( DocCompletionExpected :: ClassAttr ( attr) )
111
+ }
106
112
_ => None ,
107
113
}
108
114
}
109
115
LuaTokenKind :: TkLeftParen => {
110
116
let parent = trigger_token. parent ( ) ?;
111
117
match parent. kind ( ) . into ( ) {
112
- LuaSyntaxKind :: DocAttribute => Some ( DocCompletionExpected :: ClassAttr ) ,
118
+ LuaSyntaxKind :: DocAttribute => {
119
+ let attr = LuaDocAttribute :: cast ( parent. clone ( ) . into ( ) ) ?;
120
+ Some ( DocCompletionExpected :: ClassAttr ( attr) )
121
+ }
113
122
_ => None ,
114
123
}
115
124
}
116
125
_ => return None ,
117
126
}
118
127
}
119
128
120
- #[ derive( Debug , Copy , Clone , Eq , PartialEq ) ]
129
+ #[ derive( Debug , Clone , Eq , PartialEq ) ]
121
130
enum DocCompletionExpected {
122
131
ParamName ,
123
132
Cast ,
124
133
DiagnosticAction ,
125
134
DiagnosticCode ,
126
- ClassAttr ,
135
+ ClassAttr ( LuaDocAttribute ) ,
127
136
Namespace ,
128
137
Using ,
129
138
Export ,
@@ -219,42 +228,30 @@ fn add_tag_diagnostic_code_completion(builder: &mut CompletionBuilder) {
219
228
}
220
229
}
221
230
222
- fn add_tag_class_attr_completion ( builder : & mut CompletionBuilder ) {
223
- let attributes = [
224
- ( LuaTypeAttribute :: Partial , "partial" ) ,
225
- ( LuaTypeAttribute :: Key , "key" ) ,
226
- ( LuaTypeAttribute :: Constructor , "constructor" ) ,
227
- ( LuaTypeAttribute :: Exact , "exact" ) ,
228
- ( LuaTypeAttribute :: Meta , "meta" ) ,
229
- ] ;
231
+ fn add_tag_class_attr_completion (
232
+ builder : & mut CompletionBuilder ,
233
+ node : LuaDocAttribute ,
234
+ ) -> Option < ( ) > {
235
+ let mut attributes = vec ! [ ( LuaTypeAttribute :: Partial , "partial" ) ] ;
230
236
231
- // 已存在的属性
232
- let mut existing_attrs = HashSet :: new ( ) ;
233
- match builder. trigger_token . kind ( ) . into ( ) {
234
- LuaTokenKind :: TkLeftParen | LuaTokenKind :: TkComma => {
235
- let parent = builder. trigger_token . parent ( ) . unwrap ( ) ;
236
- let attr = LuaDocAttribute :: cast ( parent) . unwrap ( ) ;
237
- for token in attr. get_attrib_tokens ( ) {
238
- let name_text = token. get_name_text ( ) . to_string ( ) ;
239
- existing_attrs. insert ( name_text) ;
240
- }
237
+ match LuaDocTag :: cast ( node. syntax ( ) . parent ( ) ?) ? {
238
+ LuaDocTag :: Alias ( _) => { }
239
+ LuaDocTag :: Class ( _) => {
240
+ attributes. push ( ( LuaTypeAttribute :: Exact , "exact" ) ) ;
241
+ attributes. push ( ( LuaTypeAttribute :: Constructor , "constructor" ) ) ;
241
242
}
242
- LuaTokenKind :: TkWhitespace => {
243
- let left_token = builder. trigger_token . prev_token ( ) . unwrap ( ) ;
244
- match left_token. kind ( ) . into ( ) {
245
- LuaTokenKind :: TkComma => {
246
- let parent = left_token. parent ( ) . unwrap ( ) ;
247
- let attr = LuaDocAttribute :: cast ( parent) . unwrap ( ) ;
248
- for token in attr. get_attrib_tokens ( ) {
249
- let name_text = token. get_name_text ( ) . to_string ( ) ;
250
- existing_attrs. insert ( name_text) ;
251
- }
252
- }
253
- _ => { }
254
- }
243
+ LuaDocTag :: Enum ( _) => {
244
+ attributes. insert ( 0 , ( LuaTypeAttribute :: Key , "key" ) ) ;
245
+ attributes. push ( ( LuaTypeAttribute :: Exact , "exact" ) ) ;
255
246
}
256
247
_ => { }
257
248
}
249
+ // 已存在的属性
250
+ let mut existing_attrs = HashSet :: new ( ) ;
251
+ for token in node. get_attrib_tokens ( ) {
252
+ let name_text = token. get_name_text ( ) . to_string ( ) ;
253
+ existing_attrs. insert ( name_text) ;
254
+ }
258
255
259
256
for ( _, name) in attributes. iter ( ) {
260
257
if existing_attrs. contains ( * name) {
@@ -267,6 +264,8 @@ fn add_tag_class_attr_completion(builder: &mut CompletionBuilder) {
267
264
} ;
268
265
builder. add_completion_item ( completion_item) ;
269
266
}
267
+
268
+ Some ( ( ) )
270
269
}
271
270
272
271
fn add_tag_namespace_completion ( builder : & mut CompletionBuilder ) {
0 commit comments