mirror of
https://github.com/nix-community/nixvim.git
synced 2025-11-08 11:36:07 +01:00
plugins/neogen: migrate to mkNeovimPlugin
Tracking: https://github.com/nix-community/nixvim/issues/2638
This commit is contained in:
parent
eb54f65d9b
commit
8bcb4c4a8c
3 changed files with 73 additions and 195 deletions
|
|
@ -1,14 +1,8 @@
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
helpers,
|
|
||||||
config,
|
|
||||||
pkgs,
|
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
with lib;
|
|
||||||
let
|
let
|
||||||
cfg = config.plugins.neogen;
|
|
||||||
|
|
||||||
keymapDef = {
|
keymapDef = {
|
||||||
generate = {
|
generate = {
|
||||||
command = "";
|
command = "";
|
||||||
|
|
@ -43,181 +37,47 @@ let
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
lib.nixvim.plugins.mkNeovimPlugin {
|
||||||
options.plugins.neogen = lib.nixvim.plugins.neovim.extraOptionsOptions // {
|
name = "neogen";
|
||||||
enable = mkEnableOption "neogen";
|
maintainers = [ lib.maintainers.GaetanLepage ];
|
||||||
|
|
||||||
package = lib.mkPackageOption pkgs "neogen" {
|
# TODO: introduced 2025-10-03: remove after 26.05
|
||||||
default = [
|
inherit (import ./deprecations.nix) deprecateExtraOptions optionsRenamedToSettings;
|
||||||
"vimPlugins"
|
|
||||||
"neogen"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
keymaps = mapAttrs (
|
settingsExample = {
|
||||||
optionsName: properties: helpers.mkNullOrOption types.str properties.description
|
snippet_engine = "mini";
|
||||||
) keymapDef;
|
languages = {
|
||||||
|
lua.template.annotation_convention = "emmylua";
|
||||||
keymapsSilent = mkOption {
|
python.template.annotation_convention = "numpydoc";
|
||||||
type = types.bool;
|
|
||||||
description = "Whether Neogen keymaps should be silent";
|
|
||||||
default = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
inputAfterComment = helpers.defaultNullOpts.mkBool true ''
|
|
||||||
If true, go to annotation after insertion, and change to insert mode
|
|
||||||
'';
|
|
||||||
|
|
||||||
enablePlaceholders = helpers.defaultNullOpts.mkBool true ''
|
|
||||||
If true, enables placeholders when inserting annotation
|
|
||||||
'';
|
|
||||||
|
|
||||||
languages = helpers.defaultNullOpts.mkAttrsOf' {
|
|
||||||
# No plugin default (see upstream)
|
|
||||||
type = types.anything;
|
|
||||||
description = ''
|
|
||||||
Configuration for languages.
|
|
||||||
|
|
||||||
`template.annotation_convention` (default: check the language default configurations):
|
|
||||||
Change the annotation convention to use with the language.
|
|
||||||
|
|
||||||
`template.use_default_comment` (default: true):
|
|
||||||
Prepend any template line with the default comment for the filetype
|
|
||||||
|
|
||||||
`template.position` (fun(node: userdata, type: string):(number,number)?):
|
|
||||||
Provide an absolute position for the annotation.
|
|
||||||
If return values are nil, use default position
|
|
||||||
|
|
||||||
`template.append`:
|
|
||||||
If you want to customize the position of the annotation.
|
|
||||||
|
|
||||||
`template.append.child_name`:
|
|
||||||
What child node to use for appending the annotation.
|
|
||||||
|
|
||||||
`template.append.position` (before/after):
|
|
||||||
Relative positioning with `child_name`.
|
|
||||||
|
|
||||||
`template.<convention_name>` (replace <convention_name> with an annotation convention):
|
|
||||||
Template for an annotation convention.
|
|
||||||
To know more about how to create your own template, go here:
|
|
||||||
https://github.com/danymat/neogen/blob/main/docs/adding-languages.md#default-generator
|
|
||||||
'';
|
|
||||||
example = {
|
|
||||||
csharp = {
|
|
||||||
template = {
|
|
||||||
annotation_convention = "...";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
snippetEngine = helpers.mkNullOrOption types.str ''
|
|
||||||
Use a snippet engine to generate annotations.
|
|
||||||
Some snippet engines come out of the box bundled with neogen:
|
|
||||||
- `"luasnip"` (https://github.com/L3MON4D3/LuaSnip)
|
|
||||||
- `"snippy"` (https://github.com/dcampos/nvim-snippy)
|
|
||||||
- `"vsnip"` (https://github.com/hrsh7th/vim-vsnip)
|
|
||||||
'';
|
|
||||||
|
|
||||||
placeholderHighlight = helpers.defaultNullOpts.mkStr "DiagnosticHint" ''
|
|
||||||
Placeholders highlights to use. If you don't want custom highlight, pass "None"
|
|
||||||
'';
|
|
||||||
|
|
||||||
placeholdersText = {
|
|
||||||
description = helpers.defaultNullOpts.mkStr "[TODO:description]" ''
|
|
||||||
Placeholder for description.
|
|
||||||
'';
|
|
||||||
|
|
||||||
tparam = helpers.defaultNullOpts.mkStr "[TODO:tparam]" ''
|
|
||||||
Placeholder for tparam.
|
|
||||||
'';
|
|
||||||
|
|
||||||
parameter = helpers.defaultNullOpts.mkStr "[TODO:parameter]" ''
|
|
||||||
Placeholder for parameter.
|
|
||||||
'';
|
|
||||||
|
|
||||||
return = helpers.defaultNullOpts.mkStr "[TODO:return]" ''
|
|
||||||
Placeholder for return.
|
|
||||||
'';
|
|
||||||
|
|
||||||
class = helpers.defaultNullOpts.mkStr "[TODO:class]" ''
|
|
||||||
Placeholder for class.
|
|
||||||
'';
|
|
||||||
|
|
||||||
throw = helpers.defaultNullOpts.mkStr "[TODO:throw]" ''
|
|
||||||
Placeholder for throw.
|
|
||||||
'';
|
|
||||||
|
|
||||||
varargs = helpers.defaultNullOpts.mkStr "[TODO:varargs]" ''
|
|
||||||
Placeholder for varargs.
|
|
||||||
'';
|
|
||||||
|
|
||||||
type = helpers.defaultNullOpts.mkStr "[TODO:type]" ''
|
|
||||||
Placeholder for type.
|
|
||||||
'';
|
|
||||||
|
|
||||||
attribute = helpers.defaultNullOpts.mkStr "[TODO:attribute]" ''
|
|
||||||
Placeholder for attribute.
|
|
||||||
'';
|
|
||||||
|
|
||||||
args = helpers.defaultNullOpts.mkStr "[TODO:args]" ''
|
|
||||||
Placeholder for args.
|
|
||||||
'';
|
|
||||||
|
|
||||||
kwargs = helpers.defaultNullOpts.mkStr "[TODO:kwargs]" ''
|
|
||||||
Placeholder for kwargs.
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
# TODO introduced 2024-03-07: remove 2024-05-07
|
extraOptions = {
|
||||||
imports = [
|
keymaps = lib.mapAttrs (
|
||||||
(mkRenamedOptionModule
|
optionsName: properties: lib.nixvim.mkNullOrOption lib.types.str properties.description
|
||||||
[
|
) keymapDef;
|
||||||
"plugins"
|
|
||||||
"neogen"
|
|
||||||
"placeholderHighligt"
|
|
||||||
]
|
|
||||||
[
|
|
||||||
"plugins"
|
|
||||||
"neogen"
|
|
||||||
"placeholderHighlight"
|
|
||||||
]
|
|
||||||
)
|
|
||||||
];
|
|
||||||
|
|
||||||
config =
|
keymapsSilent = lib.mkOption {
|
||||||
let
|
type = lib.types.bool;
|
||||||
setupOptions = with cfg; {
|
description = "Whether Neogen keymaps should be silent";
|
||||||
enabled = enable;
|
default = false;
|
||||||
input_after_comment = inputAfterComment;
|
|
||||||
inherit languages;
|
|
||||||
snippet_engine = snippetEngine;
|
|
||||||
enable_placeholders = enablePlaceholders;
|
|
||||||
placeholder_text = placeholdersText;
|
|
||||||
placeholder_hl = placeholderHighlight;
|
|
||||||
};
|
|
||||||
in
|
|
||||||
mkIf cfg.enable {
|
|
||||||
extraPlugins = [ cfg.package ];
|
|
||||||
|
|
||||||
extraConfigLua = ''
|
|
||||||
require("neogen").setup(${lib.nixvim.toLuaObject setupOptions})
|
|
||||||
'';
|
|
||||||
|
|
||||||
keymaps = flatten (
|
|
||||||
mapAttrsToList (
|
|
||||||
optionName: properties:
|
|
||||||
let
|
|
||||||
key = cfg.keymaps.${optionName};
|
|
||||||
in
|
|
||||||
optional (key != null) {
|
|
||||||
mode = "n";
|
|
||||||
inherit key;
|
|
||||||
action = ":Neogen ${properties.command}<CR>";
|
|
||||||
options.silent = cfg.keymapsSilent;
|
|
||||||
}
|
|
||||||
) keymapDef
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
extraConfig = cfg: {
|
||||||
|
keymaps = lib.flatten (
|
||||||
|
lib.mapAttrsToList (
|
||||||
|
optionName: properties:
|
||||||
|
let
|
||||||
|
key = cfg.keymaps.${optionName};
|
||||||
|
in
|
||||||
|
lib.optional (key != null) {
|
||||||
|
mode = "n";
|
||||||
|
inherit key;
|
||||||
|
action = ":Neogen ${properties.command}<CR>";
|
||||||
|
options.silent = cfg.keymapsSilent;
|
||||||
|
}
|
||||||
|
) keymapDef
|
||||||
|
);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
15
plugins/by-name/neogen/deprecations.nix
Normal file
15
plugins/by-name/neogen/deprecations.nix
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
deprecateExtraOptions = true;
|
||||||
|
|
||||||
|
optionsRenamedToSettings = [
|
||||||
|
"inputAfterComment"
|
||||||
|
"languages"
|
||||||
|
"snippetEngine"
|
||||||
|
"enablePlaceholders"
|
||||||
|
"placeholdersText"
|
||||||
|
{
|
||||||
|
old = "placeholderHighlight";
|
||||||
|
new = "placeholder_hl";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
@ -7,8 +7,6 @@
|
||||||
plugins.neogen = {
|
plugins.neogen = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
enablePlaceholders = false;
|
|
||||||
inputAfterComment = false;
|
|
||||||
keymaps = {
|
keymaps = {
|
||||||
generate = "<leader>a";
|
generate = "<leader>a";
|
||||||
generateClass = "<leader>b";
|
generateClass = "<leader>b";
|
||||||
|
|
@ -17,26 +15,31 @@
|
||||||
generateType = "<leader>e";
|
generateType = "<leader>e";
|
||||||
};
|
};
|
||||||
keymapsSilent = true;
|
keymapsSilent = true;
|
||||||
languages = {
|
|
||||||
csharp = {
|
settings = {
|
||||||
template = {
|
enable_placeholders = false;
|
||||||
annotation_convention = "...";
|
input_after_comment = false;
|
||||||
|
languages = {
|
||||||
|
csharp = {
|
||||||
|
template = {
|
||||||
|
annotation_convention = "...";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
placeholder_hl = "None";
|
||||||
|
placeholders_text = {
|
||||||
|
attribute = "attribute";
|
||||||
|
class = "class";
|
||||||
|
description = "description";
|
||||||
|
kwargs = "kwargs";
|
||||||
|
parameter = "parameter";
|
||||||
|
throw = "throw";
|
||||||
|
tparam = "tparam";
|
||||||
|
type = "type";
|
||||||
|
varargs = "varargs";
|
||||||
|
};
|
||||||
|
snippet_engine = "vsnip";
|
||||||
};
|
};
|
||||||
placeholderHighlight = "None";
|
|
||||||
placeholdersText = {
|
|
||||||
attribute = "attribute";
|
|
||||||
class = "class";
|
|
||||||
description = "description";
|
|
||||||
kwargs = "kwargs";
|
|
||||||
parameter = "parameter";
|
|
||||||
throw = "throw";
|
|
||||||
tparam = "tparam";
|
|
||||||
type = "type";
|
|
||||||
varargs = "varargs";
|
|
||||||
};
|
|
||||||
snippetEngine = "vsnip";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue