Skip to content

Commit f99c3de

Browse files
committed
update inlay_hint, prevent recursion
1 parent 56ba46a commit f99c3de

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub fn build_closure_hint(
5555
label_parts.push(InlayHintLabelPart {
5656
value: typ_desc,
5757
location: Some(
58-
get_type_location(semantic_model, typ)
58+
get_type_location(semantic_model, typ, 0)
5959
.unwrap_or(Location::new(document.get_uri(), lsp_range)),
6060
),
6161
..Default::default()
@@ -132,13 +132,13 @@ fn get_part(semantic_model: &SemanticModel, typ: &LuaType) -> Option<InlayHintLa
132132
LuaType::Nil => {
133133
return Some(InlayHintLabelPart {
134134
value: "?".to_string(),
135-
location: get_type_location(semantic_model, typ),
135+
location: get_type_location(semantic_model, typ, 0),
136136
..Default::default()
137137
});
138138
}
139139
_ => {
140140
let value = hint_humanize_type(semantic_model, typ, RenderLevel::Simple);
141-
let location = get_type_location(semantic_model, typ);
141+
let location = get_type_location(semantic_model, typ, 0);
142142
return Some(InlayHintLabelPart {
143143
value,
144144
location,
@@ -148,7 +148,14 @@ fn get_part(semantic_model: &SemanticModel, typ: &LuaType) -> Option<InlayHintLa
148148
}
149149
}
150150

151-
fn get_type_location(semantic_model: &SemanticModel, typ: &LuaType) -> Option<Location> {
151+
fn get_type_location(
152+
semantic_model: &SemanticModel,
153+
typ: &LuaType,
154+
depth: usize,
155+
) -> Option<Location> {
156+
if depth > 10 {
157+
return None;
158+
}
152159
match typ {
153160
LuaType::Ref(id) | LuaType::Def(id) => {
154161
let type_decl = semantic_model
@@ -162,9 +169,11 @@ fn get_type_location(semantic_model: &SemanticModel, typ: &LuaType) -> Option<Lo
162169
}
163170
LuaType::Generic(generic) => {
164171
let base_type_id = generic.get_base_type_id();
165-
get_type_location(semantic_model, &LuaType::Ref(base_type_id))
172+
get_type_location(semantic_model, &LuaType::Ref(base_type_id), depth + 1)
173+
}
174+
LuaType::Array(array_type) => {
175+
get_type_location(semantic_model, array_type.get_base(), depth + 1)
166176
}
167-
LuaType::Array(array_type) => get_type_location(semantic_model, array_type.get_base()),
168177
LuaType::Any => get_base_type_location(semantic_model, "any"),
169178
LuaType::Nil => get_base_type_location(semantic_model, "nil"),
170179
LuaType::Unknown => get_base_type_location(semantic_model, "unknown"),

0 commit comments

Comments
 (0)