-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[SourceKit] Add CollectVariableType
request
#37867
Conversation
585c6cb
to
43b6c0a
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.
Mostly looking good to me. I’ve added some questions and comments inline.
Thanks for the feedback, I've followed the implementation of |
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.
Sorry for the delay, I only now managed to look through the code. Unfortunately, after looking at the implementation of the new TypeVariableArray
, I remembered why we needed the approach with the output stream + offsets in ExpressionTypeArrayBuilder
and I think it’s also necessary for VariableTypeArray
😬. Sorry for the back and forth about this.
b21d042
to
0c79595
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.
And I’ve got some more comments inline.
I have updated the implementation to use |
- Add VariableTypeCollector This new SourceEntityWalker collects types from variable declarations. - Add SwiftLangSupport::collectVariableTypes - Implement CollectVariableType request - Provide information about explicit types in CollectVarType - Fix HasExplicitType in VariableTypeArray - Fix typo - Implement ranged CollectVariableTypes requests - Use offset/length params for CollectVariableType in sourcekitd-test - Address a bunch of PR suggestions - Remove CanonicalType from VariableTypeCollector This turned out not to be needed (for now). - Improve doc comment on VariableTypeCollector::getTypeOffsets - Remove unused CanonicalTy variable - Remove out-of-date comment - Run clang-format on the CollectVariableType implementation - Fix some minor style issues - Use emplace_back while collecting variable infos - Pass CollectVariableType range to VariableTypeCollector - Use capitalized variable names in VariableTypeArray ...as recommended by the LLVM coding standards - Use PrintOptions for type printing in VariableTypeCollector - Return void for collectVariableType This seems to be cleaner stylistically. - Avoid visiting subranges of invalid range in VariableTypeCollector - Use std::string for type buffer in VariableTypeCollectorASTConsumer - Use plural for PrintedType in VariableTypeArray - Remove unused fields in VariableTypeArrayBuilder - Add suggested doc comments to VariableTypeArray - Remove unused VariableTypeInfo.TypeLength - Fix typo of ostream in VariableTypeCollectorASTConsumer - Fix typo - Document Offset and Length semantics in collectVariableTypes
- Add CollectVariableType test for function/closure parameters - Test ranged CollectVariableType request - Add separate test for ranged CollectVariableType - Use line:col positions in sourcekitd-test for var types - Add test case for CollectVariableType and inout params - Update ranged CollectVariableType test ...as per the PR suggestions. - Fix style issue
- Add SourceRange::contains and SourceRange::overlaps - Use SourceRange in VariableTypeCollector
93630fe
to
7a73c99
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.
I’ve got some minor comments regarding variable names and doc comments again. Other than that, it’s looking great. Can’t wait to try this out with the editor.
Also add a test to verify that error types get ignored (as intended).
Rename VariableTypeCollector::getTypeOffsets to ::getTypeOffset and only return the start offset, since the end offset is no longer needed (the string is null-terminated). Also improve variable naming slightly.
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.
Nice! Let’s get this 🚢ed.
@swift-ci Please smoke test |
To provide accurate support for inlay type hints in SourceKit-LSP (see swiftlang/sourcekit-lsp#406 for details), this PR introduces a new request called
CollectVariableType
. Although similar toCollectExpressionType
, the new request provides types for variable declarations and closure parameters specifically, together with the identifiers' ranges and a flag stating whether there already exists an explicit type annotation.Example
yields the following response:
Additions to the SourceKit protocol
The request looks like this:
The response looks like this:
Implementation Progress
VariableTypeCollector
that traverses AST and collects variable type informationkey.offset
,key.length
)