modules/lsp: switch to explicit lib calls

This commit is contained in:
NotAShelf 2024-03-12 03:46:29 +03:00
parent dfc7c6737f
commit c488f0490f
No known key found for this signature in database
GPG key ID: 02D1DD3FA08B6B29
33 changed files with 285 additions and 273 deletions

View file

@ -15,10 +15,12 @@
mkBinding = binding: action: "vim.api.nvim_buf_set_keymap(bufnr, 'n', '${binding.value}', '<cmd>lua ${action}<CR>', {noremap=true, silent=true, desc='${binding.description}'})";
in {
config = mkIf cfg.enable {
vim.startPlugins = optional usingNvimCmp "cmp-nvim-lsp";
vim = {
startPlugins = optional usingNvimCmp "cmp-nvim-lsp";
vim.autocomplete.sources = {"nvim_lsp" = "[LSP]";};
vim.luaConfigRC.lsp-setup = ''
autocomplete.sources = {"nvim_lsp" = "[LSP]";};
luaConfigRC.lsp-setup = ''
vim.g.formatsave = ${boolToString cfg.formatOnSave};
local attach_keymaps = function(client, bufnr)
@ -110,4 +112,5 @@ in {
${optionalString usingNvimCmp "capabilities = require('cmp_nvim_lsp').default_capabilities()"}
'';
};
};
}

View file

@ -1,4 +1,4 @@
_: {
{
imports = [
# nvim lsp support
./config.nix

View file

@ -3,20 +3,21 @@
lib,
...
}: let
inherit (lib) mkIf nvim;
inherit (lib.modules) mkIf;
inherit (lib.nvim.dag) entryAnywhere;
cfg = config.vim.lsp;
in {
config = mkIf (cfg.enable && cfg.lightbulb.enable) {
vim.startPlugins = ["nvim-lightbulb"];
vim = {
startPlugins = ["nvim-lightbulb"];
vim.configRC.lightbulb = nvim.dag.entryAnywhere ''
autocmd CursorHold,CursorHoldI * lua require'nvim-lightbulb'.update_lightbulb()
'';
luaConfigRC.lightbulb = entryAnywhere ''
vim.api.nvim_command('autocmd CursorHold,CursorHoldI * lua require\'nvim-lightbulb\'.update_lightbulb()')
vim.luaConfigRC.lightbulb = nvim.dag.entryAnywhere ''
-- Enable trouble diagnostics viewer
require'nvim-lightbulb'.setup()
'';
};
};
}

View file

@ -1,4 +1,4 @@
_: {
{
imports = [
./lightbulb.nix
./config.nix

View file

@ -1,9 +1,5 @@
{
config,
lib,
...
}: let
inherit (lib) mkEnableOption;
{lib, ...}: let
inherit (lib.options) mkEnableOption;
in {
options.vim.lsp = {
lightbulb = {

View file

@ -3,19 +3,22 @@
lib,
...
}: let
inherit (lib) mkIf nvim optionalString;
inherit (lib.modules) mkIf;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.strings) optionalString;
cfg = config.vim.lsp;
in {
config = mkIf (cfg.enable && cfg.lspSignature.enable) {
vim.startPlugins = [
vim = {
startPlugins = [
"lsp-signature"
];
vim.luaConfigRC.lsp-signature = nvim.dag.entryAnywhere ''
luaConfigRC.lsp-signature = entryAnywhere ''
-- Enable lsp signature viewer
require("lsp_signature").setup({
${optionalString (config.vim.ui.borders.plugins.lsp-signature.enable) ''
${optionalString config.vim.ui.borders.plugins.lsp-signature.enable ''
bind = true, -- This is mandatory, otherwise border config won't get registered.
handler_opts = {
border = "${config.vim.ui.borders.plugins.lsp-signature.style}"
@ -24,4 +27,5 @@ in {
})
'';
};
};
}

View file

@ -1,4 +1,4 @@
_: {
{
imports = [
./lsp-signature.nix
./config.nix

View file

@ -1,13 +1,9 @@
{
config,
lib,
...
}: let
inherit (lib) mkEnableOption;
{lib, ...}: let
inherit (lib.options) mkEnableOption;
in {
options.vim.lsp = {
lspSignature = {
enable = mkEnableOption "lsp signature viewer";
enable = mkEnableOption "lsp signature viewer [lsp-signature]";
};
};
}

View file

@ -1,32 +1,35 @@
{
pkgs,
config,
lib,
...
}: let
inherit (lib) mkIf mkMerge nvim optionalString mapAttrs;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.strings) optionalString;
inherit (lib.attrsets) mapAttrs;
inherit (lib.nvim.dag) entryAfter;
cfg = config.vim.lsp;
in {
config = mkIf cfg.lspconfig.enable (mkMerge [
{
vim.lsp.enable = true;
vim = {
lsp.enable = true;
vim.startPlugins = ["nvim-lspconfig"];
startPlugins = ["nvim-lspconfig"];
vim.luaConfigRC.lspconfig = nvim.dag.entryAfter ["lsp-setup"] ''
luaConfigRC.lspconfig = entryAfter ["lsp-setup"] ''
local lspconfig = require('lspconfig')
${
# TODO: make border style configurable
optionalString (config.vim.ui.borders.enable) ''
optionalString config.vim.ui.borders.enable ''
require('lspconfig.ui.windows').default_options.border = '${config.vim.ui.borders.globalStyle}'
''
}
'';
};
}
{
vim.luaConfigRC = mapAttrs (_: v: (nvim.dag.entryAfter ["lspconfig"] v)) cfg.lspconfig.sources;
vim.luaConfigRC = mapAttrs (_: v: (entryAfter ["lspconfig"] v)) cfg.lspconfig.sources;
}
]);
}

View file

@ -1,4 +1,4 @@
_: {
{
imports = [
./config.nix
./lspconfig.nix

View file

@ -1,17 +1,13 @@
{
pkgs,
config,
lib,
...
}: let
inherit (lib) mkEnableOption mkOption types;
{lib, ...}: let
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.types) attrsOf str;
in {
options.vim.lsp.lspconfig = {
enable = mkEnableOption "nvim-lspconfig, also enabled automatically";
sources = mkOption {
description = "nvim-lspconfig sources";
type = with types; attrsOf str;
type = attrsOf str;
default = {};
};
};

View file

@ -1,16 +1,16 @@
{
pkgs,
config,
lib,
...
}: let
inherit (lib) mkIf nvim;
inherit (lib.modules) mkIf;
inherit (lib.nvim.dag) entryAnywhere;
cfg = config.vim.lsp;
in {
config = mkIf (cfg.enable && cfg.lspkind.enable) {
vim.startPlugins = ["lspkind"];
vim.luaConfigRC.lspkind = nvim.dag.entryAnywhere ''
vim.luaConfigRC.lspkind = entryAnywhere ''
local lspkind = require'lspkind'
local lspkind_opts = {
mode = '${cfg.lspkind.mode}'

View file

@ -1,4 +1,4 @@
_: {
{
imports = [
./config.nix
./lspkind.nix

View file

@ -1,12 +1,6 @@
{
pkgs,
config,
lib,
...
}: let
inherit (lib) mkEnableOption mkOption types;
cfg = config.vim.lsp;
{lib, ...}: let
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.types) enum;
in {
options.vim.lsp = {
lspkind = {
@ -14,7 +8,7 @@ in {
mode = mkOption {
description = "Defines how annotations are shown";
type = with types; enum ["text" "text_symbol" "symbol_text" "symbol"];
type = enum ["text" "text_symbol" "symbol_text" "symbol"];
default = "symbol_text";
};
};

View file

@ -3,13 +3,14 @@
lib,
...
}: let
inherit (lib) mkIf nvim;
inherit (lib.modules) mkIf;
inherit (lib.nvim.dag) entryAfter;
cfg = config.vim.lsp;
in {
config = mkIf (cfg.enable && cfg.lsplines.enable) {
vim.startPlugins = ["lsp-lines"];
vim.luaConfigRC.lsplines = nvim.dag.entryAfter ["lspconfig"] ''
vim.luaConfigRC.lsplines = entryAfter ["lspconfig"] ''
require("lsp_lines").setup()
vim.diagnostic.config({

View file

@ -1,4 +1,4 @@
_: {
{
imports = [
./config.nix
./lsplines.nix

View file

@ -1,9 +1,11 @@
{lib, ...}: let
inherit (lib) mkEnableOption;
inherit (lib.options) mkEnableOption;
in {
options.vim.lsp = {
lsplines = {
enable = mkEnableOption "diagnostics using virtual lines on top of the real line of code. [lsp_lines]";
enable = mkEnableOption ''
diagnostics using virtual lines on top of the real line of code. [lsp_lines]
'';
};
};
}

View file

@ -3,7 +3,10 @@
lib,
...
}: let
inherit (lib) addDescriptionsToMappings mkIf mkSetLuaBinding mkMerge nvim optionalString;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.strings) optionalString;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.binds) addDescriptionsToMappings mkSetLuaBinding;
cfg = config.vim.lsp;
self = import ./lspsaga.nix {inherit lib;};
@ -12,11 +15,12 @@
mappings = addDescriptionsToMappings cfg.lspsaga.mappings mappingDefinitions;
in {
config = mkIf (cfg.enable && cfg.lspsaga.enable) {
vim.startPlugins = ["lspsaga"];
vim = {
startPlugins = ["lspsaga"];
vim.maps.visual = mkSetLuaBinding mappings.codeAction "require('lspsaga.codeaction').range_code_action";
vim.maps.normal = mkMerge [
maps = {
visual = mkSetLuaBinding mappings.codeAction "require('lspsaga.codeaction').range_code_action";
normal = mkMerge [
(mkSetLuaBinding mappings.lspFinder "require('lspsaga.provider').lsp_finder")
(mkSetLuaBinding mappings.renderHoveredDoc "require('lspsaga.hover').render_hover_doc")
@ -35,15 +39,15 @@ in {
(mkIf (!cfg.nvimCodeActionMenu.enable) (mkSetLuaBinding mappings.codeAction "require('lspsaga.codeaction').code_action"))
(mkIf (!cfg.lspSignature.enable) (mkSetLuaBinding mappings.signatureHelp "require('lspsaga.signaturehelp').signature_help"))
];
};
vim.luaConfigRC.lspsage = nvim.dag.entryAnywhere ''
-- Enable lspsaga
local saga = require 'lspsaga'
saga.init_lsp_saga({
${optionalString (config.vim.ui.borders.plugins.lspsaga.enable) ''
luaConfigRC.lspsaga = entryAnywhere ''
require('lspsaga').init_lsp_saga({
${optionalString config.vim.ui.borders.plugins.lspsaga.enable ''
border_style = '${config.vim.ui.borders.plugins.lspsaga.style}',
''}
})
'';
};
};
}

View file

@ -1,4 +1,4 @@
_: {
{
imports = [
./lspsaga.nix
./config.nix

View file

@ -1,5 +1,6 @@
{lib, ...}: let
inherit (lib) mkEnableOption mkMappingOption;
inherit (lib.options) mkEnableOption;
inherit (lib.nvim.binds) mkMappingOption;
in {
options.vim.lsp.lspsaga = {
enable = mkEnableOption "LSP Saga";

View file

@ -1,5 +1,6 @@
{lib, ...}: let
inherit (lib) mkEnableOption mkMappingOption;
inherit (lib.options) mkEnableOption;
inherit (lib.nvim.binds) mkMappingOption;
in {
options.vim.lsp = {
enable = mkEnableOption "LSP, also enabled automatically through null-ls and lspconfig options";

View file

@ -1,5 +1,4 @@
{
pkgs,
config,
lib,
...
@ -10,16 +9,18 @@
in {
config = mkIf cfg.null-ls.enable (mkMerge [
{
vim.lsp.enable = true;
vim.startPlugins = ["none-ls"];
vim = {
lsp.enable = true;
startPlugins = ["none-ls"];
vim.luaConfigRC.null_ls-setup = nvim.dag.entryAnywhere ''
luaConfigRC.null_ls-setup = nvim.dag.entryAnywhere ''
local null_ls = require("null-ls")
local null_helpers = require("null-ls.helpers")
local null_methods = require("null-ls.methods")
local ls_sources = {}
'';
vim.luaConfigRC.null_ls = nvim.dag.entryAfter ["null_ls-setup" "lsp-setup"] ''
luaConfigRC.null_ls = nvim.dag.entryAfter ["null_ls-setup" "lsp-setup"] ''
require('null-ls').setup({
debug = false,
diagnostics_format = "[#{m}] #{s} (#{c})",
@ -29,6 +30,7 @@ in {
on_attach = default_on_attach
})
'';
};
}
{
vim.luaConfigRC = mapAttrs (_: v: (nvim.dag.entryBetween ["null_ls"] ["null_ls-setup"] v)) cfg.null-ls.sources;

View file

@ -1,4 +1,4 @@
_: {
{
imports = [
./config.nix
./null-ls.nix

View file

@ -1,19 +1,13 @@
{
pkgs,
config,
lib,
...
}: let
inherit (lib) mkEnableOption mkOption types;
cfg = config.vim.lsp;
{lib, ...}: let
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.types) attrsOf str;
in {
options.vim.lsp.null-ls = {
enable = mkEnableOption "null-ls, also enabled automatically";
sources = mkOption {
description = "null-ls sources";
type = with types; attrsOf str;
type = attrsOf str;
default = {};
};
};

View file

@ -3,32 +3,35 @@
lib,
...
}: let
inherit (lib) addDescriptionsToMappings mkIf mkSetBinding nvim pushDownDefault;
inherit (lib.modules) mkIf;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.binds) mkSetBinding addDescriptionsToMappings pushDownDefault;
cfg = config.vim.lsp;
self = import ./nvim-code-action-menu.nix {inherit lib;};
mappingDefinitions = self.options.vim.lsp.nvimCodeActionMenu.mappings;
mappings = addDescriptionsToMappings cfg.nvimCodeActionMenu.mappings mappingDefinitions;
in {
config = mkIf (cfg.enable && cfg.nvimCodeActionMenu.enable) {
vim.startPlugins = ["nvim-code-action-menu"];
vim = {
startPlugins = ["nvim-code-action-menu"];
vim.maps.normal = mkSetBinding mappings.open ":CodeActionMenu<CR>";
maps.normal = mkSetBinding mappings.open ":CodeActionMenu<CR>";
vim.binds.whichKey.register = pushDownDefault {
binds.whichKey.register = pushDownDefault {
"<leader>c" = "+CodeAction";
};
vim.luaConfigRC.code-action-menu = nvim.dag.entryAnywhere ''
luaConfigRC.code-action-menu = entryAnywhere ''
-- border configuration
vim.g.code_action_menu_window_border = '${config.vim.ui.borders.plugins.code-action-menu.style}'
-- show individual sections of the code action menu
${lib.optionalString (cfg.nvimCodeActionMenu.show.details) "vim.g.code_action_menu_show_details = true"}
${lib.optionalString (cfg.nvimCodeActionMenu.show.diff) "vim.g.code_action_menu_show_diff = true"}
${lib.optionalString (cfg.nvimCodeActionMenu.show.actionKind) "vim.g.code_action_menu_show_action_kind = true"}
${lib.optionalString cfg.nvimCodeActionMenu.show.details "vim.g.code_action_menu_show_details = true"}
${lib.optionalString cfg.nvimCodeActionMenu.show.diff "vim.g.code_action_menu_show_diff = true"}
${lib.optionalString cfg.nvimCodeActionMenu.show.actionKind "vim.g.code_action_menu_show_action_kind = true"}
'';
};
};
}

View file

@ -1,4 +1,4 @@
_: {
{
imports = [
./nvim-code-action-menu.nix
./config.nix

View file

@ -1,5 +1,6 @@
{lib, ...}: let
inherit (lib) mkEnableOption mkMappingOption;
inherit (lib.options) mkEnableOption;
inherit (lib.nvim.binds) mkMappingOption;
in {
options.vim.lsp = {
nvimCodeActionMenu = {

View file

@ -3,8 +3,10 @@
lib,
...
}: let
inherit (lib) mkIf nvim addDescriptionsToMappings mkSetBinding mkMerge;
inherit (builtins) toString;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.binds) addDescriptionsToMappings mkSetBinding;
cfg = config.vim.lsp.nvim-docs-view;
self = import ./nvim-docs-view.nix {inherit lib;};
@ -17,7 +19,7 @@ in {
lsp.enable = true;
startPlugins = ["nvim-docs-view"];
luaConfigRC.nvim-docs-view = nvim.dag.entryAnywhere ''
luaConfigRC.nvim-docs-view = entryAnywhere ''
require("docs-view").setup {
position = "${cfg.position}",
width = ${toString cfg.width},

View file

@ -1,4 +1,4 @@
_: {
{
imports = [
./config.nix
./nvim-docs-view.nix

View file

@ -1,11 +1,13 @@
{lib, ...}: let
inherit (lib) mkEnableOption mkOption types mkMappingOption;
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.types) enum int;
inherit (lib.nvim.binds) mkMappingOption;
in {
options.vim.lsp.nvim-docs-view = {
enable = mkEnableOption "nvim-docs-view, for displaying lsp hover documentation in a side panel.";
position = mkOption {
type = types.enum ["left" "right" "top" "bottom"];
type = enum ["left" "right" "top" "bottom"];
default = "right";
description = ''
Where to open the docs view panel
@ -13,7 +15,7 @@ in {
};
height = mkOption {
type = types.int;
type = int;
default = 10;
description = ''
Height of the docs view panel if the position is set to either top or bottom
@ -21,7 +23,7 @@ in {
};
width = mkOption {
type = types.int;
type = int;
default = 60;
description = ''
Width of the docs view panel if the position is set to either left or right
@ -29,12 +31,14 @@ in {
};
updateMode = mkOption {
type = types.enum ["auto" "manual"];
type = enum ["auto" "manual"];
default = "auto";
description = ''
Determines the mechanism used to update the docs view panel content.
- If auto, the content will update upon cursor move.
- If manual, the content will only update once :DocsViewUpdate is called
Determines the mechanism used to update the docs view panel content
Possible values:
- auto: the content will update upon cursor move.
- manual: the content will only update once :DocsViewUpdate is called
'';
};

View file

@ -3,19 +3,21 @@
lib,
...
}: let
inherit (lib) addDescriptionsToMappings mkIf mkMerge mkSetBinding nvim pushDownDefault;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.binds) addDescriptionsToMappings mkSetBinding pushDownDefault;
cfg = config.vim.lsp;
self = import ./trouble.nix {inherit lib;};
mappingDefinitions = self.options.vim.lsp.trouble.mappings;
mappings = addDescriptionsToMappings cfg.trouble.mappings mappingDefinitions;
in {
config = mkIf (cfg.enable && cfg.trouble.enable) {
vim.startPlugins = ["trouble"];
vim = {
startPlugins = ["trouble"];
vim.maps.normal = mkMerge [
maps.normal = mkMerge [
(mkSetBinding mappings.toggle "<cmd>TroubleToggle<CR>")
(mkSetBinding mappings.workspaceDiagnostics "<cmd>TroubleToggle workspace_diagnostics<CR>")
(mkSetBinding mappings.documentDiagnostics "<cmd>TroubleToggle document_diagnostics<CR>")
@ -24,15 +26,16 @@ in {
(mkSetBinding mappings.locList "<cmd>TroubleToggle loclist<CR>")
];
vim.binds.whichKey.register = pushDownDefault {
binds.whichKey.register = pushDownDefault {
"<leader>l" = "Trouble";
"<leader>x" = "+Trouble";
"<leader>lw" = "Workspace";
};
vim.luaConfigRC.trouble = nvim.dag.entryAnywhere ''
luaConfigRC.trouble = entryAnywhere ''
-- Enable trouble diagnostics viewer
require("trouble").setup {}
'';
};
};
}

View file

@ -1,4 +1,4 @@
_: {
{
imports = [
./trouble.nix
./config.nix

View file

@ -1,5 +1,6 @@
{lib, ...}: let
inherit (lib) mkEnableOption mkMappingOption;
inherit (lib.options) mkEnableOption;
inherit (lib.nvim.binds) mkMappingOption;
in {
options.vim.lsp = {
trouble = {