Use CommentRanges from the parsed output#11591
Use CommentRanges from the parsed output#11591dhruvmanila merged 2 commits intodhruv/parser-phase-2from
CommentRanges from the parsed output#11591Conversation
f1d51f8 to
b52b83c
Compare
12c3707 to
d49b4fc
Compare
b52b83c to
436f6a5
Compare
d49b4fc to
817ef3e
Compare
MichaReiser
left a comment
There was a problem hiding this comment.
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.
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.
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
CommentRangesfrom theIndexerto the parsed output.First, the
CommentRangesare 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
CommentRangeswhile 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:
CommentRangesare passed in the type directlyProgram, then the program is passed instead