plugins/nonels: remove with lib and helpers

This commit is contained in:
Austin Horstman 2024-10-06 10:37:40 -05:00
parent fb677540e1
commit 33d030d23c
No known key found for this signature in database
3 changed files with 19 additions and 23 deletions

View file

@ -4,7 +4,6 @@ sourceType: sourceName:
config, config,
pkgs, pkgs,
lib, lib,
helpers,
... ...
}: }:
let let
@ -20,7 +19,7 @@ in
{ {
enable = lib.mkEnableOption "the ${sourceName} ${sourceType} source for none-ls"; enable = lib.mkEnableOption "the ${sourceName} ${sourceType} source for none-ls";
# Support strLua for compatibility with the old withArgs option # Support strLua for compatibility with the old withArgs option
settings = helpers.defaultNullOpts.mkStrLuaOr' { settings = lib.nixvim.defaultNullOpts.mkStrLuaOr' {
type = with lib.types; attrsOf anything; type = with lib.types; attrsOf anything;
description = '' description = ''
Options provided to the `require('null-ls').builtins.${sourceType}.${sourceName}.with` function. Options provided to the `require('null-ls').builtins.${sourceType}.${sourceName}.with` function.
@ -82,7 +81,7 @@ in
plugins.none-ls.settings.sources = lib.mkDefault [ plugins.none-ls.settings.sources = lib.mkDefault [
( (
"require('null-ls').builtins.${sourceType}.${sourceName}" "require('null-ls').builtins.${sourceType}.${sourceName}"
+ lib.optionalString (cfg'.settings != null) ".with(${helpers.toLuaObject cfg'.settings})" + lib.optionalString (cfg'.settings != null) ".with(${lib.nixvim.toLuaObject cfg'.settings})"
) )
]; ];

View file

@ -1,18 +1,16 @@
{ {
lib, lib,
helpers,
config, config,
options, options,
... ...
}: }:
with lib; lib.nixvim.neovim-plugin.mkNeovimPlugin {
helpers.neovim-plugin.mkNeovimPlugin {
name = "none-ls"; name = "none-ls";
originalName = "none-ls.nvim"; originalName = "none-ls.nvim";
luaName = "null-ls"; luaName = "null-ls";
package = "none-ls-nvim"; package = "none-ls-nvim";
maintainers = [ maintainers.MattSturgeon ]; maintainers = [ lib.maintainers.MattSturgeon ];
# TODO: introduced 2024-06-18, remove after 24.11 # TODO: introduced 2024-06-18, remove after 24.11
deprecateExtraOptions = true; deprecateExtraOptions = true;
@ -51,8 +49,8 @@ helpers.neovim-plugin.mkNeovimPlugin {
in in
[ [
./sources.nix ./sources.nix
(mkRenamedOptionModule oldPluginPath basePluginPath) (lib.mkRenamedOptionModule oldPluginPath basePluginPath)
(mkRenamedOptionModule (basePluginPath ++ [ "sourcesItems" ]) (settingsPath ++ [ "sources" ])) (lib.mkRenamedOptionModule (basePluginPath ++ [ "sourcesItems" ]) (settingsPath ++ [ "sources" ]))
]; ];
settingsExample = { settingsExample = {
@ -95,11 +93,11 @@ helpers.neovim-plugin.mkNeovimPlugin {
settingsOptions = import ./settings.nix lib; settingsOptions = import ./settings.nix lib;
extraOptions = { extraOptions = {
enableLspFormat = mkOption { enableLspFormat = lib.mkOption {
type = types.bool; type = lib.types.bool;
# TODO: consider default = false and enabling lsp-format automatically instead? # TODO: consider default = false and enabling lsp-format automatically instead?
default = config.plugins.lsp-format.enable; default = config.plugins.lsp-format.enable;
defaultText = literalExpression "plugins.lsp-format.enable"; defaultText = lib.literalExpression "plugins.lsp-format.enable";
example = false; example = false;
description = '' description = ''
Automatically configure `none-ls` to use the `lsp-format` plugin. Automatically configure `none-ls` to use the `lsp-format` plugin.
@ -119,19 +117,19 @@ helpers.neovim-plugin.mkNeovimPlugin {
# but that'd make it difficult to implement the "has no effect" warning. # but that'd make it difficult to implement the "has no effect" warning.
setupOptions = setupOptions =
cfg.settings cfg.settings
// optionalAttrs (cfg.enableLspFormat && cfg.settings.on_attach == null) { // lib.optionalAttrs (cfg.enableLspFormat && cfg.settings.on_attach == null) {
on_attach.__raw = '' on_attach.__raw = ''
require('lsp-format').on_attach require('lsp-format').on_attach
''; '';
}; };
in in
{ {
warnings = optional (cfg.enableLspFormat && cfg.settings.on_attach != null) '' warnings = lib.optional (cfg.enableLspFormat && cfg.settings.on_attach != null) ''
You have enabled the lsp-format integration with none-ls. You have enabled the lsp-format integration with none-ls.
However, you have provided a custom value to `plugins.none-ls.settings.on_attach`. However, you have provided a custom value to `plugins.none-ls.settings.on_attach`.
This means the `enableLspFormat` option will have no effect. This means the `enableLspFormat` option will have no effect.
Final value is: Final value is:
${generators.toPretty { } cfg.settings.on_attach} ${lib.generators.toPretty { } cfg.settings.on_attach}
''; '';
assertions = [ assertions = [
@ -148,7 +146,7 @@ helpers.neovim-plugin.mkNeovimPlugin {
# We only do this here because of enableLspFormat # We only do this here because of enableLspFormat
plugins.none-ls.luaConfig.content = '' plugins.none-ls.luaConfig.content = ''
require("null-ls").setup(${helpers.toLuaObject setupOptions}) require("null-ls").setup(${lib.nixvim.toLuaObject setupOptions})
''; '';
}; };
} }

View file

@ -1,13 +1,12 @@
{ lib, config, ... }: { lib, config, ... }:
with lib;
let let
cfg = config.plugins.none-ls.sources.formatting.prettier; cfg = config.plugins.none-ls.sources.formatting.prettier;
ts-ls-cfg = config.plugins.lsp.servers.ts-ls; ts-ls-cfg = config.plugins.lsp.servers.ts-ls;
in in
{ {
options.plugins.none-ls.sources.formatting.prettier = { options.plugins.none-ls.sources.formatting.prettier = {
disableTsServerFormatter = mkOption { disableTsServerFormatter = lib.mkOption {
type = with types; nullOr bool; type = with lib.types; nullOr bool;
description = '' description = ''
Disables the formatting capability of the `ts-ls` language server if it is enabled. Disables the formatting capability of the `ts-ls` language server if it is enabled.
''; '';
@ -16,8 +15,8 @@ in
}; };
}; };
config = mkIf cfg.enable { config = lib.mkIf cfg.enable {
warnings = optional ((cfg.disableTsServerFormatter == null) && ts-ls-cfg.enable) '' warnings = lib.optional ((cfg.disableTsServerFormatter == null) && ts-ls-cfg.enable) ''
You have enabled the `prettier` formatter in none-ls. You have enabled the `prettier` formatter in none-ls.
You have also enabled the `ts-ls` language server which also brings a formatting feature. You have also enabled the `ts-ls` language server which also brings a formatting feature.
@ -27,11 +26,11 @@ in
''; '';
plugins.lsp.servers.ts-ls = plugins.lsp.servers.ts-ls =
mkIf lib.mkIf
( (
cfg.enable cfg.enable
&& ts-ls-cfg.enable && ts-ls-cfg.enable
&& (isBool cfg.disableTsServerFormatter) && (lib.isBool cfg.disableTsServerFormatter)
&& cfg.disableTsServerFormatter && cfg.disableTsServerFormatter
) )
{ {