diff options
| author | William Boman <william@redwill.se> | 2023-02-20 22:19:39 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-20 22:19:39 +0100 |
| commit | b8a6632a0f2d263199d5d480ca85477fe0f414ab (patch) | |
| tree | 57e1ee0f3cef078ec144ecdf1b2fa861acf47755 /lua/mason-registry/index/r-languageserver | |
| parent | chore: autogenerate (#1015) (diff) | |
| download | mason-b8a6632a0f2d263199d5d480ca85477fe0f414ab.tar mason-b8a6632a0f2d263199d5d480ca85477fe0f414ab.tar.gz mason-b8a6632a0f2d263199d5d480ca85477fe0f414ab.tar.bz2 mason-b8a6632a0f2d263199d5d480ca85477fe0f414ab.tar.lz mason-b8a6632a0f2d263199d5d480ca85477fe0f414ab.tar.xz mason-b8a6632a0f2d263199d5d480ca85477fe0f414ab.tar.zst mason-b8a6632a0f2d263199d5d480ca85477fe0f414ab.zip | |
feat: configurable registries (#1016)
Diffstat (limited to 'lua/mason-registry/index/r-languageserver')
| -rw-r--r-- | lua/mason-registry/index/r-languageserver/init.lua | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/lua/mason-registry/index/r-languageserver/init.lua b/lua/mason-registry/index/r-languageserver/init.lua new file mode 100644 index 00000000..acb12ea4 --- /dev/null +++ b/lua/mason-registry/index/r-languageserver/init.lua @@ -0,0 +1,87 @@ +local a = require "mason-core.async" +local async_uv = require "mason-core.async.uv" +local Pkg = require "mason-core.package" +local path = require "mason-core.path" +local github = require "mason-core.managers.github" + +---@param install_dir string +---@param ref string +local function create_install_script(install_dir, ref) + return ([[ +options(langserver_library = %q); +options(langserver_quiet = FALSE); +options(repos = list(CRAN = "http://cran.rstudio.com/")); +rlsLib <- getOption("langserver_library"); +.libPaths(new = rlsLib); + +didInstallRemotes <- FALSE; +tryCatch( + expr = { library("remotes") }, + error = function (e) { + install.packages("remotes", lib = rlsLib); + loadNamespace("remotes", lib.loc = rlsLib); + didInstallRemotes <- TRUE; + } +); + +# We set force = TRUE because this command will error if languageserversetup is already installed (even if it's at a +# different library location). +remotes::install_github("jozefhajnala/languageserversetup", lib = rlsLib, force = TRUE); + +if (didInstallRemotes) { + remove.packages("remotes", lib = rlsLib); +} + +loadNamespace("languageserversetup", lib.loc = rlsLib); +languageserversetup::languageserver_install( + fullReinstall = FALSE, + confirmBeforeInstall = FALSE, + strictLibrary = TRUE, + ref = %q +); +library("languageserver", lib.loc = rlsLib); +]]):format(install_dir, ref) +end + +---@param install_dir string +local function create_server_script(install_dir) + return ([[ +options("langserver_library" = %q); +rlsLib <- getOption("langserver_library"); +.libPaths(new = c(rlsLib, .libPaths())); +loadNamespace("languageserver", lib.loc = rlsLib); +languageserver::run(); + ]]):format(install_dir) +end + +return Pkg.new { + name = "r-languageserver", + desc = [[An implementation of the Language Server Protocol for R]], + homepage = "https://github.com/REditorSupport/languageserver", + languages = { Pkg.Lang.R }, + categories = { Pkg.Cat.LSP }, + ---@async + ---@param ctx InstallContext + install = function(ctx) + local source = github.release_version { repo = "REditorSupport/languageserver" } + source.with_receipt() + ctx.spawn.R { + "--no-save", + on_spawn = a.scope(function(_, stdio) + local stdin = stdio[1] + async_uv.write(stdin, create_install_script(ctx.cwd:get(), source.release)) + async_uv.shutdown(stdin) + async_uv.close(stdin) + end), + } + ctx.fs:write_file("server.R", create_server_script(ctx.package:get_install_path())) + + ctx:link_bin( + "r-languageserver", + ctx:write_shell_exec_wrapper( + "r-languageserver", + ("R --slave -f %q"):format(path.concat { ctx.package:get_install_path(), "server.R" }) + ) + ) + end, +} |
