aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/installers
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2021-12-05 18:57:02 +0100
committerGitHub <noreply@github.com>2021-12-05 18:57:02 +0100
commitc82abb3117d83a36b58f07d341fd56a00bdfd360 (patch)
treec6efa60621a8ab8eb9d128e4a6c75f89aea82a62 /lua/nvim-lsp-installer/installers
parentsumneko_lua: don't provide -E argument as it's not needed (#309) (diff)
downloadmason-c82abb3117d83a36b58f07d341fd56a00bdfd360.tar
mason-c82abb3117d83a36b58f07d341fd56a00bdfd360.tar.gz
mason-c82abb3117d83a36b58f07d341fd56a00bdfd360.tar.bz2
mason-c82abb3117d83a36b58f07d341fd56a00bdfd360.tar.lz
mason-c82abb3117d83a36b58f07d341fd56a00bdfd360.tar.xz
mason-c82abb3117d83a36b58f07d341fd56a00bdfd360.tar.zst
mason-c82abb3117d83a36b58f07d341fd56a00bdfd360.zip
add ccls (#299)
Diffstat (limited to 'lua/nvim-lsp-installer/installers')
-rw-r--r--lua/nvim-lsp-installer/installers/context.lua27
-rw-r--r--lua/nvim-lsp-installer/installers/init.lua33
-rw-r--r--lua/nvim-lsp-installer/installers/std.lua11
3 files changed, 60 insertions, 11 deletions
diff --git a/lua/nvim-lsp-installer/installers/context.lua b/lua/nvim-lsp-installer/installers/context.lua
index bdb993a5..e80485a4 100644
--- a/lua/nvim-lsp-installer/installers/context.lua
+++ b/lua/nvim-lsp-installer/installers/context.lua
@@ -3,6 +3,8 @@ 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 fs = require "nvim-lsp-installer.fs"
+local path = require "nvim-lsp-installer.path"
local M = {}
@@ -96,7 +98,12 @@ function M.use_github_release_file(repo, file)
M.use_github_release(repo),
function(server, callback, context)
local function get_download_url(version)
- local target_file = type(file) == "function" and file(version) or file
+ local target_file
+ if type(file) == "function" then
+ target_file = file(version)
+ else
+ target_file = file
+ end
if not target_file then
log.fmt_error(
"Unable to find which release file to download. server_name=%s, repo=%s",
@@ -160,4 +167,22 @@ function M.set(fn)
end
end
+---@param rel_path string @The relative path from the current installation working directory.
+function M.set_working_dir(rel_path)
+ ---@type ServerInstallerFunction
+ return vim.schedule_wrap(function(server, callback, context)
+ log.fmt_debug("Changing installation working directory for %s", server.name)
+ local new_dir = path.concat { context.install_dir, rel_path }
+ if not fs.dir_exists(new_dir) then
+ local ok = pcall(fs.mkdirp, new_dir)
+ if not ok then
+ context.stdio_sink.stderr(("Failed to create directory %s.\n"):format(new_dir))
+ return callback(false)
+ end
+ end
+ context.install_dir = new_dir
+ callback(true)
+ end)
+end
+
return M
diff --git a/lua/nvim-lsp-installer/installers/init.lua b/lua/nvim-lsp-installer/installers/init.lua
index fdf3b0f4..a04eeafb 100644
--- a/lua/nvim-lsp-installer/installers/init.lua
+++ b/lua/nvim-lsp-installer/installers/init.lua
@@ -1,9 +1,21 @@
local platform = require "nvim-lsp-installer.platform"
local log = require "nvim-lsp-installer.log"
local Data = require "nvim-lsp-installer.data"
+local fs = require "nvim-lsp-installer.fs"
+local path = require "nvim-lsp-installer.path"
local M = {}
+---@param installer ServerInstallerFunction[]|ServerInstallerFunction
+---@return ServerInstallerFunction
+local function normalize_installer(installer)
+ if type(installer) == "table" then
+ return M.pipe(installer)
+ else
+ return installer
+ end
+end
+
---@alias ServerInstallCallback fun(success: boolean)
---@class ServerInstallContext
@@ -120,11 +132,7 @@ function M.on(platform_table)
return function(server, callback, context)
local installer = get_by_platform(platform_table)
if installer then
- if type(installer) == "function" then
- installer(server, callback, context)
- else
- M.pipe(installer)(server, callback, context)
- end
+ normalize_installer(installer)(server, callback, context)
else
callback(true)
end
@@ -139,11 +147,7 @@ function M.when(platform_table)
return function(server, callback, context)
local installer = get_by_platform(platform_table)
if installer then
- if type(installer) == "function" then
- installer(server, callback, context)
- else
- M.pipe(installer)(server, callback, context)
- end
+ normalize_installer(installer)(server, callback, context)
else
context.stdio_sink.stderr(
("Current operating system is not yet supported for server %q.\n"):format(server.name)
@@ -153,4 +157,13 @@ function M.when(platform_table)
end
end
+---@param installer ServerInstallerFunction|ServerInstallerFunction[] @The installer to execute in a new installer context.
+function M.branch_context(installer)
+ ---@type ServerInstallerFunction
+ return function(server, callback, context)
+ local new_context = vim.deepcopy(context)
+ normalize_installer(installer)(server, callback, new_context)
+ end
+end
+
return M
diff --git a/lua/nvim-lsp-installer/installers/std.lua b/lua/nvim-lsp-installer/installers/std.lua
index 4a95e9c8..f123b3ae 100644
--- a/lua/nvim-lsp-installer/installers/std.lua
+++ b/lua/nvim-lsp-installer/installers/std.lua
@@ -248,6 +248,17 @@ function M.git_clone(repo_url)
end
end
+function M.git_submodule_update()
+ ---@type ServerInstallerFunction
+ return function(_, callback, context)
+ process.spawn("git", {
+ args = { "submodule", "update", "--init", "--recursive" },
+ cwd = context.install_dir,
+ stdio_sink = context.stdio_sink,
+ }, callback)
+ end
+end
+
---@param opts {args: string[]}
function M.gradlew(opts)
---@type ServerInstallerFunction