plugins/lean: migrate to mkNeovimPlugin

This commit is contained in:
Austin Horstman 2025-01-31 16:07:26 -06:00 committed by nix-infra-bot
parent 0e92aaf3f2
commit c75e4ea37f
3 changed files with 256 additions and 263 deletions

View file

@ -1,81 +1,77 @@
{ {
lib, lib,
helpers,
config,
pkgs, pkgs,
... ...
}: }:
with lib;
let let
cfg = config.plugins.lean; inherit (lib.nixvim) defaultNullOpts mkNullOrOption;
inherit (lib) types;
in in
{ lib.nixvim.plugins.mkNeovimPlugin {
options.plugins.lean = lib.nixvim.plugins.neovim.extraOptionsOptions // { name = "lean";
enable = mkEnableOption "lean-nvim"; packPathName = "lean.nvim";
package = "lean-nvim";
package = lib.mkPackageOption pkgs "lean-nvim" { maintainers = [ lib.maintainers.khaneliman ];
default = [
"vimPlugins"
"lean-nvim"
];
};
extraOptions = {
leanPackage = lib.mkPackageOption pkgs "lean" { leanPackage = lib.mkPackageOption pkgs "lean" {
nullable = true; nullable = true;
default = "lean4"; default = "lean4";
}; };
};
lsp = helpers.defaultNullOpts.mkNullable ( settingsOptions = {
with types; lsp = defaultNullOpts.mkNullable (types.submodule {
submodule { freeformType = types.attrsOf types.anything;
freeformType = types.attrs;
options = { options = {
enable = helpers.defaultNullOpts.mkBool true '' enable = defaultNullOpts.mkBool true ''
Whether to enable the Lean language server(s) ? Whether to enable the Lean language server(s).
Set to `false` to disable, otherwise should be a table of options to pass to Set to `false` to disable, otherwise should be a table of options to pass to
`leanls`. `leanls`.
See https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#leanls See https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#leanls
for details. for details.
''; '';
on_attach = helpers.mkNullOrOption types.str '' on_attach = mkNullOrOption types.str ''
The LSP handler. The LSP handler.
''; '';
init_options = helpers.mkNullOrOption (with types; attrsOf anything) '' init_options = mkNullOrOption (with types; attrsOf anything) ''
The options to configure the lean language server. The options to configure the lean language server.
See `Lean.Lsp.InitializationOptions` for details. See `Lean.Lsp.InitializationOptions` for details.
''; '';
}; };
} }) { } "LSP settings.";
) { } "LSP settings.";
ft = { ft = {
default = helpers.defaultNullOpts.mkStr "lean" '' default = defaultNullOpts.mkStr "lean" ''
The default filetype for Lean files. The default filetype for Lean files.
''; '';
nomodifiable = mkNullOrOption (types.listOf types.str) ''
nomodifiable = helpers.mkNullOrOption (with types; listOf str) ''
A list of patterns which will be used to protect any matching Lean file paths from being A list of patterns which will be used to protect any matching Lean file paths from being
accidentally modified (by marking the buffer as `nomodifiable`). accidentally modified (by marking the buffer as `nomodifiable`).
By default, this list includes the Lean standard libraries, as well as files within By default, this list includes the Lean standard libraries, as well as files within
dependency directories (e.g. `_target`) dependency directories (e.g. `_target`)
Set this to an empty table to disable. Set this to an empty table to disable.
''; '';
}; };
abbreviations = { abbreviations = {
enable = helpers.defaultNullOpts.mkBool true '' enable = defaultNullOpts.mkBool true ''
Whether to enable expanding of unicode abbreviations. Whether to enable expanding of unicode abbreviations.
''; '';
extra = defaultNullOpts.mkAttrsOf' {
extra = helpers.defaultNullOpts.mkAttrsOf types.str { } '' type = types.str;
pluginDefault = { };
description = ''
Additional abbreviations. Additional abbreviations.
'';
Example: example = lib.literalExpression ''
``` ```nix
{ {
# Add a \wknight abbreviation to insert ♘ # Add a \wknight abbreviation to insert ♘
# #
@ -85,86 +81,48 @@ in
wknight = ""; wknight = "";
} }
''; '';
};
leader = helpers.defaultNullOpts.mkStr "\\" '' leader = defaultNullOpts.mkStr "\\" ''
Change if you don't like the backslash. Change if you don't like the backslash.
(comma is a popular choice on French keyboards)
''; '';
}; };
mappings = defaultNullOpts.mkBool false ''
mappings = helpers.defaultNullOpts.mkBool false ''
Whether to enable suggested mappings. Whether to enable suggested mappings.
''; '';
infoview = { infoview = {
autoopen = helpers.defaultNullOpts.mkBool true '' autoopen = defaultNullOpts.mkBool true ''
Automatically open an infoview on entering a Lean buffer? Automatically open an infoview on entering a Lean buffer.
Should be a function that will be called anytime a new Lean file is opened. Should be a function that will be called anytime a new Lean file is opened.
Return true to open an infoview, otherwise false. Return true to open an infoview, otherwise false.
Setting this to `true` is the same as `function() return true end`, i.e. autoopen for any Setting this to `true` is the same as `function() return true end`, i.e. autoopen for any
Lean file, or setting it to `false` is the same as `function() return false end`, Lean file, or setting it to `false` is the same as `function() return false end`,
i.e. never autoopen. i.e. never autoopen.
''; '';
autopause = defaultNullOpts.mkBool false "Set whether a new pin is automatically paused.";
autopause = helpers.defaultNullOpts.mkBool false ""; width = defaultNullOpts.mkPositiveInt 50 ''
width = helpers.defaultNullOpts.mkPositiveInt 50 ''
Set infoview windows' starting width. Set infoview windows' starting width.
Windows are opened horizontally or vertically depending on spacing.
''; '';
height = defaultNullOpts.mkPositiveInt 20 ''
height = helpers.defaultNullOpts.mkPositiveInt 20 ''
Set infoview windows' starting height. Set infoview windows' starting height.
Windows are opened horizontally or vertically depending on spacing.
''; '';
horizontal_position = defaultNullOpts.mkEnumFirstDefault [ "bottom" "top" ] ''
horizontalPosition =
helpers.defaultNullOpts.mkEnum
[
"top"
"bottom"
]
"bottom"
''
Put the infoview on the top or bottom when horizontal. Put the infoview on the top or bottom when horizontal.
''; '';
separate_tab = defaultNullOpts.mkBool false ''
separateTab = helpers.defaultNullOpts.mkBool false ''
Always open the infoview window in a separate tabpage. Always open the infoview window in a separate tabpage.
Might be useful if you are using a screen reader and don't want too many dynamic updates Might be useful if you are using a screen reader and don't want too many dynamic updates
in the terminal at the same time. in the terminal at the same time.
Note that `height` and `width` will be ignored in this case. Note that `height` and `width` will be ignored in this case.
''; '';
indicators = defaultNullOpts.mkEnumFirstDefault [ "auto" "always" "never" ] ''
indicators =
helpers.defaultNullOpts.mkEnum
[
"always"
"never"
"auto"
]
"auto"
''
Show indicators for pin locations when entering an infoview window. Show indicators for pin locations when entering an infoview window.
`"auto"` = only when there are multiple pins.
''; '';
show_processing = defaultNullOpts.mkBool true "";
lean3 = { show_no_info_message = defaultNullOpts.mkBool false "";
showFilter = helpers.defaultNullOpts.mkBool true ""; use_widgets = defaultNullOpts.mkBool true "Whether to use widgets.";
mappings = defaultNullOpts.mkAttrsOf types.str {
mouseEvents = helpers.defaultNullOpts.mkBool false ''
Setting this to `true` will simulate mouse events in the Lean 3 infoview, this is buggy
at the moment so you can use the I/i keybindings to manually trigger these.
'';
};
showProcessing = helpers.defaultNullOpts.mkBool true "";
showNoInfoMessage = helpers.defaultNullOpts.mkBool false "";
useWidgets = helpers.defaultNullOpts.mkBool true "Whether to use widgets.";
mappings = helpers.defaultNullOpts.mkAttrsOf types.str {
K = "click"; K = "click";
"<CR>" = "click"; "<CR>" = "click";
gd = "go_to_def"; gd = "go_to_def";
@ -177,126 +135,59 @@ in
"<LocalLeader><Tab>" = "goto_last_window"; "<LocalLeader><Tab>" = "goto_last_window";
} "Mappings."; } "Mappings.";
}; };
progress_bars = {
progressBars = { enable = defaultNullOpts.mkBool true ''
enable = helpers.defaultNullOpts.mkBool true ''
Whether to enable the progress bars. Whether to enable the progress bars.
''; '';
priority = defaultNullOpts.mkUnsignedInt 10 ''
priority = helpers.defaultNullOpts.mkUnsignedInt 10 ''
Use a different priority for the signs. Use a different priority for the signs.
''; '';
}; };
stderr = { stderr = {
enable = helpers.defaultNullOpts.mkBool true '' enable = defaultNullOpts.mkBool true ''
Redirect Lean's stderr messages somewhere (to a buffer by default). Redirect Lean's stderr messages somewhere (to a buffer by default).
''; '';
height = defaultNullOpts.mkPositiveInt 5 "Height of the window.";
height = helpers.defaultNullOpts.mkPositiveInt 5 "Height of the window."; on_lines = defaultNullOpts.mkLuaFn "nil" ''
onLines = helpers.defaultNullOpts.mkLuaFn "nil" ''
A callback which will be called with (multi-line) stderr output. A callback which will be called with (multi-line) stderr output.
e.g., use:
```nix
onLines = "function(lines) vim.notify(lines) end";
```
if you want to redirect stderr to `vim.notify`.
The default implementation will redirect to a dedicated stderr
window.
''; '';
}; };
lsp3 = helpers.defaultNullOpts.mkNullable (
with types;
submodule {
freeformType = types.attrs;
options = {
enable = helpers.defaultNullOpts.mkBool true ''
Whether to enable the legacy Lean 3 language server ?
Set to `false` to disable, otherwise should be a table of options to pass to
`lean3ls`.
See https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#lean3ls
for details.
'';
on_attach = helpers.mkNullOrOption types.str "The LSP handler.";
};
}
) { } "Legacy Lean3 LSP settings.";
}; };
config = mkIf cfg.enable { settingsExample = {
extraPlugins = [ cfg.package ]; settings = {
lsp = {
assertions = lib.nixvim.mkAssertions "plugins.lean" { enable = true;
assertion = };
!( ft = {
# leanls lsp server is disabled in nvim-lspconfig default = "lean";
config.plugins.lsp.servers.leanls.enable nomodifiable = [ "_target" ];
# lsp is not explicitly disabled in the lean.nvim plugin };
&& (cfg.lsp.enable != false) abbreviations = {
); enable = true;
message = '' extra = {
You have not explicitly set `plugins.lean.lsp` to `false` while having `plugins.lsp.servers.leanls.enable` set to `true`. wknight = "";
You need to either };
};
- Remove the configuration in `plugins.lsp.servers.leanls` and move it to `plugins.lean.lsp`. mappings = false;
- Explicitly disable the autoconfiguration of the lsp in the lean.nvim plugin by setting `plugins.lean.lsp` to `false`. infoview = {
horizontal_position = "top";
https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#leanls separate_tab = true;
''; indicators = "always";
};
progress_bars = {
enable = false;
};
stderr = {
on_lines.__raw = "function(lines) vim.notify(lines) end";
};
};
}; };
extraConfig = cfg: {
extraPackages = [ cfg.leanPackage ]; extraPackages = [ cfg.leanPackage ];
};
extraConfigLua = # TODO: Deprecated in 2025-01-31
let inherit (import ./deprecations.nix) deprecateExtraOptions optionsRenamedToSettings;
setupOptions =
with cfg;
{
inherit lsp;
ft = with ft; {
inherit default nomodifiable;
};
abbreviations = with abbreviations; {
inherit enable extra leader;
};
inherit mappings;
infoview = with infoview; {
inherit
autoopen
autopause
width
height
;
horizontal_position = horizontalPosition;
separate_tab = separateTab;
inherit indicators;
lean3 = with lean3; {
show_filter = showFilter;
mouse_events = mouseEvents;
};
show_processing = showProcessing;
show_no_info_message = showNoInfoMessage;
use_widgets = useWidgets;
inherit mappings;
};
progress_bars = with progressBars; {
inherit enable priority;
};
stderr = with stderr; {
inherit enable height;
on_lines = onLines;
};
inherit lsp3;
}
// cfg.extraOptions;
in
''
require("lean").setup(${lib.nixvim.toLuaObject setupOptions})
'';
};
} }

View file

@ -0,0 +1,109 @@
{
deprecateExtraOptions = true;
optionsRenamedToSettings = [
"lsp"
[
"ft"
"default"
]
[
"ft"
"nomodifiable"
]
[
"abbreviations"
"enable"
]
[
"abbreviations"
"extra"
]
[
"abbreviations"
"leader"
]
"mappings"
[
"infoview"
"autoopen"
]
[
"infoview"
"autopause"
]
[
"infoview"
"width"
]
[
"infoview"
"height"
]
[
"infoview"
"horizontalPosition"
]
[
"infoview"
"separateTab"
]
[
"infoview"
"indicators"
]
[
"infoview"
"lean3"
"showFilter"
]
[
"infoview"
"lean3"
"mouseEvents"
]
[
"infoview"
"showProcessing"
]
[
"infoview"
"showNoInfoMessage"
]
[
"infoview"
"useWidgets"
]
[
"infoview"
"mappings"
]
[
"progressBars"
"enable"
]
[
"progressBars"
"priority"
]
[
"stderr"
"enable"
]
[
"stderr"
"height"
]
[
"stderr"
"onLines"
]
[
"lsp3"
"enable"
]
[
"lsp3"
"onAttach"
]
];
}

View file

@ -23,8 +23,7 @@ lib.optionalAttrs doRun {
lean = { lean = {
enable = true; enable = true;
settings.lsp.enable = false;
lsp.enable = false;
}; };
}; };
}; };
@ -35,7 +34,7 @@ lib.optionalAttrs doRun {
lean = { lean = {
enable = true; enable = true;
settings = {
lsp = { }; lsp = { };
ft = { ft = {
default = "lean"; default = "lean";
@ -43,9 +42,7 @@ lib.optionalAttrs doRun {
}; };
abbreviations = { abbreviations = {
enable = true; enable = true;
extra = { extra = { };
wknight = "";
};
leader = "\\"; leader = "\\";
}; };
mappings = false; mappings = false;
@ -54,16 +51,12 @@ lib.optionalAttrs doRun {
autopause = false; autopause = false;
width = 50; width = 50;
height = 20; height = 20;
horizontalPosition = "bottom"; horizontal_position = "bottom";
separateTab = false; separate_tab = false;
indicators = "auto"; indicators = "auto";
lean3 = { show_processing = true;
showFilter = true; show_no_info_message = false;
mouseEvents = false; use_widgets = true;
};
showProcessing = true;
showNoInfoMessage = false;
useWidgets = true;
mappings = { mappings = {
K = "click"; K = "click";
"<CR>" = "click"; "<CR>" = "click";
@ -77,16 +70,16 @@ lib.optionalAttrs doRun {
"<LocalLeader><Tab>" = "goto_last_window"; "<LocalLeader><Tab>" = "goto_last_window";
}; };
}; };
progressBars = { progress_bars = {
enable = true; enable = true;
priority = 10; priority = 10;
}; };
stderr = { stderr = {
enable = true; enable = true;
height = 5; height = 5;
onLines = "function(lines) vim.notify(lines) end"; on_lines.__raw = "function(lines) vim.notify(lines) end";
};
}; };
lsp3 = { };
}; };
}; };
}; };