-
Notifications
You must be signed in to change notification settings - Fork 302
Issues on Windows Swift 5.9 #982
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
Comments
Tracked in Apple’s issue tracker as rdar://118923500 |
TL;DR: It appears that some requests like code completion can sometimes produce very large responses that exceed 64KB and for some reason the transport layer cannot handle this (still to be investigated). As a workaround you can add the following to settings.json, which limits the response size and should work around the issue that code completion hits this maximum response size limit. "swift.sourcekit-lsp.serverArguments": ["--code-completion-max-results", "100"] Let’s use swiftlang/vscode-swift#646 as the basis for this issue because it is the most reduced example and I have been able to reproduce it. While writing this, this has migrated from being a response to more of a journal of my debug process. ReproducerI was able to reproduce the issue by having a single Swift file (not a Swift package), that contains import Foundation
let a = "". My settings are as follows {
"swift.path": "C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin",
"swift.SDK": "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\SDKs\\Windows.sdk",
"swift.swiftEnvironmentVariables": {
"SOURCEKIT_LOGGING": "3"
}
} Installed Swift version: 5.9.1 Open AnalysisLooking at the LSP log output, there three notable pieces:
This leads me to believe that there’s something funny going on with the process communication between sourcekit-lsp and VS Code and for some reason sourcekit-lsp can’t send any more information to VS Code. All following requests fail in the same way. For example, if you change the contents of the file to struct Foo {}
let x: Foo And go to definition on Interestingly, Possible failure reasonsAFAICT the communication channel could break in two ways:
Limiting number of code completion resultsWhen limiting the code completion results by adding the following snippet to "swift.sourcekit-lsp.serverArguments": ["--code-completion-max-results", "134"] Inspecting the 135th result in the code completion response revealed … that it wasn’t anything special, no Unicode characters or anything. With that insight, I was also able to reproduce the issue by setting the max code completion results to 500 and completing after So it appears that we are exceeding some limit that we can send to VS Code. And indeed, it turns out that the 135 results for the string completion take 63.97KB. If we add the Checking if we are hitting some OS limit on number of bytes we can sendIt doesn’t appear to be a import Dispatch
import struct CDispatch.dispatch_fd_t
import Foundation
let realStdout = dup(STDOUT_FILENO)
if realStdout == -1 {
fatalError("failed to dup stdout: \(strerror(errno)!)")
}
if dup2(STDERR_FILENO, STDOUT_FILENO) == -1 {
fatalError("failed to redirect stdout -> stderr: \(strerror(errno)!)")
}
let outFD = FileHandle(fileDescriptor: realStdout, closeOnDealloc: false)
let sendQueue: DispatchQueue = DispatchQueue(label: "jsonrpc-send-queue", qos: .userInitiated)
let rawOutFD = dispatch_fd_t(bitPattern: outFD._handle)
let sendIO = DispatchIO(type: .stream, fileDescriptor: rawOutFD, queue: sendQueue) { (error: Int32) in
print(error)
}
var dispatchData = DispatchData.empty
let str = String(repeating: "a", count: 65 * 1024)
str.utf8.map{$0}.withUnsafeBytes {
dispatchData.append($0)
}
let group = DispatchSemaphore(value: 0)
sendIO.write(offset: 0, data: dispatchData, queue: sendQueue) { done, _, errorCode in
group.signal()
}
group.wait() Has this issue already been fixed?
Next steps
|
@compnerd is there a release with these changes? |
The |
This should be fixed by swiftlang/swift-corelibs-libdispatch#802. Let’s close this issue. |
I think what you’re seeing is swiftlang/swift-corelibs-libdispatch#820. |
The vscode-swift repo has received a number of issues related to sourcekit-lsp crashing on Windows with swift 5.9. These include
swiftlang/vscode-swift#612 high CPU usage at start up and then auto-complete not working
swiftlang/vscode-swift#646 SourceKit-LSP stops responding after a few seconds
swiftlang/vscode-swift#561 SourceKit Language Server emits errors, autocomplete doesn't work
The text was updated successfully, but these errors were encountered: