更改日志模块为spdlog

This commit is contained in:
csh
2025-06-24 21:57:40 +08:00
parent d9beeb82a6
commit 56b0f5473a
18 changed files with 111 additions and 242 deletions
@@ -1,3 +1,4 @@
#include <spdlog/spdlog.h>
#include "./provider_registry.hpp"
#include "../initialize/initialize_provider.hpp"
#include "../initialized/initialized_provider.hpp"
@@ -5,14 +6,13 @@
#include "../text_document/did_change_provider.hpp"
#include "../text_document/completion_provider.hpp"
#include "../trace/set_trace_provider.hpp"
#include "../../lsp/logger.hpp"
namespace lsp::providers
{
void RegisterAllProviders(RequestDispatcher& dispatcher)
{
log::Info("Registering LSP providers...");
spdlog::info("Registering LSP providers...");
RegisterProvider<initialize::InitializeProvider>(dispatcher);
RegisterProvider<initialized::InitializedProvider>(dispatcher);
@@ -21,7 +21,7 @@ namespace lsp::providers
RegisterProvider<text_document::CompletionProvider>(dispatcher);
RegisterProvider<trace::SetTraceProvider>(dispatcher);
log::Info("Successfully registered ", dispatcher.GetSupportedMethods().size(), " LSP providers");
spdlog::info("Successfully registered {} LSP providers", dispatcher.GetSupportedMethods().size());
}
}
@@ -1,7 +1,7 @@
#pragma once
#include <spdlog/spdlog.h>
#include "../../lsp/dispacther.hpp"
#include "./provider_interface.hpp"
#include "../../lsp/logger.hpp"
namespace lsp::providers
{
@@ -15,7 +15,7 @@ namespace lsp::providers
auto provider = std::make_shared<ProviderClass>();
log::Info("Registering ", provider->GetProviderName(), " for method: ", provider->GetMethod());
spdlog::info("Registering {} for method: {}", provider->GetProviderName(), provider->GetMethod());
dispatcher.RegisterProvider(
provider->GetMethod(),
@@ -1,16 +1,16 @@
#include <spdlog/spdlog.h>
#include "./initialize_provider.hpp"
#include "../../lsp/logger.hpp"
namespace lsp::providers::initialize
{
nlohmann::json InitializeProvider::ProvideResponse(const LspRequest& request)
{
spdlog::debug("InitializeProvider: Providing response for method {}", request.method);
nlohmann::json response;
response["jsonrpc"] = "2.0";
response["id"] = request.id;
response["result"] = BuildInitializeResult();
log::Debug("InitializeProvider: Providing response for method '", request.method, "' with id ", request.id);
return response;
}
@@ -1,12 +1,12 @@
#include <spdlog/spdlog.h>
#include "./initialized_provider.hpp"
#include "../../lsp/logger.hpp"
namespace lsp::providers::initialized
{
nlohmann::json InitializedProvider::ProvideResponse(const LspRequest& request)
{
log::Debug("InitializedProvider: Providing response for method '", request.method, "' with id ", request.id);
spdlog::debug("InitializeProvider: Providing response for method {}", request.method);
return nlohmann::json();
}
@@ -1,11 +1,11 @@
#include <spdlog/spdlog.h>
#include "./completion_provider.hpp"
#include "../../lsp/logger.hpp"
namespace lsp::providers::text_document
{
nlohmann::json CompletionProvider::ProvideResponse(const LspRequest& request)
{
log::Debug("CompletionProvider: Providing response for method '", request.method, "' with id ", request.id);
spdlog::debug("CompletionProvider: Providing response for method {}", request.method);
try
{
nlohmann::json response = BuildCompletionResponse(request);
@@ -13,7 +13,7 @@ namespace lsp::providers::text_document
}
catch (const std::exception& e)
{
log::Error(GetProviderName(), ": Error - ", e.what());
spdlog::error("{}: Error - ", GetProviderName(), e.what());
nlohmann::json errorResponse = CreateErrorResponse(request.id, -32603, e.what());
return errorResponse;
}
@@ -38,7 +38,7 @@ namespace lsp::providers::text_document
// 验证必要参数
if (!request.params.contains("textDocument") || !request.params.contains("position"))
{
log::Warn(GetProviderName(), ": Missing required parameters in request");
spdlog::warn("{}: Missing required parameters in request", GetProviderName());
// 返回空补全列表而非错误
response["result"] = BuildCompletionResult({});
return response;
@@ -49,8 +49,7 @@ namespace lsp::providers::text_document
nlohmann::json position = ExtractPosition(request.params);
std::string prefix = ExtractPrefix(request.params);
log::Verbose(
GetProviderName(), ": Processing completion request for URI='", uri, "', Position=", position.dump(), ", Prefix='", prefix, "'");
spdlog::trace("{}: Processing completion request for URI='{}', Position={}, prefix='{}'", GetProviderName(), uri, position.dump(), prefix);
// 收集所有补全项
std::vector<CompletionItem> allItems;
@@ -66,7 +65,7 @@ namespace lsp::providers::text_document
// 构建响应
response["result"] = BuildCompletionResult(allItems);
log::Info(GetProviderName(), ": Provided ", allItems.size(), " completion items");
spdlog::info("{}: Provided {}", GetProviderName(), allItems.size());
return response;
}
@@ -88,10 +87,10 @@ namespace lsp::providers::text_document
if (params.contains("textDocument") && params["textDocument"].contains("uri"))
{
std::string uri = params["textDocument"]["uri"].get<std::string>();
log::Verbose("ExtractDocumentUri: Found URI: ", uri);
spdlog::trace("ExtractDocumentUri: Found URI: ", uri);
return uri;
}
log::Warn("ExtractDocumentUri: No URI found in parameters");
spdlog::warn("ExtractDocumentUri: No URI found in parameters");
return "";
}
@@ -100,14 +99,14 @@ namespace lsp::providers::text_document
if (params.contains("position"))
{
nlohmann::json pos = params["position"];
log::Verbose("ExtractPosition: Found position: ", pos.dump());
spdlog::trace("ExtractPosition: Found position: ", pos.dump());
return pos;
}
// 返回默认位置
nlohmann::json defaultPos;
defaultPos["line"] = 0;
defaultPos["character"] = 0;
log::Warn("ExtractPosition: No position found in parameters, using default (0, 0)");
spdlog::warn("ExtractPosition: No position found in parameters, using default (0, 0)");
return defaultPos;
}
@@ -117,7 +116,7 @@ namespace lsp::providers::text_document
if (params.contains("prefix"))
{
std::string prefix = params["prefix"].get<std::string>();
log::Verbose("ExtractPrefix: Found prefix form params: '", prefix, "'");
spdlog::trace("ExtractPrefix: Found prefix form params: '", prefix, "'");
return prefix;
}
@@ -125,13 +124,13 @@ namespace lsp::providers::text_document
if (params.contains("context") && params["context"].contains("prefix"))
{
std::string prefix = params["context"]["prefix"].get<std::string>();
log::Verbose("ExtractPrefix: Found prefix form params: '", prefix, "'");
spdlog::trace("ExtractPrefix: Found prefix form params: '", prefix, "'");
return prefix;
}
// TODO: 理想情况下,应该从文档内容和位置计算前缀
// 这需要维护文档内容的状态
log::Verbose("ExtractPrefix: No prefix found, returning empty string");
spdlog::trace("ExtractPrefix: No prefix found, returning empty string");
return "";
}
@@ -153,7 +152,7 @@ namespace lsp::providers::text_document
items.push_back(item);
}
log::Debug("ProvideKeywordCompletions: Found ", items.size(), " keyword completions");
spdlog::debug("ProvideKeywordCompletions: Found ", items.size(), " keyword completions");
return items;
}
@@ -162,7 +161,7 @@ namespace lsp::providers::text_document
const nlohmann::json& position,
const std::string& prefix)
{
log::Debug("ProvideContextualCompletions: Processing contextual completions for URI: ", uri);
spdlog::debug("ProvideContextualCompletions: Processing contextual completions for URI: ", uri);
std::vector<CompletionItem> items;
// TODO: 基于上下文提供补全
@@ -171,7 +170,7 @@ namespace lsp::providers::text_document
// - 函数名补全
// - 类型补全
// - 属性补全等
log::Debug("ProvideContextualCompletions: Found ", items.size(), " contextual completions");
spdlog::debug("ProvideContextualCompletions: Found ", items.size(), " contextual completions");
return items;
}
@@ -205,7 +204,7 @@ namespace lsp::providers::text_document
error["message"] = GetProviderName() + ": " + message;
response["error"] = error;
log::Error("CreateErrorResponse: Created error response with code ", code, " and message: ", message);
spdlog::error("CreateErrorResponse: Created error response with code {} and message {}", code, message);
return response;
}
@@ -1,13 +1,13 @@
#include <spdlog/spdlog.h>
#include "./did_change_provider.hpp"
#include "./did_open_provider.hpp"
#include "../../lsp/logger.hpp"
namespace lsp::providers::text_document
{
nlohmann::json DidChangeProvider::ProvideResponse(const LspRequest& request)
{
log::Debug("DidChangeProvider: Providing response for method '", request.method, "' with id ", request.id);
spdlog::debug("DidChangeProvider: Providing response for method {}", request.method);
try
{
auto params = request.params;
@@ -1,5 +1,5 @@
#include <spdlog/spdlog.h>
#include "./did_open_provider.hpp"
#include "../../lsp/logger.hpp"
namespace lsp::providers::text_document
{
@@ -7,7 +7,7 @@ namespace lsp::providers::text_document
nlohmann::json DidOpenProvider::ProvideResponse(const LspRequest& request)
{
log::Debug("DidOpenProvider: Providing response for method '", request.method, "' with id ", request.id);
spdlog::debug("DidOpenProvider: Providing response for method {}", request.method);
try
{
auto params = request.params;