VSC w/ ESP-IDF: how do I configure LSP to have autocompletion for bridged headers?

Hi :wave: I wonder if it's somehow possible to have autocompletion I get for regular Swift code:

but for the C functions imported in BridgingHeader.h, like led_driver_set_brightness() or led_driver_set_saturation(). Per Using SourceKit-LSP with Embedded Projects I've attempted to specify -import-bridging-header to the LSP like so, but I couldn't get it working.

.vscode/settings.json:

"swift.buildArguments": ["-import-bridging-header", "/Users/[redacted]/swift-matter-examples/led-blink/main/BridgingHeader.h"]

or via .sourcekit-lsp/config.json:

{
  "swiftPM": {
    "swiftCompilerFlags": "-import-bridging-header", "/Users/[redacted]/swift-matter-examples/led-blink/main/BridgingHeader.h"]
  }
}

Not sure if that matters, but I am able to successfully compile and upload the blink example to my ESP32C6. As far as I remember, in Xcode the autocomplete does suggest things imported through bridging header, so my guess is that it should be possible. Any help would be greatly appraciated.

5 Likes

any updates after the new release of VS Code extension?

IDK don't know if this works on the embedded headers, but if you add something like this with your SDK name, it might work same as Static Linux build:

{
  "swiftPM": {
    "swiftSDK": "x86_64-swift-linux-musl"
  }
}

in VSCode project, named .sourcekit-lsp/config.json