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

Add arduino support #5277

Open
mpizenberg opened this issue Dec 24, 2022 · 13 comments
Open

Add arduino support #5277

mpizenberg opened this issue Dec 24, 2022 · 13 comments
Labels
A-language-support Area: Support for programming/text languages C-enhancement Category: Improvements

Comments

@mpizenberg
Copy link

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.

@mpizenberg mpizenberg added the C-enhancement Category: Improvements label Dec 24, 2022
@the-mikedavis the-mikedavis added the A-language-support Area: Support for programming/text languages label Dec 24, 2022
@sudormrfbin
Copy link
Member

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"
  }
}

@danielgomez3
Copy link

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.

@lieskjur
Copy link

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.

@abondis
Copy link

abondis commented Nov 2, 2023

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

@blueted2
Copy link

blueted2 commented Nov 2, 2023

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.

@abondis
Copy link

abondis commented Nov 2, 2023

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.

@blueted2
Copy link

blueted2 commented Nov 3, 2023

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.

@abondis
Copy link

abondis commented Nov 13, 2023

@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

@samminhch
Copy link

@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 😊

[[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" }

@taotien
Copy link

taotien commented Apr 28, 2024

I managed to get the language server working, but for some reason highlights aren't

@samminhch
Copy link

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

@taotien
Copy link

taotien commented Apr 29, 2024

yeah I have done that. What should I be looking for in the logs to troubleshoot. Funnily the language server is running just fine

@samminhch
Copy link

samminhch commented Apr 29, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-language-support Area: Support for programming/text languages C-enhancement Category: Improvements
Projects
None yet
Development

No branches or pull requests

9 participants