"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.findPathTo = exports.walker = exports.getCurrentToken = void 0;
function getCurrentToken(tokens, offset) {
    return (tokens.find(({ range }) => range[0] <= offset && range[1] > offset) ||
        tokens.find(({ range }) => range[1] == offset));
}
exports.getCurrentToken = getCurrentToken;
function walker(node, callback) {
    if (node == undefined ||
        typeof node === 'boolean' ||
        typeof node === 'number' ||
        typeof node === 'string') {
        return;
    }
    if (Array.isArray(node)) {
        return node.map((n) => walker(n, callback));
    }
    // isObject
    if (node.args) {
        node.args.map((n) => walker(n, callback));
        callback(node);
    }
}
exports.walker = walker;
function findPathTo(node, offset) {
    const path = [];
    if (offset === null)
        return path;
    walker(node, (node) => {
        if (node.range[0] <= offset && node.range[1] >= offset) {
            path.push(node);
        }
    });
    return path;
}
exports.findPathTo = findPathTo;
