tree-sitter test

This commit is contained in:
csh
2025-08-29 16:51:24 +08:00
parent aad4917fc0
commit 4d79b8d6ba
44 changed files with 180634 additions and 1841 deletions
@@ -1,9 +1,10 @@
#pragma once
#include <memory>
#include <string>
#include <spdlog/spdlog.h>
#include "../../protocol/protocol.hpp"
#include "../../scheduler/request_scheduler.hpp"
#include "../../services/document.hpp"
#include "../../services/service_container.hpp"
namespace lsp::providers
{
@@ -21,12 +22,16 @@ namespace lsp::providers
class ExecutionContext
{
public:
ExecutionContext(scheduler::RequestScheduler* scheduler, LifecycleCallback lifecycle_callback, services::DocumentService* document_manager = nullptr) :
scheduler_(scheduler), lifecycle_callback_(lifecycle_callback), document_service_(document_manager) {}
ExecutionContext(LifecycleCallback lifecycle_callback, scheduler::RequestScheduler& scheduler, services::ServiceContainer& container) :
lifecycle_callback_(lifecycle_callback), scheduler_(scheduler), service_container_(container) {}
scheduler::RequestScheduler* GetScheduler() const { return scheduler_; }
scheduler::RequestScheduler& GetScheduler() const { return scheduler_; }
services::DocumentService* GetDocumentService() const { return document_service_; }
template<typename T>
T& GetService() const
{
return service_container_.Get<T>();
}
void TriggerLifecycleEvent(ServerLifecycleEvent event) const
{
@@ -35,9 +40,9 @@ namespace lsp::providers
}
private:
scheduler::RequestScheduler* scheduler_;
LifecycleCallback lifecycle_callback_;
services::DocumentService* document_service_;
scheduler::RequestScheduler& scheduler_;
services::ServiceContainer& service_container_;
};
// LSP请求提供者接口基类
@@ -4,6 +4,7 @@
#include "../initialized/initialized_provider.hpp"
#include "../text_document/did_open_provider.hpp"
#include "../text_document/did_change_provider.hpp"
#include "../text_document/did_close_provider.hpp"
#include "../text_document/completion_provider.hpp"
#include "../trace/set_trace_provider.hpp"
#include "../shutdown/shutdown_provider.hpp"
@@ -21,6 +22,7 @@ namespace lsp::providers
RegisterProvider<initialized::InitializedProvider>(dispatcher);
RegisterProvider<text_document::DidOpenProvider>(dispatcher);
RegisterProvider<text_document::DidChangeProvider>(dispatcher);
RegisterProvider<text_document::DidCloseProvider>(dispatcher);
RegisterProvider<text_document::CompletionProvider>(dispatcher);
RegisterProvider<set_trace::SetTraceProvider>(dispatcher);
RegisterProvider<shutdown::ShutdownProvider>(dispatcher);
@@ -20,11 +20,10 @@ namespace lsp::providers::cancel_request
std::string id_to_cancel = transform::debug::GetIdString(params.id);
spdlog::info("Processing cancel request for ID: {}", id_to_cancel);
if (auto* scheduler = context.GetScheduler())
{
bool cancelled = scheduler->Cancel(id_to_cancel);
spdlog::info("Cancel request {} result: {}", id_to_cancel, cancelled ? "success" : "not found");
}
auto& scheduler = context.GetScheduler();
bool cancelled = scheduler.Cancel(id_to_cancel);
spdlog::info("Cancel request {} result: {}", id_to_cancel, cancelled ? "success" : "not found");
}
catch (const std::exception& e)
{
@@ -1,5 +1,8 @@
#include <spdlog/spdlog.h>
#include "./did_change_provider.hpp"
#include "../../protocol/protocol.hpp"
#include "../../protocol/transform/facade.hpp"
#include "../../services/document.hpp"
namespace lsp::providers::text_document
{
@@ -16,8 +19,12 @@ namespace lsp::providers::text_document
void DidChangeProvider::HandleNotification(const protocol::NotificationMessage& notification, ExecutionContext& context)
{
static_cast<void>(context);
spdlog::debug("DidChangeProvider: Providing response for method {}", notification.method);
protocol::DidChangeTextDocumentParams did_change_text_document_params = transform::As<protocol::DidChangeTextDocumentParams>(notification.params.value());
services::DocumentService& document_service = context.GetService<services::DocumentService>();
document_service.UpdateDocument(did_change_text_document_params);
}
}
@@ -0,0 +1,30 @@
#include <spdlog/spdlog.h>
#include "./did_close_provider.hpp"
#include "../../protocol/protocol.hpp"
#include "../../protocol/transform/facade.hpp"
#include "../../services/document.hpp"
namespace lsp::providers::text_document
{
std::string DidCloseProvider::GetMethod() const
{
return "textDocument/didClose";
}
std::string DidCloseProvider::GetProviderName() const
{
return "DidCloseProvider";
}
void DidCloseProvider::HandleNotification(const protocol::NotificationMessage& notification, ExecutionContext& context)
{
spdlog::debug("DidCloseProvider: Providing response for method {}", notification.method);
protocol::DidCloseTextDocumentParams did_close_text_document_params = transform::As<protocol::DidCloseTextDocumentParams>(notification.params.value());
services::DocumentService& document_service = context.GetService<services::DocumentService>();
document_service.CloseDocument(did_close_text_document_params);
}
}
@@ -0,0 +1,14 @@
#pragma once
#include "../base/provider_interface.hpp"
namespace lsp::providers::text_document
{
class DidCloseProvider : public INotificationProvider
{
public:
DidCloseProvider() = default;
std::string GetMethod() const override;
std::string GetProviderName() const override;
void HandleNotification(const protocol::NotificationMessage& notification, ExecutionContext& context) override;
};
}
@@ -1,5 +1,7 @@
#include <spdlog/spdlog.h>
#include "./did_open_provider.hpp"
#include "../../services/document.hpp"
#include "../../protocol/transform/facade.hpp"
namespace lsp::providers::text_document
{
@@ -15,8 +17,23 @@ namespace lsp::providers::text_document
void DidOpenProvider::HandleNotification(const protocol::NotificationMessage& notification, ExecutionContext& context)
{
static_cast<void>(context);
spdlog::debug("DidOpenProvider: Providing response for method {}", notification.method);
protocol::DidOpenTextDocumentParams did_open_text_document_params = transform::As<protocol::DidOpenTextDocumentParams>(notification.params.value());
services::DocumentService& document_service = context.GetService<services::DocumentService>();
document_service.OpenDocument(did_open_text_document_params);
/*
if (auto* symbolService = context.TryGetService<SymbolService>()) {
symbolService->parseDocument(uri, content);
}
// 3. 触发诊断
if (auto* diagnosticService = context.TryGetService<DiagnosticService>()) {
diagnosticService->diagnose(uri);
}
*/
}
}