1- #include " CodeFormatServer/Service/ModuleService.h"
1+ #include " CodeFormatServer/Service/ModuleService.h"
22#include " LuaParser/LuaAstVisitor.h"
3+ #include " Util/StringUtil.h"
34
45class UnResolveModuleFinder : public LuaAstVisitor
56{
@@ -153,7 +154,7 @@ std::vector<vscode::Diagnostic> ModuleService::Diagnose(std::string_view filePat
153154 auto & undefinedModules = finder.GetUndefinedModule (parser);
154155 auto & luaModules = _moduleIndex.GetModules (options);
155156
156- std::multimap<vscode::Range, ModuleIndex::Module > rangeModule;
157+ std::multimap<vscode::Range, LuaModule > rangeModule;
157158 for (auto & undefinedModule : undefinedModules)
158159 {
159160 auto undefinedModuleName = undefinedModule->GetText ();
@@ -171,10 +172,10 @@ std::vector<vscode::Diagnostic> ModuleService::Diagnose(std::string_view filePat
171172 name = luaModule.ModuleName .substr (dotPosition + 1 );
172173 }
173174
174- if (undefinedModuleName == name)
175+ if (StringUtil::IsStringEqualIgnoreCase ( undefinedModuleName, name) )
175176 {
176177 auto & diagnostic = result.emplace_back ();
177- diagnostic.message = " not import module" ;
178+ diagnostic.message = " need import module" ;
178179 auto textRange = undefinedModule->GetTextRange ();
179180 auto range = vscode::Range (
180181 vscode::Position (
@@ -186,9 +187,17 @@ std::vector<vscode::Diagnostic> ModuleService::Diagnose(std::string_view filePat
186187 parser->GetColumn (textRange.EndOffset )
187188 )
188189 );
189- rangeModule.insert ({range, luaModule});
190+
191+ rangeModule.insert ({
192+ range, LuaModule{
193+ .ModuleName = luaModule.ModuleName ,
194+ .FilePath = luaModule.FilePath ,
195+ .Name = std::string (undefinedModuleName)
196+ }
197+ });
198+
190199 diagnostic.range = range;
191- diagnostic.severity = vscode::DiagnosticSeverity::Information ;
200+ diagnostic.severity = vscode::DiagnosticSeverity::Hint ;
192201 }
193202 }
194203 }
@@ -214,25 +223,53 @@ bool ModuleService::IsDiagnosticRange(std::string_view filePath, vscode::Range r
214223 return false ;
215224 }
216225
217- return it->second .count (range) > 0 ;
226+ if (range.start == range.end )
227+ {
228+ for (auto & pair : it->second )
229+ {
230+ if (pair.first .start <= range.start && pair.first .end >= range.end )
231+ {
232+ return true ;
233+ }
234+ }
235+ return false ;
236+ }
237+ else
238+ {
239+ return it->second .count (range) > 0 ;
240+ }
218241}
219242
220- std::vector<ModuleIndex::Module > ModuleService::GetImportModules (std::string_view filePath, vscode::Range range)
243+ std::vector<ModuleService::LuaModule > ModuleService::GetImportModules (std::string_view filePath, vscode::Range range)
221244{
222245 auto fIt = _diagnosticCaches.find (filePath);
223246 if (fIt == _diagnosticCaches.end ())
224247 {
225248 return {};
226249 }
227250
251+ std::vector<LuaModule> result;
228252 auto & rangeModules = fIt ->second ;
229- auto equalRange = rangeModules.equal_range (range);
230- std::vector<ModuleIndex::Module> result;
231- for (auto it = equalRange.first ; it != equalRange.second ; ++it)
253+
254+ if (range.start == range.end )
232255 {
233- result.emplace_back (it->second );
256+ for (auto & pair : rangeModules)
257+ {
258+ if (pair.first .start <= range.start && pair.first .end >= range.end )
259+ {
260+ result.push_back (pair.second );
261+ }
262+ }
234263 }
264+ else
265+ {
266+ auto itPair = rangeModules.equal_range (range);
235267
268+ for (auto it = itPair.first ; it != itPair.second ; it++)
269+ {
270+ result.push_back (it->second );
271+ }
272+ }
236273 return result;
237274}
238275
@@ -271,7 +308,7 @@ vscode::Range ModuleService::FindRequireRange(std::shared_ptr<LuaParser> parser)
271308 auto callExpression = expression->FindFirstOf (LuaAstNodeType::CallExpression);
272309 if (callExpression)
273310 {
274- // ½«Ô¼¶¨×ö³É¹æ·¶
311+ // 将约定做成规范
275312 auto methodNameNode = callExpression->FindFirstOf (LuaAstNodeType::PrimaryExpression);
276313 if (methodNameNode)
277314 {
@@ -287,7 +324,7 @@ vscode::Range ModuleService::FindRequireRange(std::shared_ptr<LuaParser> parser)
287324 }
288325 default :
289326 {
290- break ;
327+ goto endLoop ;
291328 }
292329 }
293330 lastNode = statement;
0 commit comments