Skip to content

Metrics of a file are attributed to its first function space when the root of the tree is an ERROR node #1260

Closed

Description

@marco-c

When error recovery turns the root of the tree into an ERROR node, metrics() doesn't open a space for it: is_func_space only matches program, translation_unit, etc. The first function found below the root then becomes the root space, and every following space is merged into it.

For example, with this JavaScript code:

const F = {
    a: x => 1
};
class A {
    g() {

the root of the tree is an ERROR node, and the metrics returned for the file are the ones of a function space named after the file, spanning only line 2 (the a arrow function).

On larger files, this gives nonsensical values, e.g. for third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/preact/src/app/index.js in mozilla-central (134 lines, which fails to parse because of JSX class= attributes), the file-level space spans line 11 only, with sloc 1 and blank -106.

It also affects the DeepSpeech snapshots in rca-output: the root of kenlm/lm/model.hh is a namespace spanning line 22, and the root of the two pywrapfst.cc files (57363 lines) is a struct spanning lines 391-395.

This was already the case before #1253, but tree-sitter 0.27 recovers from errors differently, so it now happens for files that used to get a program root.

Activity

  1. added a commit that references this issue on Nov 21, 2026
    10acb9d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions