Skip to content

improve comment/node association #1770

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
josharian opened this issue Aug 12, 2023 · 1 comment
Open

improve comment/node association #1770

josharian opened this issue Aug 12, 2023 · 1 comment

Comments

@josharian
Copy link
Collaborator

We could start by stealing some of the Go heuristics, which definitely have some shortcomings but work well enough for common cases in practice:

A CommentGroup represents a sequence of comments with no other tokens and no empty lines between.

A comment group g is associated with a node n if:

  • g starts on the same line as n ends
  • g starts on the line immediately following n, and there is at least one empty line after g and before the next node
  • g starts before n and is not associated to the node before n via the previous rules

[It] tries to associate a comment group to the "largest" node possible: For instance, if the comment is a line comment trailing an assignment, the comment is associated with the entire assignment rather than just the last operand in the assignment.

@pokey
Copy link
Member

pokey commented Aug 12, 2023

Use cases:

  • "item" scope could include the comment associated with the item
  • Other scopes could include their associated comments

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