aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2021-12-27 00:03:23 +0100
committerGitHub <noreply@github.com>2021-12-27 00:03:23 +0100
commite65e4966e1b3db486ae548a5674f20a8416a42d0 (patch)
tree3d8e8eb0b00e0f26680aa7e88395b5ce4eaa8eb3 /lua
parentrun autogen_metadata.sh (diff)
downloadmason-e65e4966e1b3db486ae548a5674f20a8416a42d0.tar
mason-e65e4966e1b3db486ae548a5674f20a8416a42d0.tar.gz
mason-e65e4966e1b3db486ae548a5674f20a8416a42d0.tar.bz2
mason-e65e4966e1b3db486ae548a5674f20a8416a42d0.tar.lz
mason-e65e4966e1b3db486ae548a5674f20a8416a42d0.tar.xz
mason-e65e4966e1b3db486ae548a5674f20a8416a42d0.tar.zst
mason-e65e4966e1b3db486ae548a5674f20a8416a42d0.zip
fix(arduino_language_server): install clangd, also add docs on how to work with FQBN (#364)
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-lsp-installer/servers/arduino_language_server/README.md74
-rw-r--r--lua/nvim-lsp-installer/servers/arduino_language_server/init.lua25
2 files changed, 99 insertions, 0 deletions
diff --git a/lua/nvim-lsp-installer/servers/arduino_language_server/README.md b/lua/nvim-lsp-installer/servers/arduino_language_server/README.md
new file mode 100644
index 00000000..718f12d0
--- /dev/null
+++ b/lua/nvim-lsp-installer/servers/arduino_language_server/README.md
@@ -0,0 +1,74 @@
+# arduino_language_server
+
+## Necessary extra configuration
+
+The Arduino Language Server does not come fully bootstrapped out of the box. In order for the language server to
+successfully start, you need to provide which [FQBN](#FQBN) (e.g. "arduino:avr:nano") it should start with.
+
+This is done during server initialization, and can be done by utilizing lspconfig's `on_new_config` hook:
+
+```lua
+local lsp_installer = require("nvim-lsp-installer")
+
+lsp_installer.on_server_ready(function (server)
+ local opts = {}
+ if server.name == "arduino_language_server" then
+ opts.on_new_config = function (config, root_dir)
+ local partial_cmd = server:get_default_options().cmd
+ local MY_FQBN = "arduino:avr:nano"
+ config.cmd = vim.list_extend(partial_cmd, { "-fqbn", MY_FQBN })
+ end
+ end
+ server:setup(opts)
+end)
+```
+
+### Dynamically changing FQBN per project
+
+```lua
+local lsp_installer = require("nvim-lsp-installer")
+
+-- When the arduino server starts in these directories, use the provided FQBN.
+-- Note that the server needs to start exactly in these directories.
+-- This example would require some extra modification to support applying the FQBN on subdirectories!
+local my_arduino_fqbn = {
+ ["/home/h4ck3r/dev/arduino/blink"] = "arduino:avr:nano",
+ ["/home/h4ck3r/dev/arduino/sensor"] = "arduino:mbed:nanorp2040connect",
+}
+
+local DEFAULT_FQBN = "arduino:avr:uno"
+
+lsp_installer.on_server_ready(function (server)
+ local opts = {}
+ if server.name == "arduino_language_server" then
+ opts.on_new_config = function (config, root_dir)
+ local partial_cmd = server:get_default_options().cmd
+ local fqbn = my_arduino_fqbn[root_dir]
+ if not fqbn then
+ vim.notify(("Could not find which FQBN to use in %q. Defaulting to %q."):format(root_dir, DEFAULT_FQBN))
+ fqbn = DEFAULT_FQBN
+ end
+ config.cmd = vim.list_extend(partial_cmd, { "-fqbn", fqbn })
+ end
+ end
+ server:setup(opts)
+end)
+```
+
+## FQBN
+
+A FQBN, fully qualified board name, is used to distinguish between the various supported boards. Its format is defined
+as `<package>:<architecture>:<board>`, where
+
+- `<package>` - vendor identifier; typically just `arduino` for Arduino boards
+- `<architecture>` - microcontroller architecture; e.g., `avr`, `megaavr`, `sam`, etc.
+- `<board>` - board name defined by the software; e.g., `uno`, `uno2018`, `yun`, etc.
+
+To identify the available FQBNs for boards you currently have connected, you may use the `arduino-cli` command, like so:
+
+```sh
+$ arduino-cli board list
+Port Protocol Type Board Name FQBN Core
+/dev/ttyACM0 serial Serial Port (USB) Arduino Uno arduino:avr:uno arduino:avr
+ ^^^^^^^^^^^^^^^
+```
diff --git a/lua/nvim-lsp-installer/servers/arduino_language_server/init.lua b/lua/nvim-lsp-installer/servers/arduino_language_server/init.lua
index 341eb854..3f794a65 100644
--- a/lua/nvim-lsp-installer/servers/arduino_language_server/init.lua
+++ b/lua/nvim-lsp-installer/servers/arduino_language_server/init.lua
@@ -63,22 +63,47 @@ return function(name, root_dir)
go.packages { "github.com/arduino/arduino-language-server" },
}
+ local clangd_installer = installers.branch_context {
+ context.set(function(ctx)
+ -- The user's requested version should not apply to clangd.
+ ctx.requested_server_version = nil
+ end),
+ context.use_github_release_file("clangd/clangd", function(version)
+ local target_file = coalesce(
+ when(platform.is_mac, "clangd-mac-%s.zip"),
+ when(platform.is_linux and platform.arch == "x64", "clangd-linux-%s.zip"),
+ when(platform.is_win, "clangd-windows-%s.zip")
+ )
+ return target_file and target_file:format(version)
+ end),
+ context.capture(function(ctx)
+ return installers.pipe {
+ std.unzip_remote(ctx.github_release_file),
+ std.rename(("clangd_%s"):format(ctx.requested_server_version), "clangd"),
+ }
+ end),
+ }
+
return server.Server:new {
name = name,
root_dir = root_dir,
homepage = "https://github.com/arduino/arduino-language-server",
languages = { "arduino" },
installer = {
+ clangd_installer,
arduino_cli_installer,
arduino_language_server_installer,
},
default_options = {
cmd = {
+ -- This cmd is incomplete. Users need to manually append their FQBN (e.g., -fqbn arduino:avr:nano)
go.executable(path.concat { root_dir, "arduino-language-server" }, "arduino-language-server"),
"-cli",
path.concat { root_dir, "arduino-cli", platform.is_win and "arduino-cli.exe" or "arduino-cli" },
"-cli-config",
path.concat { root_dir, "arduino-cli", "arduino-cli.yaml" },
+ "-clangd",
+ path.concat { root_dir, "clangd", "bin", platform.is_win and "clangd.bat" or "clangd" },
},
},
}