#pragma once
#include <string>
#include <vector>
#include "../base/provider_interface.hpp"
#include "../../protocol/protocol.hpp"
#include "../../language/tsl_keywords.hpp"

namespace lsp::providers::text_document
{
    class CompletionProvider : public IRequestProvider
    {
    public:
        CompletionProvider() = default;

        std::string GetMethod() const override;
        std::string GetProviderName() const override;
        std::string ProvideResponse(const protocol::RequestMessage& request, ProviderContext& context) override;

    private:
        // 构建完整的补全响应
        protocol::CompletionList BuildCompletionResponse(const protocol::CompletionParams& params);

        // 获取补全前缀（从文档内容和位置计算）
        std::string ExtractPrefix(const protocol::TextDocumentIdentifier& textDocument, const protocol::Position& position);

        // 提供不同类型的补全
        std::vector<protocol::CompletionItem> ProvideKeywordCompletions(const std::string& prefix);
        std::vector<protocol::CompletionItem> ProvideContextualCompletions(const protocol::TextDocumentIdentifier& textDocument, const protocol::Position& position, const std::string& prefix);

    private:
        tsl::TslKeywords tsl_keywords_;
    };
}
