Skip to content

Commit 9d67d46

Browse files
committed
Fix #822
1 parent 4628ccf commit 9d67d46

File tree

4 files changed

+56
-7
lines changed

4 files changed

+56
-7
lines changed

crates/emmylua_code_analysis/src/compilation/analyzer/flow/bind_analyze/stats.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use emmylua_parser::{
22
BinaryOperator, LuaAssignStat, LuaAst, LuaAstNode, LuaBlock, LuaBreakStat, LuaCallArgList,
33
LuaCallExprStat, LuaDoStat, LuaExpr, LuaForRangeStat, LuaForStat, LuaFuncStat, LuaGotoStat,
4-
LuaIfStat, LuaLabelStat, LuaLocalStat, LuaRepeatStat, LuaReturnStat, LuaWhileStat,
4+
LuaIfStat, LuaLabelStat, LuaLocalStat, LuaRepeatStat, LuaReturnStat, LuaVarExpr, LuaWhileStat,
55
};
66

77
use crate::{
@@ -366,8 +366,20 @@ pub fn bind_if_stat(binder: &mut FlowBinder, if_stat: LuaIfStat, current: FlowId
366366
}
367367

368368
pub fn bind_func_stat(binder: &mut FlowBinder, func_stat: LuaFuncStat, current: FlowId) -> FlowId {
369-
bind_each_child(binder, LuaAst::LuaFuncStat(func_stat), current);
370-
current
369+
let Some(func_name) = func_stat.get_func_name() else {
370+
return current; // If there's no function name, just return the current flow
371+
};
372+
373+
bind_each_child(binder, LuaAst::LuaFuncStat(func_stat.clone()), current);
374+
let LuaVarExpr::NameExpr(_) = func_name else {
375+
return current; // If the function name is not a simple name, just return the current flow
376+
};
377+
378+
let func_kind = FlowNodeKind::ImplFunc(func_stat.to_ptr());
379+
let flow_id = binder.create_node(func_kind);
380+
binder.add_antecedent(flow_id, current);
381+
382+
flow_id
371383
}
372384

373385
pub fn bind_local_func_stat(

crates/emmylua_code_analysis/src/db_index/flow/flow_node.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use emmylua_parser::{
22
LuaAssignStat, LuaAstNode, LuaAstPtr, LuaChunk, LuaClosureExpr, LuaDocTagCast, LuaExpr,
3-
LuaForStat, LuaSyntaxKind, LuaSyntaxNode,
3+
LuaForStat, LuaFuncStat, LuaSyntaxKind, LuaSyntaxNode,
44
};
55
use internment::ArcIntern;
66
use rowan::{TextRange, TextSize};
@@ -48,6 +48,8 @@ pub enum FlowNodeKind {
4848
TrueCondition(LuaAstPtr<LuaExpr>),
4949
/// Conditional flow (type guards, existence checks)
5050
FalseCondition(LuaAstPtr<LuaExpr>),
51+
/// impl function
52+
ImplFunc(LuaAstPtr<LuaFuncStat>),
5153
/// For loop initialization
5254
ForIStat(LuaAstPtr<LuaForStat>),
5355
/// Tag cast comment

crates/emmylua_code_analysis/src/semantic/infer/narrow/get_type_at_flow.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use emmylua_parser::{LuaAssignStat, LuaAstNode, LuaChunk, LuaVarExpr};
22

33
use crate::{
44
CacheEntry, DbIndex, FlowId, FlowNode, FlowNodeKind, FlowTree, InferFailReason, LuaDeclId,
5-
LuaInferCache, LuaMemberId, LuaType, TypeOps, infer_expr,
5+
LuaInferCache, LuaMemberId, LuaSignatureId, LuaType, TypeOps, infer_expr,
66
semantic::infer::{
77
InferResult, VarRefId,
88
narrow::{
@@ -86,6 +86,32 @@ pub fn get_type_at_flow(
8686
antecedent_flow_id = get_single_antecedent(tree, flow_node)?;
8787
}
8888
}
89+
FlowNodeKind::ImplFunc(func_ptr) => {
90+
let func_stat = func_ptr.to_node(root).ok_or(InferFailReason::None)?;
91+
let Some(func_name) = func_stat.get_func_name() else {
92+
antecedent_flow_id = get_single_antecedent(tree, flow_node)?;
93+
continue;
94+
};
95+
96+
let Some(ref_id) = get_var_expr_var_ref_id(db, cache, func_name.to_expr()) else {
97+
antecedent_flow_id = get_single_antecedent(tree, flow_node)?;
98+
continue;
99+
};
100+
101+
if ref_id == *var_ref_id {
102+
let Some(closure) = func_stat.get_closure() else {
103+
return Err(InferFailReason::None);
104+
};
105+
106+
result_type = LuaType::Signature(LuaSignatureId::from_closure(
107+
cache.get_file_id(),
108+
&closure,
109+
));
110+
break;
111+
} else {
112+
antecedent_flow_id = get_single_antecedent(tree, flow_node)?;
113+
}
114+
}
89115
FlowNodeKind::TrueCondition(condition_ptr) => {
90116
let condition = condition_ptr.to_node(root).ok_or(InferFailReason::None)?;
91117
let result_or_continue = get_type_at_condition_flow(

crates/emmylua_ls/src/handlers/initialized/client_config/default_config.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,19 @@ pub async fn get_client_config_default(
3232
section: Some(scope.to_string()),
3333
}],
3434
};
35+
log::info!("fetching client config for scope {scope:?}");
3536
let cancel_token = time_cancel_token(Duration::from_secs(5));
36-
let fetched_configs: Vec<_> = client
37+
let fetched_configs: Vec<_> = match client
3738
.get_configuration::<Value>(params, cancel_token)
38-
.await?
39+
.await
40+
{
41+
Some(configs) => configs,
42+
None => {
43+
log::warn!("failed to fetch client config for scope {scope:?}");
44+
continue;
45+
}
46+
};
47+
let fetched_configs: Vec<_> = fetched_configs
3948
.into_iter()
4049
.filter(|config| !config.is_null())
4150
.collect();

0 commit comments

Comments
 (0)