VS Code extension is failing. How to debug a cause?

Hi. I am getting the following when I hover over variables:

let protected: <<error type>>

and I am getting nothing at all on most functions I hover.

It will sometime detect the types, but rarely. Sometimes it will show 'loading' briefly and then it will stop showing anything.

The output console says:

21:58:21: SourceKit-LSP setup
21:58:21: Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)
21:58:21: Failed to find /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lldb-vscode
21:58:23: MiniFrame.Server: add: /Users/russ/Projects/MiniFrame.Server
21:58:23: MiniFrame.Server: Resolving Dependencies ... 21:58:23: MiniFrame.Server: focus: /Users/russ/Projects/MiniFrame.Server
21:58:24: MiniFrame.Server: Test Discovery Failed: error: terminated(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/libexec/swift/pm/swiftpm-xctest-helper /Users/russ/Projects/MiniFrame.Server/.build/x86_64-apple-macosx/debug/MiniFrame.ServerPackageTests.xctest /var/folders/l3/r5mnb0zs1vs62xwj7zzbx9p00000gn/T/TemporaryFile.4c9zNy output:
    error: unableToLoadBundle("/Users/russ/Projects/MiniFrame.Server/.build/x86_64-apple-macosx/debug/MiniFrame.ServerPackageTests.xctest")
    

done.

How should I proceed? After all, it used to open normally just a few days ago. This is a Vapor project, btw. Also, it works fine in Xcode.

swift -version

swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)
Target: x86_64-apple-macosx14.0
xcodebuild -version

Xcode 15.0.1
Build version 15A507
VS Code Help: About

Version: 1.83.1
Commit: f1b07bd25dfad64b0167beb15359ae573aecd2cc
Date: 2023-10-10T23:46:55.789Z
Electron: 25.8.4
ElectronBuildId: 24154031
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Darwin x64 23.0.0
Swift Extension: v1.7.0

Thanks for your time.

I have seen this recently as well. I think it might be an issue with the Intel Mac version of SourceKit-LSP. I haven’t had time to investigate further yet.

I am afraid, it is not limited to Intel Macs. I managed to test it on M1 mac today and I got exactly the same result. Very sad. :frowning:

I assume you built the project beforehand. Sometimes it takes a little time after the build before SourceKit-LSP returns results.

You could add an issue to the SourceKit-LSP repo with the full sourcekit-lsp log. To get a log

  • Set the setting swift.sourcekit-lsp.trace.server to verbose.
  • Restart VSCode
  • Perform action that isn’t working
  • Go to output pane and select SourceKit-LSP and copy contents of log into your issue.

I enabled the tracing and copied the output after a hover over a variable:

[Trace - 14:55:40] Sending request 'textDocument/hover - (11)'.
Params: {
    "textDocument": {
        "uri": "file:///Users/ruslan/Projects/MiniFrame.Server/Sources/App/Controllers/AuthController.swift"
    },
    "position": {
        "line": 38,
        "character": 19
    }
}


[Trace - 14:55:40] Received response 'textDocument/hover - (11)' in 10ms.
Result: {
    "contents": {
        "value": "protected\n```swift\nlet protected: <<error type>>\n```\n\n---\n",
        "kind": "markdown"
    }
}


[Trace - 14:56:03] Sending request 'textDocument/diagnostic - (12)'.
Params: {
    "textDocument": {
        "uri": "file:///Users/ruslan/Projects/MiniFrame.Server/Sources/App/Controllers/AuthController.swift"
    }
}


[Trace - 14:56:03] Received response 'textDocument/diagnostic - (12)' in 3ms.
Result: {
    "kind": "full",
    "items": []
}

And here is the result on hover over a function:

[Trace - 14:59:20] Sending request 'textDocument/hover - (13)'.
Params: {
    "textDocument": {
        "uri": "file:///Users/ruslan/Projects/MiniFrame.Server/Sources/App/Controllers/AuthController.swift"
    },
    "position": {
        "line": 41,
        "character": 52
    }
}


[Trace - 14:59:21] Received response 'textDocument/hover - (13)' in 379ms.
No result returned.

It does not seem like it is enough to debug an issue and the entire output of the swift extension by the time I opened a single file and hovered was already around 29000 lines.

Should I post the entire 29 000 lines of output? Can I do anything else to help debugging this issue?

I will create a GitHub issue in the meantime.

1 Like

Here is the issue for those who are interested: https://github.com/swift-server/vscode-swift/issues/632

Just a small update. I managed to replicate an issue accidentally in a new and empty Vapor project by writing an invalid swift struct+function call (which was not reported by the extension as an error) but was causing my build to fail.

However, my current code base compiles and works fine in Xcode, and yet it seems to trigger an error in the lsp somehow.

Finally, I just want to mention that every time I reopen VS Code, it triggers Resolve Package Dependencies and it always takes quite some time. The extension is only showing Loading... while this is happening.

PS. I should have opened an issue in LSP repository indeed. I will open an issue there as soon as I can.

When it says loading it is calling swift package describe. It needs this to generate launch profiles, build tasks and various other things. Once this has finished it will trigger a swift package resolve and a swift package plugin --list to ensure all your dependencies are downloaded and it has a list of plugins available. If you don't want the resolve or plugin list then there is a swift.disableAutoResolve setting to disable it.

1 Like

Hi. I just wanted to let you know that I tried:

swift package reset
swift package resolve
swift package build

And then restarting VS Code, and it fixed my issue. Hinting works as expected.

Furthermore, opening files was returning -32802 error code from the LSP for the inlay hints command. Lastly, I can say that I recently migrated the project to 5.9 from 5.8, but I do not remember when exactly I started having LSP issues. I suspect that something changed in the incremental build process, which consequently broke the LSP.

I will soon close the issue in the extension repository, explaining that fully cleaning the build folder helped with the problem and that the problem is likely related to a change in the swift tools version.