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

**URL:** <https://forums.swift.org/t/vsc-w-esp-idf-how-do-i-configure-lsp-to-have-autocompletion-for-bridged-headers/75292>\
**Category:** Embedded\
**Tags:** vscode, esp32, vscode-swift\
**Created:** [October 10, 2024, 9:12pm UTC](https://forums.swift.org/t/vsc-w-esp-idf-how-do-i-configure-lsp-to-have-autocompletion-for-bridged-headers/75292 "2024-10-10T21:12:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![3Qax](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/3qax/32/37700_2.png) [@3Qax](https://forums.swift.org/u/3Qax)\
**Post date:** [October 10, 2024, 9:12pm UTC](https://forums.swift.org/t/vsc-w-esp-idf-how-do-i-configure-lsp-to-have-autocompletion-for-bridged-headers/75292/1 "2024-10-10T21:12:03Z")

</div>

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

 ![Screenshot 2024-10-10 at 22.59.49](https://global.discourse-cdn.com/swift/original/3X/b/4/b41acd863c36002d5848ca426053915218d16af5.jpeg)

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](https://github.com/swiftlang/sourcekit-lsp/blob/main/Documentation/Using%20SourceKit-LSP%20with%20Embedded%20Projects.md) I've attempted to specify `-import-bridging-header` to the LSP like so, but I couldn't get it working.

_.vscode/settings.json_:

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

```

or via _.sourcekit-lsp/config.json_:

```swift
{
  "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.

---

<div class="post-metadata">

**Author:** ![tiye](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tiye/32/36941_2.png) [@tiye](https://forums.swift.org/u/tiye)\
**Post date:** [February 14, 2025, 5:30pm UTC](https://forums.swift.org/t/vsc-w-esp-idf-how-do-i-configure-lsp-to-have-autocompletion-for-bridged-headers/75292/2 "2025-02-14T17:30:04Z")

</div>

any updates after the new release of VS Code extension?

---

<div class="post-metadata">

**Author:** ![Amm0](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/amm0/32/39507_2.png) [@Amm0](https://forums.swift.org/u/Amm0)\
**Post date:** [February 14, 2025, 9:09pm UTC](https://forums.swift.org/t/vsc-w-esp-idf-how-do-i-configure-lsp-to-have-autocompletion-for-bridged-headers/75292/3 "2025-02-14T21:09:30Z")

</div>

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:

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

```

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

---

<div class="post-metadata">

**Author:** ![MisutaaAsriel](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/misutaaasriel/32/39978_2.png) [@MisutaaAsriel](https://forums.swift.org/u/MisutaaAsriel)\
**Post date:** [March 13, 2025, 2:34pm UTC](https://forums.swift.org/t/vsc-w-esp-idf-how-do-i-configure-lsp-to-have-autocompletion-for-bridged-headers/75292/4 "2025-03-13T14:34:45Z")

</div>

> [@VSCode: Bridging headers with Intellisense in simple Embedded Project](https://forums.swift.org/t/vscode-bridging-headers-with-intellisense-in-simple-embedded-project/78470/2):
>
> The problem you're running into here is that with the current setup, sourcekit-lsp has no way to know what settings to use for a particular file (so eg. `main.swift` here).
> 
> sourcekit-lsp has a few ways to retrieve this information - either through SwiftPM, a [compilation databases](https://clang.llvm.org/docs/JSONCompilationDatabase.html), or a custom [BSP server](https://github.com/swiftlang/sourcekit-lsp/blob/main/Contributor%20Documentation/Implementing%20a%20BSP%20server.md#implementing-a-bsp-server).
> 
> The second is what you're looking for in this case.
> 
> Unfortunately, there's no simple way to produce [compile\_commands.json](https://clang.llvm.org/docs/JSONCompilationDatabase.html#format) with Make (with CMake you can set `CMAKE_EXPORT_COMPILE_COMMANDS`). You could probably get away with using [compile\_flags.txt](https://clang.llvm.org/docs/JSONCompilationDatabase.html#alternatives) today, but I would recommend just manually crafting `compile_commads.json` instead:
> 
> 1. Remove `swift.sourcekit-lsp.serverArguments` from `.vscode/settings.json` - these are arguments to provide to the language server (sourcekit-lsp) on launch, not compilation arguments.
> 2. Remove `.sourcekit-lsp/config.json` - `swiftPM` is specifically for configuring SwiftPM projects further, which you don't have here.
> 3. Add a `compile_commands.json` next to your `makefile`:
> 
> ```swift
> [
> {
> "directory": "<Absolute path to project root>",
> "command": "swiftc <Relative path to main swift file> -enable-experimental-feature Embedded <Flags go here>",
> "file": "<Relative path to main swift file>"
> }
> ]
> 
> ```
> 
> 1. Open the workspace in VS Code

I asked a similar question here [elsewhere](https://forums.swift.org/t/vscode-bridging-headers-with-intellisense-in-simple-embedded-project/78470) in regards to another project that had a similar structure, albeit it uses makefiles instead of cmake.

TL:DR it appears that what we were trying was for SwiftPM project, which **we are not using.**

In your case, you appear to be using CMAKE, so you can seemingly, in fact, achieve autocomplete using `CMAKE_EXPORT_COMPILE_COMMANDS` to create the compilation database.

For those using makefiles, you apparently need to craft the compilation database `json` yourself.
