From eefc7a9d1dad0f619198956f8ba899d080ebf4cd Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Thu, 16 May 2024 19:09:20 +0300 Subject: [PATCH] lsp/null-lsp: allow null-ls options to be configured This should probably still be converted to setupOpts. Missing docs --- modules/plugins/lsp/null-ls/config.nix | 45 +++++++++++++++---------- modules/plugins/lsp/null-ls/null-ls.nix | 24 ++++++++++++- 2 files changed, 51 insertions(+), 18 deletions(-) diff --git a/modules/plugins/lsp/null-ls/config.nix b/modules/plugins/lsp/null-ls/config.nix index 83dada5..e0d1694 100644 --- a/modules/plugins/lsp/null-ls/config.nix +++ b/modules/plugins/lsp/null-ls/config.nix @@ -5,6 +5,7 @@ }: let inherit (lib.modules) mkIf mkMerge; inherit (lib.attrsets) mapAttrs; + inherit (lib.trivial) boolToString; inherit (lib.nvim.dag) entryAnywhere entryAfter entryBetween; cfg = config.vim.lsp; @@ -12,26 +13,36 @@ in { config = mkIf cfg.null-ls.enable (mkMerge [ { vim = { + startPlugins = [ + "none-ls" + "plenary-nvim" + ]; + + # null-ls implies LSP already being set up + # since it will hook into LSPs to receive information lsp.enable = true; - startPlugins = ["none-ls"]; - luaConfigRC.null_ls-setup = entryAnywhere '' - local null_ls = require("null-ls") - local null_helpers = require("null-ls.helpers") - local null_methods = require("null-ls.methods") - local ls_sources = {} - ''; + luaConfigRC = { + # early setup for null-ls + null_ls-setup = entryAnywhere '' + local null_ls = require("null-ls") + local null_helpers = require("null-ls.helpers") + local null_methods = require("null-ls.methods") + local ls_sources = {} + ''; - luaConfigRC.null_ls = entryAfter ["null_ls-setup" "lsp-setup"] '' - require('null-ls').setup({ - debug = false, - diagnostics_format = "[#{m}] #{s} (#{c})", - debounce = 250, - default_timeout = 5000, - sources = ls_sources, - on_attach = default_on_attach - }) - ''; + # null-ls setup + null_ls = entryAfter ["null_ls-setup" "lsp-setup"] '' + require('null-ls').setup({ + debug = ${boolToString cfg.null-ls.debug}, + diagnostics_format = "${cfg.null-ls.diagnostics_format}", + debounce = ${toString cfg.null-ls.debounce}, + default_timeout = ${toString cfg.null-ls.default_timeout}, + sources = ls_sources, + on_attach = default_on_attach + }) + ''; + }; }; } { diff --git a/modules/plugins/lsp/null-ls/null-ls.nix b/modules/plugins/lsp/null-ls/null-ls.nix index 8c63df2..8067e10 100644 --- a/modules/plugins/lsp/null-ls/null-ls.nix +++ b/modules/plugins/lsp/null-ls/null-ls.nix @@ -1,10 +1,32 @@ {lib, ...}: let inherit (lib.options) mkEnableOption mkOption; - inherit (lib.types) attrsOf str; + inherit (lib.types) attrsOf str int; + inherit (lib.generators) mkLuaInline; + inherit (lib.nvim.types) luaInline; in { options.vim.lsp.null-ls = { enable = mkEnableOption "null-ls, also enabled automatically"; + debug = mkEnableOption "debugging information for `null-ls"; + + diagnostics_format = mkOption { + type = luaInline; + default = mkLuaInline "[#{m}] #{s} (#{c})"; + description = "Diagnostic output format for null-ls"; + }; + + debounce = mkOption { + type = int; + default = 250; + description = "Default debounce"; + }; + + default_timeout = mkOption { + type = int; + default = 5000; + description = "Default timeout value, in miliseconds"; + }; + sources = mkOption { description = "null-ls sources"; type = attrsOf str;