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

Fix comment indentation #143

Merged
merged 2 commits into from
Feb 18, 2025
Merged

Fix comment indentation #143

merged 2 commits into from
Feb 18, 2025

Conversation

zaneduffield
Copy link
Collaborator

Before this change, the parser would default to setting the level of
comments to the level of the current context, making an exception for
comments inside a 'subroutine' or 'type block' context. This exception
allows some comments to inherit the level of the next line.

This change fixes an issue where only the last comment in a series
would have this exception applied, and also flips the default handling
so that this 'exception' is actually the norm.

Usually, comments are 'supposed' to relate to what they precede, so we
should try to set the level of the comment to the next 'thing'. However
in some cases this makes little sense, because the next 'thing' may be a
token that only exists to end a block context (e.g. 'end'). So the new
exception is for comments in 'statement list' contexts to have the level
of the context, but everything else has the level of the next line.

Before this change, the parser would default to setting the level of
comments to the level of the current context, making an exception for
comments inside a 'subroutine' or 'type block' context. This exception
allows some comments to inherit the level of the next line.

This change fixes an issue where only the last comment in a series
would have this exception applied, and also flips the default handling
so that this 'exception' is actually the norm.

Usually, comments are 'supposed' to relate to what they precede, so we
should try to set the level of the comment to the next 'thing'. However
in some cases this makes little sense, because the next 'thing' may be a
token that only exists to end a block context (e.g. 'end'). So the new
exception is for comments in 'statement list' contexts to have the level
of the context, but everything else has the level of the next line.
Copy link
Collaborator

@jgardn3r jgardn3r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All in all, a fairly simple change. Love to see it.

@zaneduffield zaneduffield merged commit 9dfce54 into master Feb 18, 2025
5 checks passed
@zaneduffield zaneduffield deleted the fix-comment-levels branch February 18, 2025 05:16
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 this pull request may close these issues.

2 participants