Skip to content

Commit ac80309

Browse files
committed
修复一个require位置的问题
1 parent 700074c commit ac80309

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

CodeFormatServer/src/Service/CompletionService.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ void CompletionService::Start()
1515
AddCompleteContributor({LuaAstNodeType::NameIdentify},
1616
std::bind(&ModuleService::GetModuleCompletions, GetService<ModuleService>().get(),
1717
_1, _2, _3, _4));
18+
// AddCompleteContributor({LuaAstNodeType::LiteralExpression},
19+
// std::bind(&ModuleService::GetRequireCompletions, GetService<ModuleService>().get(),
20+
// _1, _2, _3, _4)
21+
// );
1822
}
1923

2024
std::vector<vscode::CompletionItem> CompletionService::GetCompletions(std::string_view uri,
@@ -74,11 +78,10 @@ std::shared_ptr<LuaAstNode> CompletionService::FindAstFromPosition(vscode::Posit
7478
}
7579
}
7680

77-
if(!hasNext)
81+
if (!hasNext)
7882
{
7983
return ast;
8084
}
81-
8285
}
8386

8487
return nullptr;

CodeFormatServer/src/Service/ModuleService.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ vscode::Range ModuleService::FindRequireRange(std::shared_ptr<LuaParser> parser,
129129
auto blockNode = chunkAst->GetChildren().front();
130130

131131
std::shared_ptr<LuaAstNode> lastNode = nullptr;
132-
132+
int lastLine = -1;
133133
auto& children = blockNode->GetChildren();
134134
for (auto statement : children)
135135
{
@@ -184,7 +184,13 @@ vscode::Range ModuleService::FindRequireRange(std::shared_ptr<LuaParser> parser,
184184
goto endLoop;
185185
}
186186
}
187+
188+
if (parser->GetLine(statement->GetTextRange().StartOffset) - lastLine > 2)
189+
{
190+
goto endLoop;
191+
}
187192
lastNode = statement;
193+
lastLine = parser->GetLine(lastNode->GetTextRange().EndOffset);
188194
}
189195
endLoop:
190196
if (lastNode)
@@ -221,9 +227,9 @@ std::vector<vscode::CompletionItem> ModuleService::GetModuleCompletions(std::sha
221227

222228
for (auto& luaModule : luaModules)
223229
{
224-
if(completionMap.count(luaModule->MatchName) == 0)
230+
if (completionMap.count(luaModule->MatchName) == 0)
225231
{
226-
completionMap.insert({ luaModule->MatchName, { luaModule} });
232+
completionMap.insert({luaModule->MatchName, {luaModule}});
227233
}
228234
else
229235
{
@@ -249,7 +255,8 @@ std::vector<vscode::CompletionItem> ModuleService::GetModuleCompletions(std::sha
249255
command.arguments.push_back(uri);
250256
command.arguments.push_back(insertRange.Serialize());
251257

252-
if (pair.second.size() == 1) {
258+
if (pair.second.size() == 1)
259+
{
253260
auto& luaModule = pair.second.front();
254261
completion.detail = format("({})", name);
255262
completion.documentation = format("import from {}", luaModule->FilePath);
@@ -258,12 +265,12 @@ std::vector<vscode::CompletionItem> ModuleService::GetModuleCompletions(std::sha
258265
object["path"] = luaModule->FilePath;
259266
object["name"] = name;
260267
command.arguments.push_back(object);
261-
262268
}
263269
else
264270
{
265271
completion.detail = "import multi choice";
266-
for (auto& luaModule : pair.second) {
272+
for (auto& luaModule : pair.second)
273+
{
267274
auto object = nlohmann::json::object();
268275
object["moduleName"] = luaModule->ModuleName;
269276
object["path"] = luaModule->FilePath;
@@ -276,3 +283,11 @@ std::vector<vscode::CompletionItem> ModuleService::GetModuleCompletions(std::sha
276283

277284
return result;
278285
}
286+
287+
// std::vector<vscode::CompletionItem> ModuleService::GetRequireCompletions(std::shared_ptr<LuaAstNode> expression,
288+
// std::shared_ptr<LuaParser> parser,
289+
// std::shared_ptr<LuaCodeStyleOptions> options,
290+
// std::string_view uri)
291+
// {
292+
//
293+
// }

include/CodeFormatServer/Service/ModuleService.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ class ModuleService : public Service
4141
std::shared_ptr<LuaCodeStyleOptions> options,
4242
std::string_view uri);
4343

44+
// std::vector<vscode::CompletionItem> GetRequireCompletions(std::shared_ptr<LuaAstNode> expression,
45+
// std::shared_ptr<LuaParser> parser,
46+
// std::shared_ptr<LuaCodeStyleOptions> options,
47+
// std::string_view uri);
48+
4449
private:
4550
ModuleIndex _moduleIndex;
4651
std::map<std::string, std::multimap<vscode::Range, LuaModule>, std::less<>> _diagnosticCaches;

0 commit comments

Comments
 (0)