"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.register = void 0;
const transformer = require("../transformer");
const vscode = require("vscode-languageserver-protocol");
const common_1 = require("../utils/common");
function register(context) {
    return async (query, token = vscode.CancellationToken.None) => {
        const symbolsList = [];
        for (const plugin of Object.values(context.plugins)) {
            if (token.isCancellationRequested)
                break;
            if (!plugin.provideWorkspaceSymbols)
                continue;
            const embeddedSymbols = await plugin.provideWorkspaceSymbols(query, token);
            if (!embeddedSymbols)
                continue;
            const symbols = embeddedSymbols.map(symbol => transformer.asWorkspaceSymbol(symbol, loc => {
                if (context.documents.isVirtualFileUri(loc.uri)) {
                    for (const [_, map] of context.documents.getMapsByVirtualFileUri(loc.uri)) {
                        const range = map.toSourceRange(loc.range);
                        if (range) {
                            return vscode.Location.create(map.sourceFileDocument.uri, range);
                        }
                    }
                }
                else {
                    return loc;
                }
            })).filter(common_1.notEmpty);
            symbolsList.push(symbols);
        }
        return symbolsList.flat();
    };
}
exports.register = register;
//# sourceMappingURL=workspaceSymbols.js.map