[IDE][Parse] Fix syntax coloring ranges for type attributes #26418
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.
When looking for the
SyntaxNode
corresponding to a type attribute (like@escaping
),ModelASTWalker
would look for one whose range started at the type attribute's source location. It never found one, though, because theSyntaxNode
's range included the@
, while the type attribute's source location pointed to the name after the@
. The result was that type attribute tokens were highlighted as unknown, rather than built-in attributes. This PR changes type attribute source locations to point to the@
rather than the name (which matches the start location ofDeclAttribute
s too). This PR also fixes a bug I noticed where the fixit for removing@escaping
on non-function types would compute the incorrect range for the attribute.TypeAttributes
would ideally keepSourceLoc
s for both the@
and the attribute name since things like@ /*this is fine...*/ escaping
are valid. I didn't do that since it represents which attributes are on a type via a fixed-length array of SourceLocs, with one entry for every possible type attribute kind, where each SourceLoc's validity encodes whether the attribute is present or not. Extending this to a list of SourceRanges would work, but seemed like a waste of memory. Given that the@
is usually next to the attribute name, it's needed purely for syntax highlighting, and we'll hopefully be using the libSyntax tree to track source locations in future, I let that case be for now.