helix
helix copied to clipboard
Add arduino support
All is in the title. I've been enjoying Helix for rust / elm / python dev. I also have some DIY embedded projects and thought it would be awesome to have arduino support in Helix.
The instructions from nvim-lspconfig
for arduino-language-server
can be adapted to work with helix. An additional step I would add is generating a project specific sketch.json
file so that the FQBN is not hardcoded as a command line flag to the LSP. For example:
{
"cpu": {
"fqbn": "arduino:avr:uno",
"name": "Arduino Uno",
"port": "serial:///dev/ttyACM0"
}
}
I've been tinkering with it for a while, but nothing is getting this to work. I get 'language server exited'. Maybe are there discrete steps? Perhasps my language.toml file isn't properly configured with the right args.. - Gentoo linux user.
I spent some time trying to also make it work but with no luck. I can start the lsp in my terminal
> arduino-language-server -cli "arduino-cli" -cli-config "~/.arduino15/arduino-cli.yaml" -clangd "clangd"
04:42:58.078921 LS: : Initial board configuration:
04:42:58.078960 LS: : arduino-language-server Version: 0.0.0-git Commit: Date:
04:42:58.078969 LS: : Language server build path: /tmp/arduino-language-server1743458347
04:42:58.078974 LS: : Language server build sketch root: /tmp/arduino-language-server1743458347/sketch
04:42:58.078978 LS: : Language server FULL build path: /tmp/arduino-language-server2383572508
arduino-language-server is a language server that provides IDE-like features to editors.
It should be used via an editor plugin rather than invoked directly. For more information, see:
https://github.com/arduino/arduino-language-server/
https://microsoft.github.io/language-server-protocol/
but when included in languages.toml
as
language-server = { command = "arduino-language-server", args = ["-cli", "arduino-cli", "-cli-config", "~/.arduino15/arduino-cli.yaml", "-clangd", "clangd"] }
the lsp quits at internal clangd startup. I am also pretty sure the sketch.json
file does not get loaded.
For now I am quite happy using platformIO Core in combination with clangd, although it can be a bit inconvenient when collaborating with others. If anyone wants to take a look, I can share my helix.log
, didn't want to make the comment too long.
I don't know if you figured it out, but I was able to get some completion and hover to work with this setting in the root of my repo, the repo has a bunch of arduino projects
- .helix/languages.toml
[[language]]
scope = "source.cpp"
name = "arduino"
file-types = ["ino"]
roots = ["*.ino", "sketch.yaml"]
language-server = { command = "arduino-language-server", args = ["--log"] }
I am setting up my project with arduino-cli and I setup a sketch.yaml
systematically, the *.ino
doesn't seem to be recognized ...
This setup doesn't have the syntax highlighting, I don't know why but it's my first time with helix and I didn't have time to investigate yet
I've managed to bodge syntax highlighting into working by adding the following to languages.toml
:
[language-server.arduino-lsp]
command = "arduino-language-server"
args = ["-cli", "arduino-cli", "-cli-config", "~/.arduino15/arduino-cli.yaml", "-clangd", "clangd"]
[[grammar]]
name = "cpp"
source = { git = "https://github.com/tree-sitter/tree-sitter-cpp", rev = "a90f170f92d5d70e7c2d4183c146e61ba5f3a457" }
[[grammar]]
name = "arduino"
source = { git = "https://github.com/ObserverOfTime/tree-sitter-arduino", rev = "db929fc6822b9b9e1211678d508f187894ce0345"}
[[language]]
name = "arduino"
scope = "source.arduino"
injection-regex = "arduino"
file-types = ["ino"]
roots = [ "sketch.yaml"]
language-servers = [ "arduino-lsp" ]
and by "borrowing" the 'cpp' and 'arduino' tree-sitter queries from nvim-treesitter, putting them in ~/.config/helix/runtime/queries/{cpp,arduino}
.
I'm not exactly sure why I needed to both use a more recent version of tree-sitter-cpp
and manually import the cpp queries, I think there's a version mismatch between what Helix uses and what tree-sitter-arduino
expects, but it seems to work.
I am using the latest version of Helix which subtly changes the language server configuration (language-server
->language-servers
), so watch out for that if you're using an older version.
Oh that's great, thank you, indeed it seems the queries are required.
By the way my arduino lsp config, just works with command = "arduino-language-server"
and no info about clangd or the rest.
By the way my arduino lsp config, just works with
command = "arduino-language-server"
and no info about clangd or the rest.
Oh you're right, I had just copied the args from a previous comment without thinking.
@lieskjur said:
For now I am quite happy using platformIO Core in combination with clangd, although it can be a bit inconvenient when collaborating with others. If anyone wants to take a look, I can share my
helix.log
, didn't want to make the comment too long.
did you make that work properly in Helix? I keep having errors showing up in helix when modifying a platformio project about the #include <Arduino.h>
, any suggestion?
Thanks
@lieskjur said:
For now I am quite happy using platformIO Core in combination with clangd, although it can be a bit inconvenient when collaborating with others. If anyone wants to take a look, I can share my
helix.log
, didn't want to make the comment too long.did you make that work properly in Helix? I keep having errors showing up in helix when modifying a platformio project about the
#include <Arduino.h>
, any suggestion?Thanks
@abondis This might be related to your problem---my Arduino language configuration also includes cpp
and h
file types, and it ends up working just fine for me. Hope that was helpful for you :blush:
[[language]]
name = "arduino"
scope = "source.arduino"
injection-regex = "arduino"
file-types = ["ino", "cpp", "h"] # ⭐ this line is what matters
comment-token = "//"
roots = ["sketch.yaml"]
language-servers = ["arduino-language-server"]
indent = { tab-width = 4, unit = " " }
auto-format = true
[language.formatter]
command = "clang-format"
[language-server.arduino-language-server]
command = "arduino-language-server"
[[grammar]]
name = "cpp"
source = { git = "https://github.com/tree-sitter/tree-sitter-cpp", rev = "a90f170f92d5d70e7c2d4183c146e61ba5f3a457" }
[[grammar]]
name = "arduino"
source = { git = "https://github.com/ObserverOfTime/tree-sitter-arduino", rev = "db929fc6822b9b9e1211678d508f187894ce0345" }
I managed to get the language server working, but for some reason highlights aren't
I managed to get the language server working, but for some reason highlights aren't
Have you run these commands after using the above config?
helix -g fetch
helix -g build
yeah I have done that. What should I be looking for in the logs to troubleshoot. Funnily the language server is running just fine
yeah I have done that. What should I be looking for in the logs to troubleshoot. Funnily the language server is running just fine
Hm, I'm not sure why it's not working at the moment. A temporary solution I can think of for now is setting the grammar in [[language]]
to "cpp":
[[language]]
name = "arduino"
grammar = "cpp"
# ... the rest of your config