perf!: don't look for indent/dedent if comment is at current indent level #244
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Whether an indent/dedent token is generated for a comment depends on
whether the indent/dedent is persisted after the comment. This takes
O(comment_length) to check. Checking it for every line takes
O(comment_length * comment_lines), which is quadratic.
An optimization was made in a901729 which skips this check when there
is no possible indent/dedent, such as in the following:
However, the check cannot be skipped in the following case:
which comes up when commenting out code.
This PR optimizes this case by skipping the check if the comment is at the
current indent length. In the above example,
# comment 1
looks aheadto
def bar()
and changes the indent length to 4, after which comments2-1000 do not look ahead, since they are also at indent length 4.
This PR does not optimize the following case:
but it does optimize:
BREAKING CHANGE: In the following scenario, we previously generated an
indent token before comment 1; we now generate it before comment 2.
This is more consistent with how dedents are handled.
Related: nvim-treesitter/nvim-treesitter#4839