aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-04-29 13:17:54 +0200
committerGitHub <noreply@github.com>2022-04-29 13:17:54 +0200
commit049cb63d5e0b78843c8b41f0a0b7694363f5b185 (patch)
treed49fc67abfca65f23e9d72868744d1f69022259d /lua
parentdocs: more deprecations and update some outdated docs (diff)
downloadmason-049cb63d5e0b78843c8b41f0a0b7694363f5b185.tar
mason-049cb63d5e0b78843c8b41f0a0b7694363f5b185.tar.gz
mason-049cb63d5e0b78843c8b41f0a0b7694363f5b185.tar.bz2
mason-049cb63d5e0b78843c8b41f0a0b7694363f5b185.tar.lz
mason-049cb63d5e0b78843c8b41f0a0b7694363f5b185.tar.xz
mason-049cb63d5e0b78843c8b41f0a0b7694363f5b185.tar.zst
mason-049cb63d5e0b78843c8b41f0a0b7694363f5b185.zip
fix!(arduino_language_server): dont install arduino-cli and clangd (#640)
This is now expected to be installed on the system instead.
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-lsp-installer/servers/arduino_language_server/README.md52
-rw-r--r--lua/nvim-lsp-installer/servers/arduino_language_server/init.lua121
2 files changed, 34 insertions, 139 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
index 718f12d0..e229366b 100644
--- a/lua/nvim-lsp-installer/servers/arduino_language_server/README.md
+++ b/lua/nvim-lsp-installer/servers/arduino_language_server/README.md
@@ -5,29 +5,23 @@
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:
+This is done during server setup, and can be done by providing a custom `cmd`:
```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)
+local MY_FQBN = "arduino:avr:nano"
+lspconfig.arduino_language_server.setup {
+ cmd = {
+ "arduino-language-server",
+ "-cli-config", "/path/to/arduino-cli.yaml",
+ "-fqbn",
+ MY_FQBN
+ }
+}
```
### 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!
@@ -38,21 +32,21 @@ local my_arduino_fqbn = {
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 })
+lspconfig.arduino_language_server.setup {
+ on_new_config = function (config, root_dir)
+ 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 = {
+ "arduino-language-server",
+ "-cli-config", "/path/to/arduino-cli.yaml",
+ "-fqbn",
+ fqbn
+ }
end
- server:setup(opts)
-end)
+}
```
## FQBN
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 81188828..b46592e5 100644
--- a/lua/nvim-lsp-installer/servers/arduino_language_server/init.lua
+++ b/lua/nvim-lsp-installer/servers/arduino_language_server/init.lua
@@ -1,75 +1,21 @@
-local path = require "nvim-lsp-installer.path"
local server = require "nvim-lsp-installer.server"
local platform = require "nvim-lsp-installer.platform"
local Data = require "nvim-lsp-installer.data"
local installer = require "nvim-lsp-installer.core.installer"
local github = require "nvim-lsp-installer.core.managers.github"
-local std = require "nvim-lsp-installer.core.managers.std"
local Optional = require "nvim-lsp-installer.core.optional"
local process = require "nvim-lsp-installer.process"
local coalesce, when = Data.coalesce, Data.when
return function(name, root_dir)
- ---@async
- local function arduino_cli_installer()
- local ctx = installer.context()
-
- ctx.fs:mkdir "arduino-cli"
- ctx:chdir("arduino-cli", function()
- local opts = {
- repo = "arduino/arduino-cli",
- version = Optional.empty(),
- asset_file = function(release)
- local target = coalesce(
- when(platform.is_mac, "arduino-cli_%s_macOS_64bit.tar.gz"),
- when(
- platform.is_linux,
- coalesce(
- when(platform.arch == "x64", "arduino-cli_%s_Linux_64bit.tar.gz"),
- when(platform.arch == "x86", "arduino-cli_%s_Linux_32bit.tar.gz"),
- when(platform.arch == "arm64", "arduino-cli_%s_Linux_ARM64.tar.gz"),
- when(platform.arch == "armv6", "arduino-cli_%s_Linux_ARMv6.tar.gz"),
- when(platform.arch == "armv7", "arduino-cli_%s_Linux_ARMv7.tar.gz")
- )
- ),
- when(
- platform.is_win,
- coalesce(
- when(platform.arch == "x64", "arduino-cli_%s_Windows_64bit.zip"),
- when(platform.arch == "x86", "arduino-cli_%s_Windows_32bit.zip")
- )
- )
- )
- return target and target:format(release)
- end,
- }
-
- platform.when {
- unix = function()
- github.untargz_release_file(opts)
- std.chmod("+x", { "arduino-cli" })
- end,
- win = function()
- github.unzip_release_file(opts)
- end,
- }
-
- ctx.spawn["arduino-cli"] {
- "config",
- "init",
- "--dest-file",
- "arduino-cli.yaml",
- "--overwrite",
- with_paths = { ctx.cwd:get() },
- }
- end)
- end
-
- local function arduino_language_server_installer()
- local ctx = installer.context()
- ctx.fs:mkdir "arduino-language-server"
- ctx:chdir("arduino-language-server", function()
+ return server.Server:new {
+ name = name,
+ root_dir = root_dir,
+ homepage = "https://github.com/arduino/arduino-language-server",
+ languages = { "arduino" },
+ async = true,
+ installer = function()
local opts = {
repo = "arduino/arduino-language-server",
asset_file = function(release)
@@ -100,64 +46,19 @@ return function(name, root_dir)
return target and target:format(release)
end,
}
+
platform.when {
unix = function()
- github.untargz_release_file(opts)
+ github.untargz_release_file(opts).with_receipt()
end,
win = function()
- github.unzip_release_file(opts)
+ github.unzip_release_file(opts).with_receipt()
end,
}
- end)
- end
-
- local function clangd_installer()
- local ctx = installer.context()
-
- local source = github.unzip_release_file {
- repo = "clangd/clangd",
- version = Optional.empty(),
- asset_file = function(release)
- 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(release)
- end,
- }
-
- ctx.fs:rename(("clangd_%s"):format(source.release), "clangd")
- end
-
- return server.Server:new {
- name = name,
- root_dir = root_dir,
- homepage = "https://github.com/arduino/arduino-language-server",
- languages = { "arduino" },
- async = true,
- installer = function()
- clangd_installer()
- arduino_cli_installer()
- arduino_language_server_installer()
end,
default_options = {
- cmd = {
- -- This cmd is incomplete. Users need to manually append their FQBN (e.g., -fqbn arduino:avr:nano)
- "arduino-language-server",
- "-cli",
- "arduino-cli",
- "-clangd",
- "clangd",
- "-cli-config",
- path.concat { root_dir, "arduino-cli", "arduino-cli.yaml" },
- },
cmd_env = {
- PATH = process.extend_path {
- path.concat { root_dir, "arduino-language-server" },
- path.concat { root_dir, "arduino-cli" },
- path.concat { root_dir, "clangd", "bin" },
- },
+ PATH = process.extend_path { root_dir },
},
},
}