Files
tsl-devkit/lsp-server/src/provider/shutdown/shutdown.cppm
T

54 lines
1.4 KiB
C++

module;
export module lsp.provider.shutdown.shutdown;
import spdlog;
import std;
import lsp.protocol;
import lsp.codec.facade;
import lsp.provider.base.interface;
namespace transform = lsp::codec;
export namespace lsp::provider
{
class Shutdown : public AutoRegisterProvider<Shutdown, IRequestProvider>
{
public:
static constexpr std::string_view kMethod = "shutdown";
static constexpr std::string_view kProviderName = "Shutdown";
Shutdown() = default;
std::string ProvideResponse(const protocol::RequestMessage& request, ExecutionContext& context) override;
};
}
namespace lsp::provider
{
std::string Shutdown::ProvideResponse(const protocol::RequestMessage& request, ExecutionContext& context)
{
spdlog::debug("ShutdownProvider: Providing response for method {}", request.method);
// 触发关闭事件
context.TriggerLifecycleEvent(ServerLifecycleEvent::kShuttingDown);
context.GetManagerHub().Shutdown();
// 构建响应 - shutdown 返回 null
protocol::ResponseMessage response;
response.id = request.id;
auto json = transform::Serialize(response);
if (!json.has_value())
return BuildErrorResponseMessage(request, protocol::ErrorCodes::InternalError, "Failed to serialize response");
spdlog::info("Shutdown request processed successfully");
return json.value();
}
}