@@ -117,7 +117,7 @@ std::vector<ModuleService::LuaModule> ModuleService::GetImportModules(std::strin
117117 return result;
118118}
119119
120- vscode::Range ModuleService::FindRequireRange (std::shared_ptr<LuaParser> parser)
120+ vscode::Range ModuleService::FindRequireRange (std::shared_ptr<LuaParser> parser, std::shared_ptr<ModuleConfig> config )
121121{
122122 vscode::Range range;
123123 auto chunkAst = parser->GetAst ();
@@ -156,7 +156,20 @@ vscode::Range ModuleService::FindRequireRange(std::shared_ptr<LuaParser> parser)
156156 auto methodNameNode = callExpression->FindFirstOf (LuaAstNodeType::PrimaryExpression);
157157 if (methodNameNode)
158158 {
159- if (methodNameNode->GetText () == " require" )
159+ if (methodNameNode->GetText () == config->import_function )
160+ {
161+ break ;
162+ }
163+ }
164+ }
165+ // 一些代码会有 local require = require的规则, 勉为其难支持一下
166+ else
167+ {
168+ auto primary = expression->FindFirstOf (LuaAstNodeType::PrimaryExpression);
169+ if (primary)
170+ {
171+ auto nameIdentify = primary->FindFirstOf (LuaAstNodeType::NameIdentify);
172+ if (nameIdentify && nameIdentify->GetText () == config->import_function )
160173 {
161174 break ;
162175 }
@@ -200,17 +213,17 @@ std::vector<vscode::CompletionItem> ModuleService::GetModuleCompletions(std::sha
200213 finder.Analysis (parser);
201214
202215 auto definedNames = finder.GetDefinedName (expression);
203-
216+ auto config = _moduleIndex. GetConfig (path);
204217 auto luaModules = _moduleIndex.GetModules (path);
205- auto insertRange = FindRequireRange (parser);
218+ auto insertRange = FindRequireRange (parser, config );
206219
207220
208221 for (auto & luaModule : luaModules)
209222 {
210223 auto & completion = result.emplace_back ();
211224
212225 std::string& name = luaModule->MatchName ;
213- if (definedNames.count (name) > 0 )
226+ if (definedNames.count (name) > 0 )
214227 {
215228 continue ;
216229 }
0 commit comments