-
Notifications
You must be signed in to change notification settings - Fork 314
Handle new swift-syntax closure expansion behavior #1831
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
Conversation
Tests/SourceKitLSPTests/RewriteSourceKitPlaceholdersTests.swift
Outdated
Show resolved
Hide resolved
319f8bf
to
31fa3e9
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.
Thank you @woolsweater, great changes!
I only have a few comments, otherwise looks great.
Tests/SourceKitLSPTests/RewriteSourceKitPlaceholdersTests.swift
Outdated
Show resolved
Hide resolved
Tests/SourceKitLSPTests/RewriteSourceKitPlaceholdersTests.swift
Outdated
Show resolved
Hide resolved
31fa3e9
to
0eb410b
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.
Thanks. I just have two minor comments, otherwise this looks great.
return false | ||
} | ||
|
||
return token.keyPathInParent == \ClosureSignatureSyntax.inKeyword |
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 would move the check for token.keyPathInParent == \ClosureSignatureSyntax.inKeyword
to the top of the function because it’s an O(1) check vs the ancestorOrSelf
check, which needs to traverse the tree up to the root to determine that a token is not in a ClosureExprSyntax
.
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.
Good point; done!
import SwiftParser | ||
import SwiftSyntax | ||
import Swift | ||
@testable import SourceKitLSP |
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.
We build SourceKit-LSP with testability disabled in Swift CI because otherwise we would need to build everything twice: Once with testability enabled for testing and then with testability disabled to produce the binary we include in the toolchain. Could you change this to not use @testable
? We use @_spi(Testing)
to a similar effect where needed.
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.
Got it, updated. 🤔 I am not very familiar with how @_spi
works, but it seems to require everything including the imports to become public. Let me know if there is another way I should have done this.
0eb410b
to
f81206e
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.
Thanks. A small comment that you couldn’t have been aware of regarding the imports.
public import SwiftSyntax | ||
public import SwiftBasicFormat |
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.
We need to support building with a Swift 5.10 compiler as well, which doesn’t support the access level imports.
public import SwiftSyntax | |
public import SwiftBasicFormat | |
#if compiler(>=6.0) | |
public import SwiftSyntax | |
public import SwiftBasicFormat | |
#else | |
import SwiftSyntax | |
import SwiftBasicFormat | |
#endif |
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.
Done!
/// lines. | ||
@_spi(Testing) | ||
public class ClosureCompletionFormat: BasicFormat { | ||
public override func requiresNewline(between first: TokenSyntax?, and second: TokenSyntax?) -> Bool { |
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 would add @_spi(Testing)
here as well, just to be clear that it’s not a properly public declaration.
public override func requiresNewline(between first: TokenSyntax?, and second: TokenSyntax?) -> Bool { | |
@_spi(Testing) public override func requiresNewline(between first: TokenSyntax?, and second: TokenSyntax?) -> Bool { |
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.
Makes sense; done!
f81206e
to
92a674e
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.
Looking good. Thanks for implementing this and following up on my review comments.
@swift-ci Please test |
//===----------------------------------------------------------------------===// | ||
|
||
import SKTestSupport | ||
@testable import SourceKitLSP |
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.
Shoot, I missed this other @testable
import last night. Does this need to be changed as well @ahoppen ?
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.
Yes, we can’t have @testable
imports.
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.
Fixed!
92a674e
to
be3eeda
Compare
@swift-ci Please test |
be3eeda
to
58ecdcc
Compare
@swift-ci Please test |
@swift-ci Please test Windows |
58ecdcc
to
a714d41
Compare
Updated just now to appease the linter. |
@swift-ci Please test |
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.
Could you add this file to CMakeLists.txt. We use CMake to build SourceKit-LSP on Windows.
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.
Done!
This resolves <swiftlang#1788>, following the discussion of alternatives on <https://github.com/swiftlang/sourcekit-lsp/pulls/1789>. The bulk of the change updates the translation from SourceKit placeholders to LSP placeholders to handle nesting. The `CodeCompletionSession` also passes a new custom formatter to the swift-syntax expansion routine, which disables the transformation to trailing closures.
a714d41
to
60beed8
Compare
@swift-ci Please test |
@swift-ci Please test Windows |
Thank you for shepherding these changes, @ahoppen ! 🙌 |
This resolves #1788, following the discussion of alternatives on https://github.com/swiftlang/sourcekit-lsp/pulls/1789. The bulk of the change updates the translation from SourceKit placeholders to LSP placeholders to handle nesting, which is implemented in swiftlang/swift-syntax#2897
closure-expansion.mov