SourceKit-LSP Loading the standard library failed

I'm exploring swift-embedded-examples and would like to have LSP features in VS Code.

When I open Application.swift file in stm32-uart-echo example project Swift extension features like code completion and jump to definition do not work. As I understand this features depend on sourcekit-lsp and I can see the errors in OUTPUT view in VS Code for SourceKit Language Server

[Error - 11:15:04] Request textDocument/hover failed.
  Message: sourcekitd request failed: error response (Request Failed): Loading the standard library failed
  Code: -32001

As far I as understand Embedded Swift does not include standard library, so this error might be expected.

I have toolchain path configured.
Here's my settings.json for VS Code

{
    "swift.swiftEnvironmentVariables": {
        "DEVELOPER_DIR": "/Applications/Xcode.app"
    },
    "swift.path": "/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-08-05-a.xctoolchain/usr/bin",
    "lldb.library": "/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-08-05-a.xctoolchain/System/Library/PrivateFrameworks/LLDB.framework/Versions/A/LLDB",
    "lldb.launch.expressions": "native"
}

Do I need to pass a configuration parameter to SourceKit-LSP for it to not try to load standard library ?

1 Like

I can reproduce this problem, and @ahoppen suggested we need a .sourcekit-lsp/config.json file to pass the right flags (that we use when building) to the SourceKit compilations, too. Let me open a PR for it: stm32-uart-echo: Add a .sourcekit-lsp/config.json file to pass triple (and other flags) to SourceKit compilations by kubamracek · Pull Request #47 · apple/swift-embedded-examples · GitHub

Would you be able to try it and see if that helps?

Yes, this solved the problem, thanks !
I did a clean checkout on pr branch and LSP features work.

By the way, the project builds successfully but I can see some errors highlighted in code like

Cannot use metatype of type 'RCC.AHB1ENR.ReadWrite' in embedded SwiftSourceKit

But I guess that's a different problem. Initial issue is resolved, thanks again !

2 Likes

Yes, that's a separate issue. I think I've seen it before, would you mind opening a Github issue for it?

Here's the GitHub issue #48

1 Like

Tried the latest downloadable toolchain and verified this is fixed now.