[Solved]: Arduino-Language-Server in neovim

Hi everyone,

I’m trying to set up clangd for an Arduino project on Windows, but I’m running into some issues and could use some help.

Context:
I’m trying working with Arduino sketches in Neovim and would like to use clangd to get better linting and Diagnostics support. However for some reason autocompletion works but my Diagnostics say: Use of undeclared identifier 'Serial' right next to both Serial in my Code below.

My setup:

--lspconfig.lua
lspconfig.clangd.setup({
    cmd = {"clangd", "--compile-commands-dir=" .. vim.loop.cwd() },
    filetypes = { "c", "cpp", "objc", "objcpp", "arduino" },
    init_options = {
        usePlaceholders = true,
        completeUnimported = true,
    },
})
//test.ino
void setup() {
    Serial.begin(115200);
    Serial.println("");
}
void loop() {}

I compiled it using arduino-cli compile --fqbn arduino:esp32:nano_nora --build-path ./build .\test.ino then afterwards i copied the compile_commands.json and build.options.json to the root of my project.

The issue with Serial disappears when putting in #include "USBCDC.h" . But then i am getting this error: In included file: '../hal.h' file not found. I am also getting the same error when using #include "Arduino.h"

I already tried using the arduino-language-server but it seems not to work with Neovim currently I also tried downgrading my Neovim version without any achievements.

I’d appreciate any advice or tips,
Thanks in advance.

Hi @dynastray.

Which version of Arduino CLI do you have installed? The recent reports of problems using Arduino Language Server are usually found to be caused by people using the release version of Arduino language server with Arduino CLI >=1.0.0. There was a breaking change in the Arduino CLI API introduced in the 1.0.0 release which caused it to become incompatible with Arduino Language Server.

The compatibility has already been restored:

However, there hasn't been a new release of Arduino Language Server since that time so the release version can't be used with the latest Arduino CLI.

Hi @ptillisch, thx for the fast response i am currently using:

arduino-cli Version: 1.0.4 Commit: a0d912da Date: 2024-08-12T13:42:36Z

i now tried Arduino CLI v0.35.3 but still not working.

I have attatched my lsp log
lsp.log - Pastebin.com

at the end it says something with waiting clangd
but i got it installed

PS C:\Users\danie> clangd --version
clangd version 18.1.8
Features: windows
Platform: x86_64-w64-windows-gnu

Got it to work now

using:

--lspconfig.lua
lspconfig.arduino_language_server.setup({
    cmd = {
        "arduino-language-server",
        "-clangd",      "C:/msys64/mingw64/bin/clangd.exe",
        "-cli",         "C:/Program Files/Arduino CLI/arduino-cli.exe",
        "-cli-config",  "C:/Users/danie/AppData/Local/Arduino15/arduino-cli.yaml",
        "-fqbn",  "arduino:esp32:nano_nora"
    }
})

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.