Add inline variable refactoring - #2754
Conversation
ahoppen
left a comment
There was a problem hiding this comment.
Thanks for tackling this, @somiljain2006. I left a few suggestions inline.
ahoppen
left a comment
There was a problem hiding this comment.
Thanks! Looks a lot simpler now already. I have left a few more suggestions inline.
ahoppen
left a comment
There was a problem hiding this comment.
I have a couple more nitpicky comments comments, otherwise looks great to me 👍🏽
ahoppen
left a comment
There was a problem hiding this comment.
One last nitpick, then we’re ready to ship.
|
@swift-ci Please test |
|
@ahoppen I'm having trouble identifying the exact cause of the Windows CI failure. The build fails during CMake generation because the SwiftSyntax::SwiftLexicalLookup target cannot be found. I checked the top-level CMakeLists.txt, where SwiftSyntax is already brought in with find_package(SwiftSyntax CONFIG REQUIRED), but I haven't been able to figure out whether the issue is with how the dependency is declared in SourceKit-LSP or with the SwiftSyntax CMake package used by the Windows Stage2 toolchain. Can you tell me what I'm missing? |
|
Seems like we need to expose |
…ULES` It seems like we can’t reference `SwiftLexicalLookup` from CMake in SourceKit-LSP because it’s not in this list. `SwiftLexicalLookup` will be used by swiftlang/sourcekit-lsp#2754, so we need to expose it.
|
The Windows issue should be fixed now. Let's try again. @swift-ci Please test Windows |
|
@ahoppen How about extending the inline variable code action to support var declarations? |
|
I don’t think extending it to |
|
@ahoppen I was thinking of this approach: only offer the action when the variable has an initializer and all resolved references are read-only. I would reject direct mutations (=, +=, etc.), inout uses such as &x, and any cases where a known mutation pattern is detected. More complex cases like closure captures and mutable pointer APIs could remain unsupported initially. |
|
I think I personally think that this would be a fairly big investment to do correctly with marginal pay-offs, so I wouldn’t do it. |
Fixes #2507
Implements Inline Variable for local let declarations with lexical lookup