重构语法树/符号表
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include <spdlog/spdlog.h>
|
||||
#include "./initialize.hpp"
|
||||
#include "../../service/symbol.hpp"
|
||||
#include "../../scheduler/async_executor.hpp"
|
||||
#include "../../protocol/transform/facade.hpp"
|
||||
|
||||
namespace lsp::provider
|
||||
@@ -18,6 +20,10 @@ namespace lsp::provider
|
||||
{
|
||||
spdlog::debug("InitializeProvider: Providing response for method {}", request.method);
|
||||
|
||||
protocol::InitializeParams params = transform::As<protocol::InitializeParams>(request.params.value());
|
||||
if (params.workspaceFolders)
|
||||
ProcessWorkspaceFolder(params.workspaceFolders.value(), context);
|
||||
|
||||
protocol::ResponseMessage response;
|
||||
response.id = request.id;
|
||||
response.result = transform::LSPAny(BuildInitializeResult());
|
||||
@@ -53,9 +59,9 @@ namespace lsp::provider
|
||||
protocol::CompletionOptions Initialize::BuildCompletionOptions()
|
||||
{
|
||||
protocol::CompletionOptions options;
|
||||
options.triggerCharacters = { std::vector<std::string>{ "." } };
|
||||
options.triggerCharacters = { std::vector<std::string>{ ".", "(" } };
|
||||
options.resolveProvider = true;
|
||||
options.completionItem = {.labelDetailsSupport = true};
|
||||
options.completionItem = { .labelDetailsSupport = true };
|
||||
return options;
|
||||
}
|
||||
|
||||
@@ -100,4 +106,39 @@ namespace lsp::provider
|
||||
return options;
|
||||
}
|
||||
|
||||
void Initialize::ProcessWorkspaceFolder(const std::vector<protocol::WorkspaceFolder>& workspace_folders, ExecutionContext& context)
|
||||
{
|
||||
auto symbol = context.GetService<service::Symbol>();
|
||||
auto& scheduler = context.GetScheduler();
|
||||
for (const auto& workspace_folder : workspace_folders)
|
||||
{
|
||||
std::string workspace_path = UriToPath(workspace_folder.uri);
|
||||
scheduler.Submit("Load workspace symbols", [symbol, workspace_path, folder_name = workspace_folder.name]() -> std::optional<std::string> {
|
||||
try
|
||||
{
|
||||
symbol->LoadWorkspaceSymbols(workspace_path);
|
||||
|
||||
return fmt::format("Loaded workspace {} symbols", workspace_path);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
spdlog::error("Failed to load workspace {} symbols: {}", folder_name, e.what());
|
||||
throw; // Request会处理异常
|
||||
} }, [](const std::string& result) { spdlog::info("Worksapce loading result:", result); });
|
||||
}
|
||||
|
||||
spdlog::info("Initiated loading for {} workspace folder(s)", workspace_folders.size());
|
||||
}
|
||||
|
||||
std::string Initialize::UriToPath(const protocol::DocumentUri& uri)
|
||||
{
|
||||
std::string path = uri;
|
||||
if (path.find("file://") == 0)
|
||||
path = path.substr(7);
|
||||
#ifdef _WIN32
|
||||
if (path.length() > 0 && path[0] == '/')
|
||||
path = path.substr(1);
|
||||
#endif
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,5 +17,8 @@ namespace lsp::provider
|
||||
protocol::TextDocumentSyncOptions BuildTextDocumentSyncOptions();
|
||||
protocol::CompletionOptions BuildCompletionOptions();
|
||||
protocol::SemanticTokensOptions BuildSemanticTokenOptions();
|
||||
|
||||
void ProcessWorkspaceFolder(const std::vector<protocol::WorkspaceFolder>& workspace_folders, ExecutionContext& context);
|
||||
std::string UriToPath(const protocol::DocumentUri& uri);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user