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

leading comment not considered part of function body #112

Open
orph opened this issue Jul 23, 2021 · 1 comment
Open

leading comment not considered part of function body #112

orph opened this issue Jul 23, 2021 · 1 comment

Comments

@orph
Copy link

orph commented Jul 23, 2021

I would expect the comment to be part of the body in both these cases.

Screen Shot 2021-07-23 at 5 57 15 PM

Screen Shot 2021-07-23 at 5 59 58 PM

If this is intended, is there a good strategy to consider a leading comment as part of the body? If no body, check the node following the function_definition is a comment, and if there is a body check if previous siblings are comments?

@niklaskorz
Copy link

niklaskorz commented Feb 25, 2022

The same bug applies to the body blocks of with statements unfortunately. Consider:

with managed_resource(timeout=3600) as resource:
     # Resource is released at the end of this block,
     # even if code in the block raises an exception
     a = 42
     # hello
     b = 19

The first two comment lines will be put between the with_clause and body: block, while the third comment is part of the body. The grammar cannot be the issue, as it only allows a block to follow the with clause and the colon:

    "with_statement": {
      "type": "SEQ",
      "members": [
        {
          "type": "CHOICE",
          "members": [
            {
              "type": "STRING",
              "value": "async"
            },
            {
              "type": "BLANK"
            }
          ]
        },
        {
          "type": "STRING",
          "value": "with"
        },
        {
          "type": "SYMBOL",
          "name": "with_clause"
        },
        {
          "type": "STRING",
          "value": ":"
        },
        {
          "type": "FIELD",
          "name": "body",
          "content": {
            "type": "SYMBOL",
            "name": "_suite"
          }
        }
      ]
    },

I suppose this bug is part of tree-sitter itself?

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

No branches or pull requests

2 participants