Skip to content
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

Comments get falsely included in preceding indent block #37

Open
aMOPel opened this issue Sep 21, 2023 · 2 comments
Open

Comments get falsely included in preceding indent block #37

aMOPel opened this issue Sep 21, 2023 · 2 comments
Labels
enhancement New feature or request low severity This issue is not prioritized

Comments

@aMOPel
Copy link
Contributor

aMOPel commented Sep 21, 2023

Current Behaviour

var 
  var1 = 5
  # comment

# comment about something else
var var2 = 5
var_section [0, 0] - [5, 0]
  variable_declaration [1, 2] - [1, 10]
    symbol_declaration_list [1, 2] - [1, 6]
      symbol_declaration [1, 2] - [1, 6]
        name: identifier [1, 2] - [1, 6]
    value: integer_literal [1, 9] - [1, 10]
  comment [2, 2] - [2, 11]                                        <- both comments belong to first block
  comment [4, 0] - [4, 30]                                        <-
var_section [5, 0] - [5, 12]
  variable_declaration [5, 4] - [5, 12]
    symbol_declaration_list [5, 4] - [5, 8]
      symbol_declaration [5, 4] - [5, 8]
        name: identifier [5, 4] - [5, 8]
    value: integer_literal [5, 11] - [5, 12]

Expected Behaviour

When not indented like the block, a trailing comment should not be part of it.

@aMOPel aMOPel changed the title Comments get falsely captured by preceding indent block Comments get falsely included in preceding indent block Sep 21, 2023
@alaviss alaviss added bug Something isn't working low severity This issue is not prioritized enhancement New feature or request and removed bug Something isn't working labels Sep 21, 2023
@alaviss
Copy link
Owner

alaviss commented Sep 21, 2023

It is not easy to solve this because you can write something like this:

var
  foo: int
# comment
  bar: int

And it'd still be valid code.

Comments are not treated as a part of the structure, so we can only say that a structure ended when we see code that is outside of that structure.

Technically, we can do some very fancy lookahead to emit a block close at that comment, but tree-sitter architecture is not optimized for this and would require a lot of work to implement this.

@aMOPel
Copy link
Contributor Author

aMOPel commented Sep 21, 2023

It's fine then. Just something I noticed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request low severity This issue is not prioritized
Projects
None yet
Development

No branches or pull requests

2 participants