Skip to content

Commit f816417

Browse files
committed
add await hint
1 parent a6b9294 commit f816417

File tree

1 file changed

+60
-3
lines changed

1 file changed

+60
-3
lines changed

crates/emmylua_ls/src/handlers/inlay_hint/build_inlay_hint.rs

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::collections::HashMap;
22

3-
use code_analysis::{LuaFunctionType, LuaSignatureId, LuaType, SemanticModel};
3+
use code_analysis::{LuaFunctionType, LuaPropertyOwnerId, LuaSignatureId, LuaType, SemanticModel};
44
use emmylua_parser::{LuaAst, LuaAstNode, LuaCallExpr, LuaClosureExpr, LuaExpr, LuaLocalName};
55
use lsp_types::{InlayHint, InlayHintKind, InlayHintLabel};
66
use rowan::NodeOrToken;
@@ -16,7 +16,8 @@ pub fn build_inlay_hints(semantic_model: &mut SemanticModel) -> Option<Vec<Inlay
1616
build_closure_hint(semantic_model, &mut result, closure);
1717
}
1818
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);
2021
}
2122
LuaAst::LuaLocalName(local_name) => {
2223
build_local_name_hint(semantic_model, &mut result, local_name);
@@ -80,7 +81,7 @@ fn build_closure_hint(
8081
Some(())
8182
}
8283

83-
fn build_call_expr_hint(
84+
fn build_call_expr_param_hint(
8485
semantic_model: &mut SemanticModel,
8586
result: &mut Vec<InlayHint>,
8687
call_expr: LuaCallExpr,
@@ -119,6 +120,62 @@ fn build_call_expr_hint(
119120
Some(())
120121
}
121122

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+
122179
fn build_call_args_for_func_type(
123180
semantic_model: &mut SemanticModel,
124181
result: &mut Vec<InlayHint>,

0 commit comments

Comments
 (0)