aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/core
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-04-06 11:35:35 +0200
committerGitHub <noreply@github.com>2022-04-06 11:35:35 +0200
commit0795a757e8b78116f7e6d9e353bcb0443c7dbc52 (patch)
tree76f8d5d5eb55bb438db0de84a741b2d6b81fe073 /lua/nvim-lsp-installer/core
parentfix(pip3): always use normalized "python" executable with venv-enhanced path ... (diff)
downloadmason-0795a757e8b78116f7e6d9e353bcb0443c7dbc52.tar
mason-0795a757e8b78116f7e6d9e353bcb0443c7dbc52.tar.gz
mason-0795a757e8b78116f7e6d9e353bcb0443c7dbc52.tar.bz2
mason-0795a757e8b78116f7e6d9e353bcb0443c7dbc52.tar.lz
mason-0795a757e8b78116f7e6d9e353bcb0443c7dbc52.tar.xz
mason-0795a757e8b78116f7e6d9e353bcb0443c7dbc52.tar.zst
mason-0795a757e8b78116f7e6d9e353bcb0443c7dbc52.zip
fix(r_language_server): run install script via stdin (#578)
Fixes #568.
Diffstat (limited to 'lua/nvim-lsp-installer/core')
-rw-r--r--lua/nvim-lsp-installer/core/fs.lua21
-rw-r--r--lua/nvim-lsp-installer/core/installer/context.lua7
-rw-r--r--lua/nvim-lsp-installer/core/spawn.lua9
3 files changed, 23 insertions, 14 deletions
diff --git a/lua/nvim-lsp-installer/core/fs.lua b/lua/nvim-lsp-installer/core/fs.lua
index 3819bd51..b915baf5 100644
--- a/lua/nvim-lsp-installer/core/fs.lua
+++ b/lua/nvim-lsp-installer/core/fs.lua
@@ -6,15 +6,6 @@ local M = {}
---@async
---@param path string
----@param contents string
-function M.append_file(path, contents)
- local fd = uv.fs_open(path, "a", 438)
- uv.fs_write(fd, contents, -1)
- uv.fs_close(fd)
-end
-
----@async
----@param path string
function M.file_exists(path)
local ok, fd = pcall(uv.fs_open, path, "r", 438)
if not ok then
@@ -81,11 +72,19 @@ end
---@async
---@param path string
---@param contents string
-function M.write_file(path, contents)
+---@param flags string @Defaults to "w".
+function M.write_file(path, contents, flags)
log.fmt_debug("fs: write_file %s", path)
- local fd = assert(uv.fs_open(path, "w", 438))
+ local fd = assert(uv.fs_open(path, flags or "w", 438))
uv.fs_write(fd, contents, -1)
assert(uv.fs_close(fd))
end
+---@async
+---@param path string
+---@param contents string
+function M.append_file(path, contents)
+ M.write_file(path, contents, "a")
+end
+
return M
diff --git a/lua/nvim-lsp-installer/core/installer/context.lua b/lua/nvim-lsp-installer/core/installer/context.lua
index ad956178..0b13859b 100644
--- a/lua/nvim-lsp-installer/core/installer/context.lua
+++ b/lua/nvim-lsp-installer/core/installer/context.lua
@@ -43,6 +43,13 @@ function ContextualFs:append_file(rel_path, contents)
end
---@async
+---@param rel_path string @The relative path from the current working directory to the file to write.
+---@param contents string
+function ContextualFs:write_file(rel_path, contents)
+ return fs.write_file(path.concat { self.cwd:get(), rel_path }, contents)
+end
+
+---@async
---@param rel_path string @The relative path from the current working directory.
function ContextualFs:file_exists(rel_path)
return fs.file_exists(path.concat { self.cwd:get(), rel_path })
diff --git a/lua/nvim-lsp-installer/core/spawn.lua b/lua/nvim-lsp-installer/core/spawn.lua
index 992b1557..4776ff66 100644
--- a/lua/nvim-lsp-installer/core/spawn.lua
+++ b/lua/nvim-lsp-installer/core/spawn.lua
@@ -3,8 +3,6 @@ local Result = require "nvim-lsp-installer.core.result"
local process = require "nvim-lsp-installer.process"
local platform = require "nvim-lsp-installer.platform"
-local async_spawn = a.promisify(process.spawn)
-
---@alias JobSpawn Record<string, async fun(opts: JobSpawnOpts): Result>
---@type JobSpawn
local spawn = {
@@ -58,7 +56,12 @@ setmetatable(spawn, {
end
local cmd = self._aliases[k] or k
- local _, exit_code = async_spawn(cmd, spawn_args)
+ local _, exit_code = a.wait(function(resolve)
+ local handle, stdio = process.spawn(cmd, spawn_args, resolve)
+ if args.on_spawn and handle and stdio then
+ args.on_spawn(handle, stdio)
+ end
+ end)
if exit_code == 0 then
return Result.success {