|
| 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 | +} |
0 commit comments