languageserver
languageserver copied to clipboard
nvim-lsp-installer must install packages and dependencies locally
I would like to know if the devs working on this package know how to integrate with nvim-lsp. I have enjoyed this lsp installer if only it had R support then it would be feature complete for me.
The full issue is documented here.
https://github.com/williamboman/nvim-lsp-installer/pull/81
It is technically possible to create a sandbox environment for languageserver by installing it in an empty directory and carefully injecting the new path to .libPaths(). However there are not much benefits of doing so because most R users are used to having all packages installed globally.
I see what you are saying. I personally would see a lot of value in this sandbox/.libPaths() approach.
@alexhallam It's work in Neovim 0.5.1
Install languageserver in some dir, example ~/.local/share/nvim/lsp_servers/r_language_server
install.packages("languageserver", lib = "~/.local/share/nvim/lsp_servers/r_language_server")
Setup LSP
require('lspconfig').r_language_server.setup{
cmd = {
'R',
'--slave',
'-e',
[[
.libPaths(new = "~/.local/share/nvim/lsp_servers/r_language_server");
langserver <- languageserver:::LanguageServer$new("localhost", NULL);
.libPaths(new = Sys.getenv("R_LIBS_USER"));
langserver$run()
]]
}
}


Nice. By the way, why do you need the second .libPaths to add R_LIBS_USER? I think it is in .libPaths in default.
.libPaths() with new argument not add a new path, it changes R_LIBS_USER
> .libPaths()
[1] "/home/pedro/.R" "/usr/lib/R/library"
> .libPaths(new = "~/.local/share/nvim/lsp_servers/r_language_server")
> .libPaths()
[1] "/home/pedro/.local/share/nvim/lsp_servers
/r_language_server"
[2] "/usr/lib/R/library"
Ai, you are right. Didn't know that before. Maybe this is better?
.libPaths(new = c(
"~/.local/share/nvim/lsp_servers/r_language_server",
Sys.getenv("R_LIBS_USER")))
This works but does not completely isolate languageserver
cmd = { 'R', '--slave', '-e',
[[
.libPaths(new = c("~/.local/share/nvim/lsp_servers/r_language_server", Sys.getenv("R_LIBS_USER")));
langserver <- languageserver:::LanguageServer$new("localhost", NULL);
langserver$run()
]]
Note that LSP is listing the languageserver package, but it is installed in "~/.local/share/nvim/lsp_servers/r_language_server"

But setting .libPaths(new = Sys.getenv("R_LIBS_USER")) means that languageserver no longer is able to find its dependencies in "~/.local/share/nvim/lsp_servers/r_language_server"?
For example, what happens if you uninstall a dependency of languagserver, say lintr from your regular R?
But setting
.libPaths(new = Sys.getenv("R_LIBS_USER"))means thatlanguageserverno longer is able to find its dependencies in"~/.local/share/nvim/lsp_servers/r_language_server"?
Yes
I did a test, installed all languageserver dependencies in "~/.local/share/nvim/lsp_servers/r_language_server".
backports crayon glue magrittr purrr rlang tibble yaml
brew desc highr mockery R.cache roxygen2 utf8
callr digest jsonlite pillar R.methodsS3 rprojroot vctrs
cli ellipsis knitr pkgconfig R.oo rstudioapi withr
collections evaluate languageserver pkgload R.utils stringi xfun
commonmark fansi lifecycle processx R6 stringr xml2
cpp11 fs lintr ps rematch2 styler xmlparsedata
I removed three dependencies from my .libPaths(), R6, xml2 and lintr
> .libPaths()
[1] "/home/pedro/.R" "/usr/lib/R/library"
> library(xml2)
Error in library(xml2) : there is no package called ‘xml2’
> library(R6)
Error in library(R6) : there is no package called ‘R6’
> library(lintr)
Error in library(lintr) : there is no package called ‘lintr’
LSP is still working

Language client log: /home/pedro/.cache/nvim/lsp.log
Detected filetype: r
1 client(s) attached to this buffer:
Client: r_language_server (id: 1, pid: 402633, bufnr: [3, 4])
filetypes: r, rmd
autostart: true
root directory: /home/pedro
cmd: R --slave -e .libPaths(new = "~/.local/share/nvim/lsp_servers/r_language_server"); langserver <- languageserver:::LanguageServer$new("localhost", NULL); .libPaths(new = Sys.getenv("R_LIBS_USER")); langserver$run()
I expected LSP to break, because when LSP is executed langserver$run() .libPaths() not contains ~/.local/share/nvim/lsp_servers/r_language_server
Thanks @aspeddro for the info! I will update my nvim and give it a try. I will also test it out in lunarvim.