1
1
use std:: collections:: HashSet ;
2
2
3
3
use emmylua_parser:: {
4
- LuaAst , LuaAstNode , LuaElseIfClauseStat , LuaForRangeStat , LuaForStat , LuaIfStat , LuaIndexExpr ,
5
- LuaIndexKey , LuaRepeatStat , LuaSyntaxKind , LuaTokenKind , LuaVarExpr , LuaWhileStat ,
4
+ LuaAst , LuaAstNode , LuaCallExpr , LuaElseIfClauseStat , LuaForRangeStat , LuaForStat , LuaIfStat ,
5
+ LuaIndexExpr , LuaIndexKey , LuaRepeatStat , LuaSyntaxKind , LuaTokenKind , LuaVarExpr ,
6
+ LuaWhileStat ,
6
7
} ;
7
8
8
9
use crate :: {
@@ -509,6 +510,13 @@ fn check_require_table_const_with_export<'a>(
509
510
) -> Option < & ' a ModuleInfo > {
510
511
// 获取前缀表达式的语义信息
511
512
let prefix_expr = index_expr. get_prefix_expr ( ) ?;
513
+ if let Some ( call_expr) = LuaCallExpr :: cast ( prefix_expr. syntax ( ) . clone ( ) ) {
514
+ let module_info = parse_require_expr_module_info ( semantic_model, & call_expr) ?;
515
+ if module_info. is_export ( semantic_model. get_db ( ) ) {
516
+ return Some ( module_info) ;
517
+ }
518
+ }
519
+
512
520
let semantic_info = semantic_model. get_semantic_info ( prefix_expr. syntax ( ) . clone ( ) . into ( ) ) ?;
513
521
514
522
// 检查是否是声明引用
@@ -529,3 +537,23 @@ fn check_require_table_const_with_export<'a>(
529
537
}
530
538
None
531
539
}
540
+
541
+ pub fn parse_require_expr_module_info < ' a > (
542
+ semantic_model : & ' a SemanticModel ,
543
+ call_expr : & LuaCallExpr ,
544
+ ) -> Option < & ' a ModuleInfo > {
545
+ let arg_list = call_expr. get_args_list ( ) ?;
546
+ let first_arg = arg_list. get_args ( ) . next ( ) ?;
547
+ let require_path_type = semantic_model. infer_expr ( first_arg. clone ( ) ) . ok ( ) ?;
548
+ let module_path: String = match & require_path_type {
549
+ LuaType :: StringConst ( module_path) => module_path. as_ref ( ) . to_string ( ) ,
550
+ _ => {
551
+ return None ;
552
+ }
553
+ } ;
554
+
555
+ semantic_model
556
+ . get_db ( )
557
+ . get_module_index ( )
558
+ . find_module ( & module_path)
559
+ }
0 commit comments