Skip to content

Incorrect line number in start_point for function_statement node #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jubnzv opened this issue Dec 25, 2021 · 1 comment · May be fixed by #51
Open

Incorrect line number in start_point for function_statement node #44

jubnzv opened this issue Dec 25, 2021 · 1 comment · May be fixed by #51

Comments

@jubnzv
Copy link

jubnzv commented Dec 25, 2021

Consider the minimal example:

a = 42

function foo()
  return 19
end

The problem is that function_statement node for foo function has start_point with position (line=0, col=6). But the 0th line corresponds to the definition of a = 42, and the correct line number for the foo is 2.

Here is the minimal driver code using py-tree-sitter to quickly reproduce this issue:

parser = ts.Parser()
parser.set_language(ts.Language("lua-tree-sitter.so", "lua"))
parse_tree = parser.parse(b'''a = 42

function foo()
  return 19
end''')
q = self.ts_lang.query("(program) @p")
captures = q.captures(parse_tree.root_node)
for top_node in captures[0][0].children:
    print(f"{top_node.type}: line={top_node.start_point[0]} col={top_node.start_point[1]}")

Output:

variable_declaration: (line=0, col=0)
function_statement: (line=0, col=6)

Expected:

variable_declaration: (line=0, col=0)
function_statement: (line=2, col=6)
@jubnzv jubnzv changed the title Incorrect line number in start_point for `function_statement node Incorrect line number in start_point for function_statement node Dec 25, 2021
@starwing
Copy link

Is there any way to solve this?

@starwing starwing linked a pull request Aug 24, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants