-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Use CommentRanges
from the parsed output
#11591
Conversation
f1d51f8
to
b52b83c
Compare
12c3707
to
d49b4fc
Compare
b52b83c
to
436f6a5
Compare
d49b4fc
to
817ef3e
Compare
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.
Nevertheless, the struct will be owned by the parsed output. So, all references should now use the struct from the parsed output instead of the indexer.
I'm not sure if this will remain true if we build the comment ranges after parsing. One of the benefits of building it after parsing is that we can make it optional and only run it when the comment ranges are needed.
if !checker | ||
.indexer() | ||
.program() | ||
.comment_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 case where it could make sense to simply expose comment_ranges
on checker
so that it matters less where the comment ranges are actually stored. I don't think it is necessary to change now but it would e.g. help if we move comment ranges in the future again.
Overall, I think this is a weakness of our checker
API. Lint rules need to know too much about individual representations. I think it would be better if there's a single context
and the rules could simply ask:
- Give me the comment ranges
- give me the indexer
- give me the line index
etc. without having to do deep drilling.
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.
Yeah, I completely agree with your sentiment.
## Summary This PR updates the usages of `CommentRanges` from the `Indexer` to the parsed output. First, the `CommentRanges` are now built during the parsing step. In the future, depending on the performance numbers, it could be updated to be done after the parsing step. Nevertheless, the struct will be owned by the parsed output. So, all references should now use the struct from the parsed output instead of the indexer. Now, the motivation to build `CommentRanges` while parsing is so that it can be shared between the linter and the formatter as both requires it. This also removes the need to have a dedicated method (`tokens_and_ranges`). There are two main updates: 1. The functions which only require `CommentRanges` are passed in the type directly 2. If the functions require other fields from `Program`, then the program is passed instead
## Summary This PR updates the usages of `CommentRanges` from the `Indexer` to the parsed output. First, the `CommentRanges` are now built during the parsing step. In the future, depending on the performance numbers, it could be updated to be done after the parsing step. Nevertheless, the struct will be owned by the parsed output. So, all references should now use the struct from the parsed output instead of the indexer. Now, the motivation to build `CommentRanges` while parsing is so that it can be shared between the linter and the formatter as both requires it. This also removes the need to have a dedicated method (`tokens_and_ranges`). There are two main updates: 1. The functions which only require `CommentRanges` are passed in the type directly 2. If the functions require other fields from `Program`, then the program is passed instead
## Summary This PR updates the usages of `CommentRanges` from the `Indexer` to the parsed output. First, the `CommentRanges` are now built during the parsing step. In the future, depending on the performance numbers, it could be updated to be done after the parsing step. Nevertheless, the struct will be owned by the parsed output. So, all references should now use the struct from the parsed output instead of the indexer. Now, the motivation to build `CommentRanges` while parsing is so that it can be shared between the linter and the formatter as both requires it. This also removes the need to have a dedicated method (`tokens_and_ranges`). There are two main updates: 1. The functions which only require `CommentRanges` are passed in the type directly 2. If the functions require other fields from `Program`, then the program is passed instead
Summary
This PR updates the usages of
CommentRanges
from theIndexer
to the parsed output.First, the
CommentRanges
are now built during the parsing step. In the future, depending on the performance numbers, it could be updated to be done after the parsing step. Nevertheless, the struct will be owned by the parsed output. So, all references should now use the struct from the parsed output instead of the indexer.Now, the motivation to build
CommentRanges
while parsing is so that it can be shared between the linter and the formatter as both requires it. This also removes the need to have a dedicated method (tokens_and_ranges
).There are two main updates:
CommentRanges
are passed in the type directlyProgram
, then the program is passed instead