11use std:: collections:: HashSet ;
22
33use emmylua_parser:: {
4- LuaAst , LuaAstNode , LuaCallExpr , LuaElseIfClauseStat , LuaForRangeStat , LuaForStat , LuaIfStat ,
5- LuaIndexExpr , LuaIndexKey , LuaRepeatStat , LuaSyntaxKind , LuaTokenKind , LuaVarExpr ,
6- LuaWhileStat ,
4+ LuaAst , LuaAstNode , LuaElseIfClauseStat , LuaForRangeStat , LuaForStat , LuaIfStat , LuaIndexExpr ,
5+ LuaIndexKey , LuaRepeatStat , LuaSyntaxKind , LuaTokenKind , LuaVarExpr , LuaWhileStat ,
76} ;
87
98use crate :: {
109 DiagnosticCode , InferFailReason , LuaMemberKey , LuaSemanticDeclId , LuaType , ModuleInfo ,
11- SemanticModel , enum_variable_is_param, parse_require_module_info ,
10+ SemanticModel , enum_variable_is_param,
1211} ;
1312
1413use super :: { Checker , DiagnosticContext , humanize_lint_type} ;
@@ -64,18 +63,19 @@ fn check_index_expr(
6463 let prefix_typ = semantic_model
6564 . infer_expr ( index_expr. get_prefix_expr ( ) ?)
6665 . unwrap_or ( LuaType :: Unknown ) ;
67- let mut module_info = None ;
66+ // let mut module_info = None;
6867
6968 if is_invalid_prefix_type ( & prefix_typ) {
70- if matches ! ( prefix_typ, LuaType :: TableConst ( _) ) {
71- // 如果导入了被 @export 标记的表常量, 那么不应该跳过检查
72- module_info = check_require_table_const_with_export ( semantic_model, index_expr) ;
73- if module_info. is_none ( ) {
74- return Some ( ( ) ) ;
75- }
76- } else {
77- return Some ( ( ) ) ;
78- }
69+ // if matches!(prefix_typ, LuaType::TableConst(_)) {
70+ // // 如果导入了被 @export 标记的表常量, 那么不应该跳过检查
71+ // module_info = check_require_table_const_with_export(semantic_model, index_expr);
72+ // if module_info.is_none() {
73+ // return Some(());
74+ // }
75+ // } else {
76+
77+ // }
78+ return Some ( ( ) ) ;
7979 }
8080
8181 let index_key = index_expr. get_index_key ( ) ?;
@@ -86,7 +86,7 @@ fn check_index_expr(
8686 index_expr,
8787 & index_key,
8888 code,
89- module_info ,
89+ None ,
9090 )
9191 . is_some ( )
9292 {
@@ -479,57 +479,57 @@ fn check_enum_is_param(
479479 )
480480}
481481
482- /// 检查导入的表常量
483- fn check_require_table_const_with_export < ' a > (
484- semantic_model : & ' a SemanticModel ,
485- index_expr : & LuaIndexExpr ,
486- ) -> Option < & ' a ModuleInfo > {
487- // 获取前缀表达式的语义信息
488- let prefix_expr = index_expr. get_prefix_expr ( ) ?;
489- if let Some ( call_expr) = LuaCallExpr :: cast ( prefix_expr. syntax ( ) . clone ( ) ) {
490- let module_info = parse_require_expr_module_info ( semantic_model, & call_expr) ?;
491- if module_info. is_export ( semantic_model. get_db ( ) ) {
492- return Some ( module_info) ;
493- }
494- }
495-
496- let semantic_info = semantic_model. get_semantic_info ( prefix_expr. syntax ( ) . clone ( ) . into ( ) ) ?;
497-
498- // 检查是否是声明引用
499- let decl_id = match semantic_info. semantic_decl ? {
500- LuaSemanticDeclId :: LuaDecl ( decl_id) => decl_id,
501- _ => return None ,
502- } ;
503-
504- // 获取声明
505- let decl = semantic_model
506- . get_db ( )
507- . get_decl_index ( )
508- . get_decl ( & decl_id) ?;
509-
510- let module_info = parse_require_module_info ( semantic_model, decl) ?;
511- if module_info. is_export ( semantic_model. get_db ( ) ) {
512- return Some ( module_info) ;
513- }
514- None
515- }
516-
517- pub fn parse_require_expr_module_info < ' a > (
518- semantic_model : & ' a SemanticModel ,
519- call_expr : & LuaCallExpr ,
520- ) -> Option < & ' a ModuleInfo > {
521- let arg_list = call_expr. get_args_list ( ) ?;
522- let first_arg = arg_list. get_args ( ) . next ( ) ?;
523- let require_path_type = semantic_model. infer_expr ( first_arg. clone ( ) ) . ok ( ) ?;
524- let module_path: String = match & require_path_type {
525- LuaType :: StringConst ( module_path) => module_path. as_ref ( ) . to_string ( ) ,
526- _ => {
527- return None ;
528- }
529- } ;
530-
531- semantic_model
532- . get_db ( )
533- . get_module_index ( )
534- . find_module ( & module_path)
535- }
482+ // // / 检查导入的表常量
483+ // fn check_require_table_const_with_export<'a>(
484+ // semantic_model: &'a SemanticModel,
485+ // index_expr: &LuaIndexExpr,
486+ // ) -> Option<&'a ModuleInfo> {
487+ // // 获取前缀表达式的语义信息
488+ // let prefix_expr = index_expr.get_prefix_expr()?;
489+ // if let Some(call_expr) = LuaCallExpr::cast(prefix_expr.syntax().clone()) {
490+ // let module_info = parse_require_expr_module_info(semantic_model, &call_expr)?;
491+ // if module_info.is_export(semantic_model.get_db()) {
492+ // return Some(module_info);
493+ // }
494+ // }
495+
496+ // let semantic_info = semantic_model.get_semantic_info(prefix_expr.syntax().clone().into())?;
497+
498+ // // 检查是否是声明引用
499+ // let decl_id = match semantic_info.semantic_decl? {
500+ // LuaSemanticDeclId::LuaDecl(decl_id) => decl_id,
501+ // _ => return None,
502+ // };
503+
504+ // // 获取声明
505+ // let decl = semantic_model
506+ // .get_db()
507+ // .get_decl_index()
508+ // .get_decl(&decl_id)?;
509+
510+ // let module_info = parse_require_module_info(semantic_model, decl)?;
511+ // if module_info.is_export(semantic_model.get_db()) {
512+ // return Some(module_info);
513+ // }
514+ // None
515+ // }
516+
517+ // pub fn parse_require_expr_module_info<'a>(
518+ // semantic_model: &'a SemanticModel,
519+ // call_expr: &LuaCallExpr,
520+ // ) -> Option<&'a ModuleInfo> {
521+ // let arg_list = call_expr.get_args_list()?;
522+ // let first_arg = arg_list.get_args().next()?;
523+ // let require_path_type = semantic_model.infer_expr(first_arg.clone()).ok()?;
524+ // let module_path: String = match &require_path_type {
525+ // LuaType::StringConst(module_path) => module_path.as_ref().to_string(),
526+ // _ => {
527+ // return None;
528+ // }
529+ // };
530+
531+ // semantic_model
532+ // .get_db()
533+ // .get_module_index()
534+ // .find_module(&module_path)
535+ // }
0 commit comments