This commit is contained in:
csh
2025-07-05 10:38:05 +08:00
parent 3cc1fccc81
commit 0c4619261d
39 changed files with 2085 additions and 875 deletions
@@ -4,13 +4,25 @@
namespace lsp::providers::text_document
{
std::string CompletionProvider::ProvideResponse(const protocol::RequestMessage& request)
std::string CompletionProvider::GetMethod() const
{
return "textDocument/completion";
}
std::string CompletionProvider::GetProviderName() const
{
return "CompletionProvider";
}
std::string CompletionProvider::ProvideResponse(const protocol::RequestMessage& request, ProviderContext& context)
{
static_cast<void>(context);
spdlog::debug("CompletionProvider: Providing response for method {}", request.method);
try {
// 验证请求是否包含参数
if (!request.params.has_value()) {
if (!request.params.has_value())
{
spdlog::warn("{}: Missing params in request", GetProviderName());
return BuildErrorResponseMessage(request, protocol::ErrorCode::kInvalidParams, "Missing params");
}
@@ -42,15 +54,6 @@ namespace lsp::providers::text_document
}
}
std::string CompletionProvider::GetMethod() const
{
return "textDocument/completion";
}
std::string CompletionProvider::GetProviderName() const
{
return "CompletionProvider";
}
protocol::CompletionList CompletionProvider::BuildCompletionResponse(const protocol::CompletionParams& params)
{
@@ -7,14 +7,14 @@
namespace lsp::providers::text_document
{
class CompletionProvider : public ILspProvider
class CompletionProvider : public IRequestProvider
{
public:
CompletionProvider() = default;
std::string ProvideResponse(const protocol::RequestMessage& request) override;
std::string GetMethod() const override;
std::string GetProviderName() const override;
std::string ProvideResponse(const protocol::RequestMessage& request, ProviderContext& context) override;
private:
// 构建完整的补全响应
@@ -1,19 +1,9 @@
#include <spdlog/spdlog.h>
#include "./did_change_provider.hpp"
#include "./did_open_provider.hpp"
namespace lsp::providers::text_document
{
std::string DidChangeProvider::ProvideResponse(const protocol::RequestMessage& request)
{
spdlog::debug("DidChangeProvider: Providing response for method {}", request.method);
std::string json;
glz::obj empty_obj{}; // glaze的对象类型
auto ec = glz::write_json(empty_obj, json);
return ec ? BuildErrorResponseMessage(request, protocol::ErrorCode::kInternalError, "Internal error") : json;
}
std::string DidChangeProvider::GetMethod() const
{
return "textDocument/didChange";
@@ -24,4 +14,10 @@ namespace lsp::providers::text_document
return "DidChangeProvider";
}
void DidChangeProvider::HandleNotification(const protocol::NotificationMessage& notification, ProviderContext& context)
{
static_cast<void>(context);
spdlog::debug("DidChangeProvider: Providing response for method {}", notification.method);
}
}
@@ -3,12 +3,12 @@
namespace lsp::providers::text_document
{
class DidChangeProvider : public ILspProvider
class DidChangeProvider : public INotificationProvider
{
public:
DidChangeProvider() = default;
std::string ProvideResponse(const protocol::RequestMessage& request) override;
std::string GetMethod() const override;
std::string GetProviderName() const override;
void HandleNotification(const protocol::NotificationMessage& notification, ProviderContext& context) override;
};
}
@@ -3,15 +3,6 @@
namespace lsp::providers::text_document
{
std::string DidOpenProvider::ProvideResponse(const protocol::RequestMessage& request)
{
spdlog::debug("DidOpenProvider: Providing response for method {}", request.method);
std::string json;
glz::obj empty_obj{}; // glaze的对象类型
auto ec = glz::write_json(empty_obj, json);
return ec ? BuildErrorResponseMessage(request, protocol::ErrorCode::kInternalError, "Internal error") : json;
}
std::string DidOpenProvider::GetMethod() const
{
return "textDocument/didOpen";
@@ -22,4 +13,10 @@ namespace lsp::providers::text_document
return "DidOpenProvider";
}
void DidOpenProvider::HandleNotification(const protocol::NotificationMessage& notification, ProviderContext& context)
{
static_cast<void>(context);
spdlog::debug("DidOpenProvider: Providing response for method {}", notification.method);
}
}
@@ -4,12 +4,12 @@
namespace lsp::providers::text_document
{
class DidOpenProvider : public ILspProvider
class DidOpenProvider : public INotificationProvider
{
public:
DidOpenProvider() = default;
std::string ProvideResponse(const protocol::RequestMessage& request) override;
std::string GetMethod() const override;
std::string GetProviderName() const override;
void HandleNotification(const protocol::NotificationMessage& notification, ProviderContext& context) override;
};
}