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

Build CommentRanges outside the parser #11792

Merged
merged 4 commits into from
Jun 9, 2024
Merged

Conversation

dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Jun 7, 2024

Summary

This PR updates the parser to remove building the CommentRanges and instead it'll be built by the linter and the formatter when it's required.

For the linter, it'll be built and owned by the Indexer while for the formatter it'll be built from the Tokens struct and passed as an argument.

Test Plan

cargo insta test

@dhruvmanila dhruvmanila force-pushed the dhruv/lazy-comment-ranges branch from 7985dff to c3c5475 Compare June 7, 2024 04:48
Comment on lines +513 to +524
impl From<&Tokens> for CommentRanges {
fn from(tokens: &Tokens) -> Self {
let mut ranges = vec![];
for token in tokens {
if token.kind() == TokenKind::Comment {
ranges.push(token.range());
}
}
CommentRanges::new(ranges)
}
}

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is a better approach to create CommentRanges instead of CommentRangesBuilder. This is the primary way of building the CommentRanges outside the linter. In the linter, the Indexer creates it because it's already looping over the tokens.

Copy link
Contributor

github-actions bot commented Jun 7, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@dhruvmanila dhruvmanila added the internal An internal refactor or improvement label Jun 7, 2024
@dhruvmanila dhruvmanila marked this pull request as ready for review June 7, 2024 09:15
@dhruvmanila dhruvmanila requested a review from MichaReiser as a code owner June 7, 2024 09:15
@dhruvmanila dhruvmanila enabled auto-merge (squash) June 9, 2024 09:52
@dhruvmanila dhruvmanila merged commit 549cc1e into main Jun 9, 2024
18 checks passed
@dhruvmanila dhruvmanila deleted the dhruv/lazy-comment-ranges branch June 9, 2024 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal An internal refactor or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants