Skip to content

Commit 189aef8

Browse files
committed
languages/arduino: init
1 parent da1fed2 commit 189aef8

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

docs/release-notes/rl-0.8.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,11 @@
386386
[poz](https://poz.pet):
387387

388388
[everforest]: https://github.com/sainnhe/everforest
389+
[arduino-language-server]: https://github.com/arduino/arduino-language-server
389390

390391
- Fix gitsigns null-ls issue.
391392
- Add [everforest] theme support.
393+
- Add Arduino support with [arduino-language-server].
392394

393395
[Haskex](https://github.com/haskex):
394396

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
config,
3+
pkgs,
4+
lib,
5+
...
6+
}: let
7+
inherit (lib.options) mkEnableOption mkOption;
8+
inherit (lib.meta) getExe getExe';
9+
inherit (lib.modules) mkIf mkMerge;
10+
inherit (lib.strings) concatMapStrings optionalString;
11+
inherit (lib.types) listOf nullOr package str;
12+
inherit (lib.nvim.types) mkGrammarOption;
13+
14+
cfg = config.vim.languages.arduino;
15+
in {
16+
options.vim.languages.arduino = {
17+
enable = mkEnableOption "Arduino support";
18+
19+
treesitter = {
20+
enable = mkEnableOption "Arduino treesitter" // {default = config.vim.languages.enableTreesitter;};
21+
package = mkGrammarOption pkgs "arduino";
22+
};
23+
24+
lsp = {
25+
enable = mkEnableOption "Arduino LSP support (arduino-language-server)" // {default = config.vim.lsp.enable;};
26+
27+
package = mkOption {
28+
type = package;
29+
default = pkgs.arduino-language-server;
30+
description = "arduino-language-server package";
31+
};
32+
33+
clangdPackage = mkOption {
34+
type = package;
35+
default = config.vim.languages.clang.lsp.package;
36+
description = "clangd package";
37+
};
38+
39+
arduinoCliPackage = mkOption {
40+
type = package;
41+
default = pkgs.arduino-cli;
42+
description = "arduino-cli package";
43+
};
44+
45+
configPath = mkOption {
46+
type = str;
47+
default = "$HOME/.arduino15/arduino-cli.yaml";
48+
description = "Path to the arduino-cli config";
49+
};
50+
51+
fqbn = mkOption {
52+
type = nullOr str;
53+
default = null;
54+
description = "Fully Qualified Board Name";
55+
};
56+
57+
extraArgs = mkOption {
58+
type = listOf str;
59+
default = [];
60+
description = "Extra arguments passed to arduino-language-server";
61+
};
62+
};
63+
};
64+
config = mkIf cfg.enable (mkMerge [
65+
(mkIf cfg.treesitter.enable {
66+
vim.treesitter.enable = true;
67+
vim.treesitter.grammars = [cfg.treesitter.package];
68+
})
69+
70+
(mkIf cfg.lsp.enable {
71+
vim.lsp.lspconfig.enable = true;
72+
vim.lsp.lspconfig.sources.arduino-language-server = ''
73+
lspconfig.arduino_language_server.setup {
74+
capabilities = capabilities,
75+
on_attach = default_on_attach,
76+
cmd = {
77+
"${getExe cfg.lsp.package}",
78+
"-clangd", "${getExe' cfg.lsp.clangdPackage "clangd"}",
79+
"-cli", "${getExe cfg.lsp.arduinoCliPackage}",
80+
"-cli-config", "${cfg.lsp.configPath}"
81+
${optionalString (cfg.lsp.fqbn != null)
82+
'', "-fqbn", "${cfg.lsp.fqbn}"''}
83+
${optionalString (cfg.lsp.extraArgs != [])
84+
(concatMapStrings (arg: '', "${arg}"'') cfg.lsp.extraArgs)}
85+
},
86+
}
87+
'';
88+
})
89+
]);
90+
}

modules/plugins/languages/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
inherit (lib.nvim.languages) mkEnable;
44
in {
55
imports = [
6+
./arduino.nix
67
./asm.nix
78
./astro.nix
89
./bash.nix

0 commit comments

Comments
 (0)