1
1
use std:: collections:: HashMap ;
2
2
3
- use code_analysis:: { LuaFunctionType , LuaSignatureId , LuaType , SemanticModel } ;
3
+ use code_analysis:: { LuaFunctionType , LuaPropertyOwnerId , LuaSignatureId , LuaType , SemanticModel } ;
4
4
use emmylua_parser:: { LuaAst , LuaAstNode , LuaCallExpr , LuaClosureExpr , LuaExpr , LuaLocalName } ;
5
5
use lsp_types:: { InlayHint , InlayHintKind , InlayHintLabel } ;
6
6
use rowan:: NodeOrToken ;
@@ -16,7 +16,8 @@ pub fn build_inlay_hints(semantic_model: &mut SemanticModel) -> Option<Vec<Inlay
16
16
build_closure_hint ( semantic_model, & mut result, closure) ;
17
17
}
18
18
LuaAst :: LuaCallExpr ( call_expr) => {
19
- build_call_expr_hint ( semantic_model, & mut result, call_expr) ;
19
+ build_call_expr_param_hint ( semantic_model, & mut result, call_expr. clone ( ) ) ;
20
+ build_call_expr_await_hint ( semantic_model, & mut result, call_expr) ;
20
21
}
21
22
LuaAst :: LuaLocalName ( local_name) => {
22
23
build_local_name_hint ( semantic_model, & mut result, local_name) ;
@@ -80,7 +81,7 @@ fn build_closure_hint(
80
81
Some ( ( ) )
81
82
}
82
83
83
- fn build_call_expr_hint (
84
+ fn build_call_expr_param_hint (
84
85
semantic_model : & mut SemanticModel ,
85
86
result : & mut Vec < InlayHint > ,
86
87
call_expr : LuaCallExpr ,
@@ -119,6 +120,62 @@ fn build_call_expr_hint(
119
120
Some ( ( ) )
120
121
}
121
122
123
+ fn build_call_expr_await_hint (
124
+ semantic_model : & mut SemanticModel ,
125
+ result : & mut Vec < InlayHint > ,
126
+ call_expr : LuaCallExpr ,
127
+ ) -> Option < ( ) > {
128
+ let prefix_expr = call_expr. get_prefix_expr ( ) ?;
129
+ let semantic_info =
130
+ semantic_model. get_semantic_info ( NodeOrToken :: Node ( prefix_expr. syntax ( ) . clone ( ) ) ) ?;
131
+
132
+ match semantic_info. typ {
133
+ LuaType :: DocFunction ( f) => {
134
+ if f. is_async ( ) {
135
+ let range = call_expr. get_range ( ) ;
136
+ let document = semantic_model. get_document ( ) ;
137
+ let lsp_range = document. to_lsp_range ( range) ?;
138
+ let hint = InlayHint {
139
+ kind : Some ( InlayHintKind :: TYPE ) ,
140
+ label : InlayHintLabel :: String ( "await" . to_string ( ) ) ,
141
+ position : lsp_range. start ,
142
+ text_edits : None ,
143
+ tooltip : None ,
144
+ padding_left : None ,
145
+ padding_right : Some ( true ) ,
146
+ data : None ,
147
+ } ;
148
+ result. push ( hint) ;
149
+ }
150
+ }
151
+ LuaType :: Signature ( signature_id) => {
152
+ let property_owner_id = LuaPropertyOwnerId :: Signature ( signature_id) ;
153
+ let property = semantic_model
154
+ . get_db ( )
155
+ . get_property_index ( )
156
+ . get_property ( property_owner_id) ?;
157
+ if property. is_async {
158
+ let range = call_expr. get_range ( ) ;
159
+ let document = semantic_model. get_document ( ) ;
160
+ let lsp_range = document. to_lsp_range ( range) ?;
161
+ let hint = InlayHint {
162
+ kind : Some ( InlayHintKind :: TYPE ) ,
163
+ label : InlayHintLabel :: String ( "await" . to_string ( ) ) ,
164
+ position : lsp_range. start ,
165
+ text_edits : None ,
166
+ tooltip : None ,
167
+ padding_left : None ,
168
+ padding_right : Some ( true ) ,
169
+ data : None ,
170
+ } ;
171
+ result. push ( hint) ;
172
+ }
173
+ }
174
+ _ => { }
175
+ }
176
+ Some ( ( ) )
177
+ }
178
+
122
179
fn build_call_args_for_func_type (
123
180
semantic_model : & mut SemanticModel ,
124
181
result : & mut Vec < InlayHint > ,
0 commit comments