mirror of
https://github.com/NotAShelf/neovim-flake.git
synced 2024-11-08 01:05:58 +01:00
r: implementing lsp
This commit is contained in:
parent
cb7ff874e2
commit
6915c3f764
3 changed files with 84 additions and 0 deletions
|
@ -60,6 +60,7 @@ isMaximal: {
|
|||
python.enable = isMaximal;
|
||||
dart.enable = isMaximal;
|
||||
bash.enable = isMaximal;
|
||||
r.enable = isMaximal;
|
||||
tailwind.enable = isMaximal;
|
||||
typst.enable = isMaximal;
|
||||
clang = {
|
||||
|
|
|
@ -17,6 +17,7 @@ in {
|
|||
./ocaml.nix
|
||||
./php.nix
|
||||
./python.nix
|
||||
./r.nix
|
||||
./rust.nix
|
||||
./sql.nix
|
||||
./svelte.nix
|
||||
|
|
82
modules/plugins/languages/r.nix
Normal file
82
modules/plugins/languages/r.nix
Normal file
|
@ -0,0 +1,82 @@
|
|||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (builtins) attrNames;
|
||||
inherit (lib.options) mkEnableOption mkOption literalExpression;
|
||||
inherit (lib.meta) getExe;
|
||||
inherit (lib.modules) mkIf mkMerge;
|
||||
inherit (lib.lists) isList;
|
||||
inherit (lib.types) enum either listOf package str bool;
|
||||
inherit (lib.nvim.lua) expToLua;
|
||||
|
||||
cfg = config.vim.languages.r;
|
||||
|
||||
r-with-languageserver = pkgs.rWrapper.override {
|
||||
packages = with pkgs.rPackages; [languageserver];
|
||||
};
|
||||
|
||||
defaultServer = "r_language_server";
|
||||
servers = {
|
||||
r_language_server = {
|
||||
package = pkgs.writeShellScriptBin "r_lsp" ''
|
||||
${r-with-languageserver}/bin/R --slave -e "languageserver::run()"
|
||||
'';
|
||||
lspConfig = ''
|
||||
lspconfig.r_language_server.setup{
|
||||
capabilities = capabilities;
|
||||
on_attach = default_on_attach;
|
||||
cmd = ${
|
||||
if isList cfg.lsp.package
|
||||
then expToLua cfg.lsp.package
|
||||
else ''{"${lib.getExe cfg.lsp.package}"}''
|
||||
}
|
||||
}
|
||||
'';
|
||||
};
|
||||
};
|
||||
in {
|
||||
options.vim.languages.r = {
|
||||
enable = mkEnableOption "R language support";
|
||||
|
||||
treesitter = {
|
||||
enable = mkEnableOption "R treesitter" // {default = config.vim.languages.enableTreesitter;};
|
||||
package = mkOption {
|
||||
description = "R treesitter grammar to use";
|
||||
type = package;
|
||||
default = pkgs.vimPlugins.nvim-treesitter.builtGrammars.r;
|
||||
};
|
||||
};
|
||||
|
||||
lsp = {
|
||||
enable = mkEnableOption "R LSP support" // {default = config.vim.languages.enableLSP;};
|
||||
|
||||
server = mkOption {
|
||||
description = "R LSP server to use";
|
||||
type = enum (attrNames servers);
|
||||
default = defaultServer;
|
||||
};
|
||||
|
||||
package = mkOption {
|
||||
description = "R LSP server package, or the command to run as a list of strings";
|
||||
example = literalExpression "[ (lib.getExe pkgs.jdt-language-server) \"-data\" \"~/.cache/jdtls/workspace\" ]";
|
||||
type = either package (listOf str);
|
||||
default = servers.${cfg.lsp.server}.package;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable (mkMerge [
|
||||
(mkIf cfg.treesitter.enable {
|
||||
vim.treesitter.enable = true;
|
||||
vim.treesitter.grammars = [cfg.treesitter.package];
|
||||
})
|
||||
|
||||
(mkIf cfg.lsp.enable {
|
||||
vim.lsp.lspconfig.enable = true;
|
||||
vim.lsp.lspconfig.sources.r-lsp = servers.${cfg.lsp.server}.lspConfig;
|
||||
})
|
||||
]);
|
||||
}
|
Loading…
Reference in a new issue