plugins/refactoring: switch to mkNeovimPlugin

This commit is contained in:
Matt Sturgeon 2024-05-24 17:36:48 +01:00
parent 883d21d866
commit e3b4315903
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
2 changed files with 153 additions and 125 deletions

View file

@ -6,140 +6,135 @@
... ...
}: }:
with lib; with lib;
{ helpers.neovim-plugin.mkNeovimPlugin config {
options.plugins.refactoring = helpers.neovim-plugin.extraOptionsOptions // { name = "refactoring";
enable = mkEnableOption "refactoring.nvim"; originalName = "refactoring.nvim";
defaultPackage = pkgs.vimPlugins.refactoring-nvim;
package = helpers.mkPluginPackageOption "refactoring.nvim" pkgs.vimPlugins.refactoring-nvim; maintainers = [ helpers.maintainers.MattSturgeon ];
promptFuncReturnType = # TODO: introduced 2024-05-24, remove on 2024-08-24
helpers.defaultNullOpts.mkNullable (with types; attrsOf bool) optionsRenamedToSettings = [
"promptFuncReturnType"
"promptFuncParamType"
"printVarStatements"
"printfStatements"
"extractVarStatements"
];
settingsOptions = with helpers.nixvimTypes; {
prompt_func_return_type =
helpers.defaultNullOpts.mkAttrsOf bool
'' ''
{ {
"go" = false; go = false;
"java" = false; java = false;
"cpp" = false; cpp = false;
"c" = false; c = false;
"h" = false; h = false;
"hpp" = false; hpp = false;
"cxx" = false; cxx = false;
} }
'' ''
'' ''
For certain languages like Golang, types are required for functions that return an object(s) and parameters of functions. For certain languages like Golang, types are required for functions that return an object(s).
Unfortunately, for some parameters and functions there is no way to automatically find their type. In those instances, Unfortunately, for some functions there is no way to automatically find their type. In those instances,
we want to provide a way to input a type instead of inserting a placeholder value. we want to provide a way to input a type instead of inserting a placeholder value.
Set the relevant language(s) to `true` to enable prompting for a return type, e.g:
```nix
{
go = true;
cpp = true;
c = true;
java = true;
}
```
''; '';
promptFuncParamType = prompt_func_param_type =
helpers.defaultNullOpts.mkNullable (with types; attrsOf bool) helpers.defaultNullOpts.mkAttrsOf bool
'' ''
{ {
"go" = false; go = false;
"java" = false; java = false;
"cpp" = false; cpp = false;
"c" = false; c = false;
"h" = false; h = false;
"hpp" = false; hpp = false;
"cxx" = false; cxx = false;
} }
'' ''
'' ''
For certain languages like Golang, types are required for functions that return an object(s) and parameters of functions. For certain languages like Golang, types are required for functions parameters.
Unfortunately, for some parameters and functions there is no way to automatically find their type. In those instances, Unfortunately, for some parameters there is no way to automatically find their type. In those instances,
we want to provide a way to input a type instead of inserting a placeholder value. we want to provide a way to input a type instead of inserting a placeholder value.
Set the relevant language(s) to `true` to enable prompting for parameter types, e.g:
```nix
{
go = true;
cpp = true;
c = true;
java = true;
}
''; '';
printVarStatements = printf_statements = helpers.defaultNullOpts.mkAttrsOf (listOf (maybeRaw str)) "{ }" ''
helpers.defaultNullOpts.mkNullable (with types; attrsOf (listOf str)) In any custom printf statement, it is possible to optionally add a **max of one `%s` pattern**, which is where the debug path will go.
'' For an example custom printf statement, go to [this folder][folder], select your language, and click on `multiple-statements/printf.config`.
{
"go" = [];
"java" = [];
"cpp" = [];
"c" = [];
"h" = [];
"hpp" = [];
"cxx" = [];
}
''
''
In any custom print var statement, it is possible to optionally add a max of two %s patterns, which is where the debug path and
the actual variable reference will go, respectively. To add a literal "%s" to the string, escape the sequence like this: %%s.
For an example custom print var statement, go to this folder, select your language, and view multiple-statements/print_var.config.
Note: for either of these functions, if you have multiple custom statements, the plugin will prompt for which one should be inserted. If you just have one custom statement in your config, it will override the default automatically. Note: if you have multiple custom statements, the plugin will prompt for which one should be inserted.
If you just have one custom statement in your config, it will override the default automatically.
Example: Example:
cpp = [
"printf(\"a custom statement %%s %s\", %s)" ```nix
] {
# add a custom printf statement for cpp
cpp = [ "std::cout << \"%s\" << std::endl;" ];
}
```
[folder]: https://github.com/ThePrimeagen/refactoring.nvim/blob/master/lua/refactoring/tests/debug/printf
''; '';
printfStatements = print_var_statements = helpers.defaultNullOpts.mkAttrsOf (listOf (maybeRaw str)) "{ }" ''
helpers.defaultNullOpts.mkNullable (with types; attrsOf (listOf str)) In any custom print var statement, it is possible to optionally add a **max of two `%s` patterns**, which is where the debug path and
'' the actual variable reference will go, respectively. To add a literal `"%s"` to the string, escape the sequence like this: `%%s`.
{ For an example custom print var statement, go to [this folder][folder], select your language, and view `multiple-statements/print_var.config`.
"go" = [];
"java" = []; Note: if you have multiple custom statements, the plugin will prompt for which one should be inserted.
"cpp" = []; If you just have one custom statement in your config, it will override the default automatically.
"c" = [];
"h" = [];
"hpp" = [];
"cxx" = [];
}
''
''
In any custom printf statement, it is possible to optionally add a max of one %s pattern, which is where the debug path will go.
For an example custom printf statement, go to this folder, select your language, and click on multiple-statements/printf.config.
Example: Example:
cpp = [
"std::cout << \"%s\" << std::endl;" ```nix
] {
# add a custom print var statement for cpp
cpp = [ "printf(\"a custom statement %%s %s\", %s)" ];
}
```
[folder]: https://github.com/ThePrimeagen/refactoring.nvim/blob/master/lua/refactoring/tests/debug/print_var
''; '';
extractVarStatements = extract_var_statements = helpers.defaultNullOpts.mkAttrsOf str "{ }" ''
helpers.defaultNullOpts.mkNullable (with types; attrsOf str) When performing an `extract_var` refactor operation, you can custom how the new variable would be declared by setting configuration
''
{
"go" = "";
"java" = "";
"cpp" = "";
"c" = "";
"h" = "";
"hpp" = "";
"cxx" = "";
}
''
''
When performing an extract_var refactor operation, you can custom how the new variable would be declared by setting configuration
like the below example. like the below example.
Example: Example:
go = "%s := %s // poggers"
'';
};
config = ```nix
let {
cfg = config.plugins.refactoring; # overriding extract statement for go
in go = "%s := %s // poggers";
mkIf cfg.enable { }
extraPlugins = [ cfg.package ]; ```
extraConfigLua =
let
opts = with cfg; {
prompt_func_return_type = promptFuncReturnType;
prompt_func_param_type = promptFuncParamType;
print_var_statements = printVarStatements;
printf_statements = printfStatements;
extract_var_statements = extractVarStatements;
};
in
''
require('refactoring').setup(${helpers.toLuaObject opts})
''; '';
}; };
} }

View file

@ -3,24 +3,57 @@
plugins.refactoring.enable = true; plugins.refactoring.enable = true;
}; };
defaults = { example = {
plugins.refactoring = { plugins.refactoring = {
enable = true; enable = true;
promptFuncReturnType = {
settings = {
prompt_func_return_type = {
go = true; go = true;
}; };
promptFuncParamType = { prompt_func_param_type = {
go = true; go = true;
}; };
printVarStatements = { printf_statements = {
cpp = [ "printf(\"a custom statement %%s %s\", %s)" ];
};
printfStatements = {
cpp = [ "std::cout << \"%s\" << std::endl;" ]; cpp = [ "std::cout << \"%s\" << std::endl;" ];
}; };
extractVarStatements = { print_var_statements = {
cpp = [ "printf(\"a custom statement %%s %s\", %s)" ];
};
extract_var_statements = {
go = "%s := %s // poggers"; go = "%s := %s // poggers";
}; };
}; };
}; };
};
defaults = {
plugins.refactoring = {
enable = true;
settings = {
prompt_func_return_type = {
go = false;
java = false;
cpp = false;
c = false;
h = false;
hpp = false;
cxx = false;
};
prompt_func_param_type = {
go = false;
java = false;
cpp = false;
c = false;
h = false;
hpp = false;
cxx = false;
};
printf_statements = { };
print_var_statements = { };
extract_var_statements = { };
};
};
};
} }