在 Neovim(v0.10+) 上使用 arduino-language-server

Last

前言

  • 毕设选了个嵌入式开发的小项目,不是很想用笨重的 arduino IDE。
  • 于是浪费了半个下午配置环境……水篇博客,不然这努力岂不是白费了(bushi

正文

问题描述

  • 期初我尝试直接使用 Mason 安装 arduino-language-server,但即便按文档要求修改配置后仍然无法正常启动。

  • 查阅相关 issues/PR 之后发现,问题不在 arduino-language-server 自身,而是将其 integrate 进 Neovim 时所依赖的 go-lsp 上。

    The dependency (bugst/go-lsp) used by the Arduino language server was updated (its go.mod was bumped to Go 1.22), and its behavior causes the language server to “fail to attach” or “quit” when Neovim v0.10+ attempts to start it. This manifests as errors in the Neovim logs (e.g. errors related to clangd startup and “locked (waiting clangd)”, even though the server may still work despite the warning message).

  • speelbarrowarduino-language-server 依赖的 go-lsp 更换为了其 patch 过的版本:

    1
    2
    3
    4
    5
    6
    7
    +++ go.mod
    @@ 32,3 +32,5 @@
    gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
    gopkg.in/yaml.v3 v3.0.1 // indirect
    )
    +
    + replace go.bug.st/lsp => github.com/speelbarrow/go-lsp v0.1.3-0.20241103164431-cf1c00fb5806
  • 进一步查看其对于 go-lsp 所做的修改:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    --- jsonrpc/jsonrpc_connection.go
    +++ jsonrpc/jsonrpc_connection.go
    @@ -277,7 +277,7 @@ func (c *Connection) SendRequest(ctx context.Context, method string, params json
    _, active := c.activeOutRequests[id]
    c.activeOutRequestsMutex.Unlock()
    if active {
    - if notif, err := json.Marshal(CancelParams{ID: encodedId}); err != nil {
    + if notif, err := json.Marshal(CancelParams{ID: encodedID}); err != nil {
    // should never happen
    panic("internal error: failed json encoding")
    } else {
  • 原来只是一个类型 typo 错误吗……

解决方案

  • 虽然上文提到的 patch 已经能够使得 arduino-language-server 运行在 neovim v0.10+ 的版本中,但是该 PR 并未被 merge。查看 go-lsp 仓库的 Insights 界面可知:

    screenshot_22022025_114218.jpg

  • 很显然这个仓库已经死了。

  • 仔细看了一下,这个仓库似乎仅仅是为了 arduino-language-server 而 fork 的一个仓库,作者 cmaglie 已经很久没有对其进行维护了。

更新

cmaglie 于 2025-03-19 合并了该 PR,现在可以直接使用 Mason 安装的 arduino-language-server 了。


  • 尽管如此,办法也还是有的:

    • speelbarrow 的 repo 克隆到本地:

      1
      git clone https://github.com/speelbarrow/arduino-language-server.git
    • 手动 build 一个依赖正确 go-lsparduino-language-server

      1
      cd arduino-language-server && go build
    • 将 Mason 里安装的可执行文件替换为手动构建的 arduino-language-server

      1
      cp ./arduino-language-server ~/.local/share/nvim/mason/packages/arduino-language-server/arduino-language-server

配置文件

  • 顺带的,arduino-language-server 的启动需要一些前置步骤以及一些命令行参数。

  • 前置步骤详见: lspconfig doc

  • 本人开发 ESP32 CAM 所需要的命令行参数如下:

    astrolsp.lua:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    arduino_language_server = {
    on_new_config = function(config)
    config.capabilities.textDocument.semanticTokens = vim.NIL
    config.capabilities.workspace.semanticTokens = vim.NIL
    config.cmd = {
    "arduino-language-server",
    "-clangd",
    "/home/last/.local/share/nvim/mason/bin/clangd",
    "-cli",
    "/usr/bin/arduino-cli",
    "-cli-config",
    "/home/last/.arduino15/arduino-cli.yaml",
    "-fqbn",
    "esp32:esp32:esp32cam",
    }
    end,
    },

    注意:该配置仅适用于 AstroNvim 下,且需要使用 Mason 安装 clangd

总结

  • 又是被环境配置折磨的一天。
  • 这麻烦还是我自己找的,哈哈。
  • Title: 在 Neovim(v0.10+) 上使用 arduino-language-server
  • Author: Last
  • Created at : 2025-02-22 11:05:34
  • Link: https://blog.imlast.top/2025/02/22/arduino-language-server-on-neovim/
  • License: This work is licensed under CC BY-NC-SA 4.0.
Comments
Nickname
Email
Website
0/500
  • OωO
  • |´・ω・)ノ
  • ヾ(≧∇≦*)ゝ
  • (☆ω☆)
  • (╯‵□′)╯︵┴─┴
  •  ̄﹃ ̄
  • (/ω\)
  • ∠( ᐛ 」∠)_
  • (๑•̀ㅁ•́ฅ)
  • →_→
  • ୧(๑•̀⌄•́๑)૭
  • ٩(ˊᗜˋ*)و
  • (ノ°ο°)ノ
  • (´இ皿இ`)
  • ⌇●﹏●⌇
  • (ฅ´ω`ฅ)
  • (╯°A°)╯︵○○○
  • φ( ̄∇ ̄o)
  • ヾ(´・ ・`。)ノ"
  • ( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
  • (ó﹏ò。)
  • Σ(っ °Д °;)っ
  • ( ,,´・ω・)ノ"(´っω・`。)
  • ╮(╯▽╰)╭
  • o(*////▽////*)q
  • >﹏<
  • ( ๑´•ω•) "(ㆆᴗㆆ)
  • 😂
  • 😀
  • 😅
  • 😊
  • 🙂
  • 🙃
  • 😌
  • 😍
  • 😘
  • 😜
  • 😝
  • 😏
  • 😒
  • 🙄
  • 😳
  • 😡
  • 😔
  • 😫
  • 😱
  • 😭
  • 💩
  • 👻
  • 🙌
  • 🖕
  • 👍
  • 👫
  • 👬
  • 👭
  • 🌚
  • 🌝
  • 🙈
  • 💊
  • 😶
  • 🙏
  • 🍦
  • 🍉
  • 😣
  • 颜文字
  • Emoji
  • Bilibili
0 comments
No comment
On this page
在 Neovim(v0.10+) 上使用 arduino-language-server