-
-
Notifications
You must be signed in to change notification settings - Fork 17
Fix error when attempting to determine Arduino data path from CLI output -- Needs review, not backwards compatible #182
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
Conversation
@jmcclell Your detailed description is much appreciated. The arduino-cli (>= v0.36.0-rc.1) is currently undergoing a significant amount of breaking changes while moving forward to v1.0.0 which will be released in the upcoming months. To allow the IDE team to test such breaking changes, we are updating the LS to be compatible with the latest changes of the cli. For this reason, the latest commits present in the master branch of this repository will not work with the previous version of the cli (< v0.36.0-rc.1). The panic you're experiencing is somewhat expected because it's interacting with a cli version that doesn't respect the new API. Pinning the LS to You mentioned that you're using neovim, if you're managing the LSPs with mason you could change your lua config by pinning the LS version when passing the name to the |
Ah! That explains it :) I haven't done any Arduino development in quite some time so I was starting fresh with my IDE setup and just assumed the LSP was behind the latest release of the CLI. 🤦🏻 Will pin the version. 🙇🏻 I will mention that I installed the LSP via |
@jmcclell Yep
Usually what is sitting in the master/main/latest branch is considered unstable, but adding a notice won't harm anyone. 🤓 Tracking at #183 I appreciate your patience 💪 |
The arduino-language-server determines the Arduino data directory in one of two ways
If the
--cli-daemon-addr
and--cli-daemon-instance
options are set, it uses gRPC to talk to a settings endpoint and extracts thedirectories.data
key.If the
--cli-config
option is set, it directly execsarduino-cli
with argumentsconfig dump --format json
and attempts to parse the output as JSON into a pre-defined struct that assumes a particular structure.With current (and perhaps previous?) versions of Arduino CLI (0.35.3), this second approach generates an error if the config file was generated with
arduino-cli config init
as the output does not match the code's expected format.file:
inols-err.log
(enabled with--log
flag on arduino-language-server)Because Go doesn't check for exact matches between target structs and source data, the
unmarshall
call does not return an error in this situation.We end up with a zero-valued struct that happily returns an empty string as the data directory.
When we later turn this into a path with
dataDirPath := paths.New(dataDir)
, we end up with a nil pointer, as the paths constructor returns nil on empty string input.file:
[email protected]/paths.go
The current version of the code fails to check for this condition.
Finally, when we pass this nil pointer along to clangd, it chokes, resulting in the vague error message about clangd startup failing.
The fix in this PR updates the code to work with the current output, but it is not backward compatible!
I'll let someone else decide what to do next, but I wanted to make this patch (and explanation — pardon its length) available for anyone else running into this issue.
Environment Detail
neovim LSP config for arduino-language-server using
nvim-lspconfig
Additional Information for Passerbys
If you encounter this issue but are unfamiliar with Go, here's how to patch it quickly while the maintainers decide what to do with this PR.
Assuming you originally installed arduino-language-server with
go install github.com/arduino/arduino-language-server
, you can replace it with a locally patched version via: