Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nvim-lspconfig + arduino-language-server doesn't attach to buffer #187

Closed
3 tasks done
realhackcraft opened this issue Jun 9, 2024 · 9 comments
Closed
3 tasks done
Labels
type: imperfection Perceived defect in any part of project

Comments

@realhackcraft
Copy link

realhackcraft commented Jun 9, 2024

Describe the problem

I'm using NvChad. My arduino ls doesn't crash, but doesn't attach to the buffer either.

To reproduce

exerpt of my config:

local lspconfig = require "lspconfig"

local MY_FQBN = "arduino:avr:leonardo"

local on_attach = require("nvchad.configs.lspconfig").on_attach
local on_init = require("nvchad.configs.lspconfig").on_init
local capabilities = require("nvchad.configs.lspconfig").capabilities

lspconfig.arduino_language_server.setup {
  on_attach = on_attach,
  on_init = on_init,
  capabilities = capabilities,
  cmd = {
    "arduino-language-server",
    "-cli-config",
    "$HOME/.arduino15/arduino-cli.yaml",
    "-fqbn",
    MY_FQBN,
  },
}

Expected behavior

Attach to the buffer with the .ino file

Arduino Language Server version

0.7.6

Arduino CLI version

arduino-cli Version: 0.35.3 Commit: 95cfd654 Date: 2024-02-19T13:15:51Z

Operating system

macOS

Operating system version

14.5

Additional context

Screenshot 2024-06-08 at 23 12 38

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the latest version
  • My report contains all necessary details
@realhackcraft realhackcraft added the type: imperfection Perceived defect in any part of project label Jun 9, 2024
@realhackcraft
Copy link
Author

This is in the last lines of :LspLog:

[START][2024-06-09 12:16:08] LSP logging initiated
[ERROR][2024-06-09 12:16:08] .../vim/lsp/rpc.lua:770	"rpc"	"/Users/Borui/.local/share/nvim/mason/bin/arduino-language-server"	"stderr"	"12:16:08.152281 clangd found at /Users/Borui/.local/share/nvim/mason/bin/clangd\n12:16:08.154789 \27[97mLS: : Initial board configuration: arduino:avr:leonardo\27[0m\n12:16:08.154969 \27[97mLS: : arduino-language-server Version: 0.7.6 Commit: 9c2f44d Date: 2024-02-06T14:12:59Z\27[0m\n12:16:08.154991 \27[97mLS: : Language server temp directory: /private/var/folders/rj/bw9lqpk15g9ckdkpv0n7nhvr0000gp/T/arduino-language-server3164570696\27[0m\n12:16:08.154994 \27[97mLS: : Language server build path: /private/var/folders/rj/bw9lqpk15g9ckdkpv0n7nhvr0000gp/T/arduino-language-server3164570696/build\27[0m\n12:16:08.154995 \27[97mLS: : Language server build sketch root: /private/var/folders/rj/bw9lqpk15g9ckdkpv0n7nhvr0000gp/T/arduino-language-server3164570696/build/sketch\27[0m\n12:16:08.154997 \27[97mLS: : Language server FULL build path: /private/var/folders/rj/bw9lqpk15g9ckdkpv0n7nhvr0000gp/T/arduino-language-server3164570696/fullbuild\27[0m\n12:16:08.157664 IN Elapsed: 921.084µs\n12:16:08.160606 \27[92mIDE --> LS REQU initialize 1\27[0m\n"

It appears to be the same as the output of the arduino-language-server sh command with the arguments.

@realhackcraft
Copy link
Author

-cli-daemon-addr string
        TCP address and port of the Arduino CLI daemon (for example: localhost:50051)

Does this mean that I need to spin up a arduino cli daemon myself, or is the ls going to do it?

@HannHank
Copy link

HannHank commented Jun 9, 2024

I encountered a similar issue, which seems to align with the one described in #186. I resolved it by downgrading to Neovim version v0.9.5. It appears that there are breaking changes in the newer versions of Neovim that prevent the LSP client from connecting properly.

@realhackcraft
Copy link
Author

Right. Thank you!

@fspv
Copy link

fspv commented Jun 20, 2024

I found the problem. It is in the https://github.com/bugst/go-lsp package, which arduino LSP depends on.

nvim 0.10 passes some new capabilities to the LSP, such as inlayHint. The problem is that the lib mentioned above seems to be not maintained and/or updated and hence it doesn't support these new capabilities (try to search for inlayHint here https://github.com/bugst/go-lsp/blob/master/lsp_capabilities_client.go).

So the solution here will be to add new capabilities to the library mentioned above. The problem is, unfortunately, not fixable from this repo, because the initial request handling and parsing is done in the LSP lib.

@Vosjedev
Copy link

what are the missing capabilities? I would like to know, because then I could try setting them to false in the lsp configuration:

-- [...]
local arduino_capabilities = vim.lsp.protocol.make_client_capabilities()
-- now here set some capabilities to false:
arduino_capabilities.unsupportedCapability = false
-- then use arduino_capabilities as the capabilities value for the lspconfig entry
-- [...]

@fspv
Copy link

fspv commented Jun 26, 2024

I tried setting them to false, but it didn't work. I tried to look at the neovim code and I think there is no way to say not to pass inlay hint field to the language server. So even if you set it to false, it will be sent and the language server will crash, because it doesn't expect to see such a field in the json.

But anyway, I found out that you can just use clangd directly with the arduino code. The trick is to create a separate test.h and test.cpp files and import them from the .ino file. You can find the paths of the libraries to include in cat build/libraries.cache generated by the arduino-cli compile and place them into the .clangd file like this

CompileFlags:
  Add:
  - -I/home/fspv/.arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino
  - -I/home/fspv/.arduino15/packages/arduino/hardware/avr/1.8.6/variants/standard
  - -I/home/fspv/Arduino/libraries/MD_Parola/src
  - -I/home/fspv/Arduino/libraries/MD_MAX72XX/src
  - -I/home/fspv/.arduino15/packages/arduino/hardware/avr/1.8.6/libraries/SPI/src

So I personally don't need an arduino-language-server anymore :)

@xdanep
Copy link

xdanep commented Jun 29, 2024

I have the same issue, i tried everything but nothing works
image

@leoverde2
Copy link

This fixed it for me:

Change this:
type ProgressToken json.RawMessage

to this:
type ProgressToken string

at the end of the file jsonrpc_protocol.go in the go-lsp library that this lsp depends on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

6 participants