Code completion not available in Swift Embedded project #968
Replies: 8 comments 12 replies
-
Hi I've been exploring Swift Embedded with Matter as well and faced issues with code completion in VSCode. One approach that has helped me is ensuring the Swift Language Server (SourceKit-LSP) is correctly configured:
Additionally, verify if there are any specific configurations needed for the embedded environment you're using. The sample project you mentioned seems complex, so ensuring all dependencies and environment variables are correctly set is crucial. Here’s the link to the SourceKit-LSP repository for more detailed setup instructions: https://github.com/apple/sourcekit-lsp. I hope this information helps! If you discover any other solutions or need further assistance, please feel free to share. |
Beta Was this translation helpful? Give feedback.
-
I tried to get this working today, unsuccessfully. I've been working with apple/swift-embedded-examples:esp32-led-blink-sdk. I found adding {
"configurations": [
{
"name": "ESP-IDF",
"compilerPath": "/Users/brianhenry/.espressif/tools/riscv32-esp-elf/esp-12.2.0_20230208/riscv32-esp-elf/bin/riscv32-esp-elf-gcc",
"compileCommands": "${config:idf.buildPath}/compile_commands.json",
"includePath": [
"${config:idf.espIdfPath}/components/**",
"${workspaceFolder}/**"
],
"browse": {
"path": [
"${config:idf.espIdfPath}/components",
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true
}
}
],
"version": 4
} got the ESP library code completion working in my
but I learned there is a My I could be wrong, but I think it's a two-step compile process where the output of the original step is overwritten by the second. I spent a while trying to create a SPM package with the ESP library as a submodule.
Package.json// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "swift-esp32-wrapper",
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "swift-esp32-wrapper",
targets: ["swift-esp32-wrapper"]),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "swift-esp32-wrapper"
),
.executableTarget(
name: "CESPIDF",
dependencies: [],
exclude: [
// Relative paths under 'CMyLib' of the files
// and/or directories to exclude. For example:
// "./my-lib/src/CMakeLists.txt",
// "./my-lib/tests",
],
sources: [
// "esp-idf/components/app_trace",
// "esp-idf/components/app_update",
// "esp-idf/components/bootloader",
// "esp-idf/components/bootloader_support",
// "esp-idf/components/bt",
// "esp-idf/components/cmock",
// "esp-idf/components/console",
// "esp-idf/components/cxx",
// "esp-idf/components/driver",
// "esp-idf/components/efuse",
// "esp-idf/components/esp-tls",
// "esp-idf/components/esp_adc",
// "esp-idf/components/esp_app_format",
// "esp-idf/components/esp_coex",
// "esp-idf/components/esp_common",
// "esp-idf/components/esp_eth",
// "esp-idf/components/esp_event",
// "esp-idf/components/esp_gdbstub",
// "esp-idf/components/esp_hid",
// "esp-idf/components/esp_http_client",
// "esp-idf/components/esp_http_server",
// "esp-idf/components/esp_https_ota",
// "esp-idf/components/esp_https_server",
// "esp-idf/components/esp_hw_support",
// "esp-idf/components/esp_lcd",
// "esp-idf/components/esp_local_ctrl",
// "esp-idf/components/esp_mm",
// "esp-idf/components/esp_netif",
// "esp-idf/components/esp_netif_stack",
// "esp-idf/components/esp_partition",
// "esp-idf/components/esp_phy",
// "esp-idf/components/esp_pm",
// "esp-idf/components/esp_psram",
// "esp-idf/components/esp_ringbuf",
// "esp-idf/components/esp_rom",
// "esp-idf/components/esp_system",
// "esp-idf/components/esp_timer",
// "esp-idf/components/esp_wifi",
// "esp-idf/components/espcoredump",
// "esp-idf/components/esptool_py",
// "esp-idf/components/fatfs",
// "esp-idf/components/freertos",
// "esp-idf/components/hal",
// "esp-idf/components/heap",
// "esp-idf/components/http_parser",
// "esp-idf/components/idf_test",
// "esp-idf/components/ieee802154",
// "esp-idf/components/json",
// "esp-idf/components/log",
// "esp-idf/components/lwip",
// "esp-idf/components/mbedtls",
// "esp-idf/components/mqtt",
// "esp-idf/components/newlib",
// "esp-idf/components/nvs_flash",
// "esp-idf/components/openthread",
// "esp-idf/components/partition_table",
// "esp-idf/components/protobuf-c",
// "esp-idf/components/protocomm",
// "esp-idf/components/pthread",
// "esp-idf/components/riscv",
// "esp-idf/components/sdmmc",
// "esp-idf/components/soc",
// "esp-idf/components/spi_flash",
// "esp-idf/components/spiffs",
// "esp-idf/components/tcp_transport",
// "esp-idf/components/ulp",
// "esp-idf/components/unity",
// "esp-idf/components/usb",
// "esp-idf/components/vfs",
// "esp-idf/components/wear_levelling",
// "esp-idf/components/wifi_provisioning",
// "esp-idf/components/wpa_supplicant"
],
cSettings: [
.headerSearchPath(
"esp-idf/components/freertos/FreeRTOS-Kernel/include"
),
.unsafeFlags(["-w"]), // Disable all warnings
],
swiftSettings: [
// To mute warning about "... was identified as an executable target given the presence of a 'main' file."
.unsafeFlags(["-parse-as-library"])
]
),
]
) What I think I'm working towards is a point where Swift Package Manager thinks it knows enough to build the project, but ESP-IDF extension actually builds the artifact that is deployed. AIUI there are two ways to get Swift-LSP to understand a project – a CMake outputted This looks promising for the first approach – jerrymarino/SwiftCompilationDatabase – but I've been working on this all day (Saturday) and I'm getting tired!
I installed the ESP VS Code extension and it installed the ESP library which contained its own copy of Python which worked for me. It's important to And regularly check I had to add @plemarquand , has anyone had code completion working for embedded yet? I don't think it's a "problem" with DevSrSouza's setup, I think it's a new configuration we need a solution for. That said, I did learn a bit from the files that were shared. @adam-fowler I'm pretty sure the original answer was Chat GPT generated. |
Beta Was this translation helpful? Give feedback.
-
I've used Embedded Swift with VSCode, and documented my experience in this repo: Last time I ran the project has been two months ago, so some things might have changed a little bit. But I think that this should give some insight into what's needed to get up and running. I've had to quite carefully craft my CMakeLists.txt. Most notably, I needed specific policies to use SourceKit-LSP and export the compile commands. Without those the IDE's functionally is reduced to just text highlighting. The Compile Commands are essential, and if you experience any issues I recommend opening the file to see if the paths make sense. Some (olderr) builds of CMake or the Swift compiler don't work together well enough, and the paths become nonsensical and thus unsable for VSCode. Once it's set up though, VSCode can follow code between Swift, C and C++ all the same. |
Beta Was this translation helpful? Give feedback.
-
Thanks @Joannis. That's optimistic but I wasn't able to get your repo to build! I keep getting:
although I think that should be built by the command
Full CMake build output
I did make some minor changes to CMakeLists.txt
I'd appreciate any help. I've very little experience with CMake. Besides that, I tried jerrymarino/SwiftCompilationDatabase but I wasn't able to capture the output of I learned a lot from a reply by @etcwilde on How to use SourceKit-LSP to develop the Swift compiler repo? where I tried to use Another copy of the project where I was trying to restructure the project as a Swift Package Manager project does have code-navigation between Swift-to-Swift and C-to-C but not from Swift to C. As I tried adding the C sources to Swift Package Manager, the build time became extremely long and I still didn't get the code-navigation as I wanted. @adam-fowler Am I correct to think vscode-swift should read both SPM's output and CMake's I even ordered a RPi Pico for this but Amazon "failed delivery attempt due to dog hazard"! |
Beta Was this translation helpful? Give feedback.
-
They are mutually exclusive as far as I know. This would be a question for
SourceKit-LSP.
…On Sun, 28 Jul 2024 at 07:58, Brian Henry ***@***.***> wrote:
Thanks. I mean, does the presence of one supersede the existence of the
other? Are both outputs used together or are they mutually exclusive?
—
Reply to this email directly, view it on GitHub
<#968 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACHSVJ4OHYV433CBPZXW7ULZOSB75AVCNFSM6AAAAABK4NXNSGVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTAMJXGAZDOOI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Here's a promising project where the author says he has it working:
I spent yesterday, before I saw that post, trying to rewrite the CMakeLists so the Swift compilation is done by CMake rather than through an There's a new reply on the forum post I linked above: Which itself links to a good thread on the topic: The other example embedded projects' CMakeLists files, both in apple/swift-embedded-examples and apple/swift-matter-examples, take slightly different approaches. I'd bet some might work with LSP out of the box. I'll take another look at this next weekend. I feel I'm almost there. |
Beta Was this translation helpful? Give feedback.
-
I pulled the latest apple/swift-embedded-examples and when I built the esp32-led-blink-sdk I immediately got code-completion and navigation, thanks @kubamracek And thanks everyone else for the help. |
Beta Was this translation helpful? Give feedback.
-
This has just been posted in the sourcekit-lsp documentation |
Beta Was this translation helpful? Give feedback.
-
Hey folks! This WWDC they have shared the Swift Embedded support with cool samples using Matter. Here is the video https://developer.apple.com/videos/play/wwdc2024/10197/ .
In the video, they use NeoVim and it does have code completion suggestions, I have being trying to make it work with the VSCode Swift, but without success. I'm using latest Swift version (6.0 nightly) and setup in the VSC plugin as the toolchain but it did not improve.
Here is the video sample project if you may want to test
https://github.com/apple/swift-matter-examples/tree/main/led-blink
It is required to install esp-idf and esp-matter, I had to install Python 3.9.2 via ASDF, the current MacOS version does not work/compile esp-matter.
Beta Was this translation helpful? Give feedback.
All reactions