aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIván Giovanazzi <43305758+ivano9@users.noreply.github.com>2021-10-12 18:13:44 -0300
committerGitHub <noreply@github.com>2021-10-12 23:13:44 +0200
commitcb36bb9837e7ee2b1b1207ecde0c9c3a74a12d71 (patch)
treea943675db8045597e40dd8f7f7e23c5b33358bcc
parentui: show installer log file path in help window (diff)
downloadmason-cb36bb9837e7ee2b1b1207ecde0c9c3a74a12d71.tar
mason-cb36bb9837e7ee2b1b1207ecde0c9c3a74a12d71.tar.gz
mason-cb36bb9837e7ee2b1b1207ecde0c9c3a74a12d71.tar.bz2
mason-cb36bb9837e7ee2b1b1207ecde0c9c3a74a12d71.tar.lz
mason-cb36bb9837e7ee2b1b1207ecde0c9c3a74a12d71.tar.xz
mason-cb36bb9837e7ee2b1b1207ecde0c9c3a74a12d71.tar.zst
mason-cb36bb9837e7ee2b1b1207ecde0c9c3a74a12d71.zip
add-erlangls (#144)
Co-authored-by: William Boman <william@redwill.se>
-rw-r--r--README.md1
-rw-r--r--lua/nvim-lsp-installer/installers/context.lua69
-rw-r--r--lua/nvim-lsp-installer/servers/erlangls/init.lua35
-rw-r--r--lua/nvim-lsp-installer/servers/init.lua1
4 files changed, 75 insertions, 31 deletions
diff --git a/README.md b/README.md
index 902e8a18..0239d90e 100644
--- a/README.md
+++ b/README.md
@@ -140,6 +140,7 @@ require("nvim-lsp-installer").settings {
| Elm | `elmls` |
| Ember | `ember` |
| Emmet | `emmet_ls` |
+| Erlang | `erlangls` |
| Fortran | `fortls` |
| Go | `gopls` |
| GraphQL | `graphql` |
diff --git a/lua/nvim-lsp-installer/installers/context.lua b/lua/nvim-lsp-installer/installers/context.lua
index e75f089d..3e36b6b5 100644
--- a/lua/nvim-lsp-installer/installers/context.lua
+++ b/lua/nvim-lsp-installer/installers/context.lua
@@ -1,6 +1,7 @@
local Data = require "nvim-lsp-installer.data"
local log = require "nvim-lsp-installer.log"
local process = require "nvim-lsp-installer.process"
+local installers = require "nvim-lsp-installer.installers"
local platform = require "nvim-lsp-installer.platform"
local M = {}
@@ -56,34 +57,12 @@ local function fetch(url, callback)
}
end
-function M.github_release_file(repo, file)
+function M.latest_github_release(repo)
return function(server, callback, context)
- local function get_download_url(version)
- local target_file = type(file) == "function" and file(version) or file
- if not target_file then
- log.fmt_error(
- "Unable to find which release file to download. server_name=%s, repo=%s",
- server.name,
- repo
- )
- context.stdio_sink.stderr(
- (
- "Could not find which release file to download. Most likely, the current operating system or architecture (%s) is not supported.\n"
- ):format(platform.arch)
- )
- return nil
- end
-
- return ("https://github.com/%s/releases/download/%s/%s"):format(repo, version, target_file)
- end
+ context.github_repo = repo
if context.requested_server_version then
-- User has already provided a version - don't fetch the latest version from GitHub
- local download_url = get_download_url(context.requested_server_version)
- if not download_url then
- return callback(false)
- end
- context.github_release_file = download_url
- callback(true)
+ return callback(true)
else
context.stdio_sink.stdout "Fetching latest release version from GitHub API...\n"
fetch(
@@ -94,13 +73,8 @@ function M.github_release_file(repo, file)
return callback(false)
end
local version = Data.json_decode(response).tag_name
- log.debug("Resolved latest version", server.name, version)
+ log.debug("Resolved latest version", server.name, repo, version)
context.requested_server_version = version
- local download_url = get_download_url(version)
- if not download_url then
- return callback(false)
- end
- context.github_release_file = download_url
callback(true)
end)
)
@@ -108,6 +82,39 @@ function M.github_release_file(repo, file)
end
end
+function M.github_release_file(repo, file)
+ return installers.pipe {
+ M.latest_github_release(repo),
+ function(server, callback, context)
+ local function get_download_url(version)
+ local target_file = type(file) == "function" and file(version) or file
+ if not target_file then
+ log.fmt_error(
+ "Unable to find which release file to download. server_name=%s, repo=%s",
+ server.name,
+ repo
+ )
+ context.stdio_sink.stderr(
+ (
+ "Could not find which release file to download. Most likely, the current operating system or architecture (%s) is not supported.\n"
+ ):format(platform.arch)
+ )
+ return nil
+ end
+
+ return ("https://github.com/%s/releases/download/%s/%s"):format(repo, version, target_file)
+ end
+
+ local download_url = get_download_url(context.requested_server_version)
+ if not download_url then
+ return callback(false)
+ end
+ context.github_release_file = download_url
+ callback(true)
+ end,
+ }
+end
+
function M.capture(fn)
return function(server, callback, context, ...)
local installer = fn(context)
diff --git a/lua/nvim-lsp-installer/servers/erlangls/init.lua b/lua/nvim-lsp-installer/servers/erlangls/init.lua
new file mode 100644
index 00000000..4baa075a
--- /dev/null
+++ b/lua/nvim-lsp-installer/servers/erlangls/init.lua
@@ -0,0 +1,35 @@
+local server = require "nvim-lsp-installer.server"
+local path = require "nvim-lsp-installer.path"
+local process = require "nvim-lsp-installer.process"
+local std = require "nvim-lsp-installer.installers.std"
+local context = require "nvim-lsp-installer.installers.context"
+local platform = require "nvim-lsp-installer.platform"
+
+return function(name, root_dir)
+ local erlang_ls_file_ext = platform.is_win and ".cmd" or ""
+ return server.Server:new {
+ name = name,
+ root_dir = root_dir,
+ homepage = "https://erlang-ls.github.io/",
+ installer = {
+ std.ensure_executables {
+ { "rebar3", "rebar3 was not found in path. Refer to http://rebar3.org/docs/." },
+ },
+ context.latest_github_release "erlang-ls/erlang_ls",
+ std.git_clone "https://github.com/erlang-ls/erlang_ls.git",
+ function(server, callback, context)
+ local c = process.chain {
+ cwd = server.root_dir,
+ stdio_sink = context.stdio_sink,
+ }
+ local rebar3 = platform.is_win and "rebar3.cmd" or "rebar3"
+ c.run(rebar3, { "escriptize" })
+ c.run(rebar3, { "as", "dap", "escriptize" })
+ c.spawn(callback)
+ end,
+ },
+ default_options = {
+ cmd = { path.concat { root_dir, "_build", "default", "bin", ("erlang_ls%s"):format(erlang_ls_file_ext) } },
+ },
+ }
+end
diff --git a/lua/nvim-lsp-installer/servers/init.lua b/lua/nvim-lsp-installer/servers/init.lua
index 48516442..35c23627 100644
--- a/lua/nvim-lsp-installer/servers/init.lua
+++ b/lua/nvim-lsp-installer/servers/init.lua
@@ -56,6 +56,7 @@ local CORE_SERVERS = Data.set_of {
"elmls",
"ember",
"emmet_ls",
+ "erlangls",
"eslintls",
"fortls",
"gopls",