Skip to content

Get node at (line, col) #891

Open
@HoldYourWaffle

Description

@HoldYourWaffle

Is your feature request related to a problem? Please describe.
I get line & column coordinates from an external source, I want to get the node(s) at this coordinate.

Describe the solution you'd like
The obvious solution would be sourceFile.getChildAtPos, but this takes a 1D coordinate. I can convert from "pos" to line+col using sourceFile.getLineAndColumnAtPos (#801) but I can't find anything for the reverse.

Describe alternatives you've considered
I bodged together this:

for (const node of source.getDescendants()) {
    if (line === node.getStartLineNumber() && col === node.getStart() - node.getStartLinePos()) {
        // We have our node!
    }
}

But that doesn't seem like an efficient solution.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions