#include <spdlog/spdlog.h>
#include "./did_open.hpp"
#include "../../protocol/transform/facade.hpp"
#include "../../service/document.hpp"

namespace lsp::provider::text_document
{
    std::string DidOpen::GetMethod() const
    {
        return "textDocument/didOpen";
    }

    std::string DidOpen::GetProviderName() const
    {
        return "TextDocumentDidOpen";
    }

    void DidOpen::HandleNotification(const protocol::NotificationMessage& notification, ExecutionContext& context)
    {
        spdlog::debug("TextDocumentDidOpenProvider: Providing response for method {}", notification.method);

        protocol::DidOpenTextDocumentParams params = transform::As<protocol::DidOpenTextDocumentParams>(notification.params.value());

        auto document_service = context.GetService<service::Document>();
        document_service->OpenDocument(params);

        /*
        if (auto* symbolService = context.TryGetService<SymbolService>()) {
            symbolService->parseDocument(uri, content);
        }

        // 3. 触发诊断
        if (auto* diagnosticService = context.TryGetService<DiagnosticService>()) {
            diagnosticService->diagnose(uri);
        }
        */
        spdlog::info("Document opened: {}", params.textDocument.uri);
    }

}
