VSCode: Bridging headers with Intellisense in simple Embedded Project

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, or a custom BSP server.

The second is what you're looking for in this case.

Unfortunately, there's no simple way to produce compile_commands.json with Make (with CMake you can set CMAKE_EXPORT_COMPILE_COMMANDS). You could probably get away with using compile_flags.txt 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:
[
  {
    "directory": "/[ ... REDACTED ... ]/HelloWorld",
    "command": "swiftc source/main.swift -enable-experimental-feature Embedded -target armv7em-none-none-eabi -no-allocations -import-objc-header source/Bridging-Header.h -I /opt/devkitPro/DEVKITARM/include -I /opt/devkitPro/DEVKITARM/arm-none-eabi/include -I /opt/devkitPro/libctru/include",
    "file": "source/main.swift"
  }
]
  1. Open the workspace in VS Code
3 Likes