aboutsummaryrefslogtreecommitdiffstats
path: root/lua
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
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')
-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
-rw-r--r--lua/nvim-lsp-installer/servers/r_language_server/init.lua31
4 files changed, 39 insertions, 29 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 {
diff --git a/lua/nvim-lsp-installer/servers/r_language_server/init.lua b/lua/nvim-lsp-installer/servers/r_language_server/init.lua
index c85107c1..c8ae0f41 100644
--- a/lua/nvim-lsp-installer/servers/r_language_server/init.lua
+++ b/lua/nvim-lsp-installer/servers/r_language_server/init.lua
@@ -1,6 +1,5 @@
local server = require "nvim-lsp-installer.server"
-local process = require "nvim-lsp-installer.process"
-local context = require "nvim-lsp-installer.installers.context"
+local path = require "nvim-lsp-installer.path"
return function(name, root_dir)
local function create_install_script(install_dir)
@@ -32,20 +31,22 @@ languageserver::run();
root_dir = root_dir,
homepage = "https://github.com/REditorSupport/languageserver",
languages = { "R" },
- installer = {
- function(_, callback, ctx)
- process.spawn("R", {
- cwd = ctx.install_dir,
- args = { "-e", create_install_script(ctx.install_dir) },
- stdio_sink = ctx.stdio_sink,
- }, callback)
- end,
- context.receipt(function(receipt)
- receipt:with_primary_source(receipt.r_package "languageserver")
- end),
- },
+ async = true,
+ ---@param ctx InstallContext
+ installer = function(ctx)
+ ctx.spawn.R {
+ "--no-save",
+ on_spawn = function(_, stdio)
+ local stdin = stdio[1]
+ stdin:write(create_install_script(ctx.cwd:get()))
+ stdin:close()
+ end,
+ }
+ ctx.fs:write_file("server.R", server_script)
+ ctx.receipt:with_primary_source(ctx.receipt.r_package "languageserver")
+ end,
default_options = {
- cmd = { "R", "--slave", "-e", server_script },
+ cmd = { "R", "--slave", "-f", path.concat { root_dir, "server.R" } },
},
}
end