-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
7985dff
to
c3c5475
Compare
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) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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.
|
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 theTokens
struct and passed as an argument.Test Plan
cargo insta test