import { SymbolKind } from "vscode-languageserver-protocol";
import { pathToUri } from "./uri.js";
function symbolKindToLsp(kind) {
    switch (kind) {
        case "function": return SymbolKind.Function;
        case "node": return SymbolKind.Module;
        case "type": return SymbolKind.TypeParameter;
        default: return SymbolKind.Variable;
    }
}
export function getWorkspaceSymbols(query, symbolTable) {
    const results = [];
    const lowerQuery = query.toLowerCase();
    for (const filePath of symbolTable.filePaths()) {
        const fileSymbols = symbolTable.getFile(filePath);
        if (!fileSymbols)
            continue;
        for (const [name, sym] of Object.entries(fileSymbols)) {
            if (lowerQuery && !name.toLowerCase().includes(lowerQuery))
                continue;
            results.push({
                name,
                kind: symbolKindToLsp(sym.kind),
                location: {
                    uri: pathToUri(filePath),
                    range: sym.loc
                        ? { start: { line: sym.loc.line, character: sym.loc.col }, end: { line: sym.loc.line, character: sym.loc.col } }
                        : { start: { line: 0, character: 0 }, end: { line: 0, character: 0 } },
                },
            });
        }
    }
    return results;
}
