#pragma once
#include <string>
#include <vector>
#include <regex>
#include "../base/interface.hpp"

namespace lsp::provider::workspace
{
    class Symbol : public IRequestProvider
    {
    public:
        Symbol() = default;

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

    private:
        // 构建工作区符号响应
        std::vector<protocol::SymbolInformation> BuildSymbolResponse(const protocol::WorkspaceSymbolParams& params, ExecutionContext& context);

        // 搜索匹配的符号
        std::vector<protocol::SymbolInformation> SearchSymbols(const std::string& query, ExecutionContext& context);

        // 将DocumentSymbol转换为SymbolInformation
        void ConvertToSymbolInformation(
            const protocol::DocumentSymbol& doc_symbol,
            const protocol::DocumentUri& uri,
            const std::string& query,
            std::vector<protocol::SymbolInformation>& results,
            const std::string& container_name = "");

        // 符号名称匹配
        bool MatchesQuery(const std::string& symbol_name, const std::string& query);

        // 模糊匹配算法
        bool FuzzyMatch(const std::string& pattern, const std::string& text);

        // 计算匹配分数（用于排序）
        int CalculateScore(const std::string& symbol_name, const std::string& query);
    };
}
