From e3b43159035ec151c2ab1b696d8e0cf1a4e4f300 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Fri, 24 May 2024 17:36:48 +0100 Subject: [PATCH] plugins/refactoring: switch to mkNeovimPlugin --- plugins/utils/refactoring.nix | 217 +++++++++--------- .../plugins/utils/refactoring.nix | 61 +++-- 2 files changed, 153 insertions(+), 125 deletions(-) diff --git a/plugins/utils/refactoring.nix b/plugins/utils/refactoring.nix index 5ddfe5d858..8cdcfdf3d1 100644 --- a/plugins/utils/refactoring.nix +++ b/plugins/utils/refactoring.nix @@ -6,140 +6,135 @@ ... }: with lib; -{ - options.plugins.refactoring = helpers.neovim-plugin.extraOptionsOptions // { - enable = mkEnableOption "refactoring.nvim"; +helpers.neovim-plugin.mkNeovimPlugin config { + name = "refactoring"; + originalName = "refactoring.nvim"; + defaultPackage = pkgs.vimPlugins.refactoring-nvim; + + maintainers = [ helpers.maintainers.MattSturgeon ]; - package = helpers.mkPluginPackageOption "refactoring.nvim" pkgs.vimPlugins.refactoring-nvim; + # TODO: introduced 2024-05-24, remove on 2024-08-24 + optionsRenamedToSettings = [ + "promptFuncReturnType" + "promptFuncParamType" + "printVarStatements" + "printfStatements" + "extractVarStatements" + ]; - promptFuncReturnType = - helpers.defaultNullOpts.mkNullable (with types; attrsOf bool) + settingsOptions = with helpers.nixvimTypes; { + prompt_func_return_type = + helpers.defaultNullOpts.mkAttrsOf bool '' { - "go" = false; - "java" = false; - "cpp" = false; - "c" = false; - "h" = false; - "hpp" = false; - "cxx" = false; + go = false; + java = false; + cpp = false; + c = false; + h = false; + hpp = false; + cxx = false; } '' '' - For certain languages like Golang, types are required for functions that return an object(s) and parameters of functions. - Unfortunately, for some parameters and functions there is no way to automatically find their type. In those instances, + For certain languages like Golang, types are required for functions that return an object(s). + 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. + + 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 = - helpers.defaultNullOpts.mkNullable (with types; attrsOf bool) + prompt_func_param_type = + helpers.defaultNullOpts.mkAttrsOf bool '' { - "go" = false; - "java" = false; - "cpp" = false; - "c" = false; - "h" = false; - "hpp" = false; - "cxx" = false; + go = false; + java = false; + cpp = false; + c = false; + h = false; + hpp = false; + cxx = false; } '' '' - For certain languages like Golang, types are required for functions that return an object(s) and parameters of functions. - Unfortunately, for some parameters and functions there is no way to automatically find their type. In those instances, + For certain languages like Golang, types are required for functions parameters. + 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. - ''; - printVarStatements = - helpers.defaultNullOpts.mkNullable (with types; attrsOf (listOf str)) - '' - { - "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. + Set the relevant language(s) to `true` to enable prompting for parameter types, e.g: - 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. - Example: - cpp = [ - "printf(\"a custom statement %%s %s\", %s)" - ] + ```nix + { + go = true; + cpp = true; + c = true; + java = true; + } ''; - printfStatements = - helpers.defaultNullOpts.mkNullable (with types; attrsOf (listOf str)) - '' - { - "go" = []; - "java" = []; - "cpp" = []; - "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. + printf_statements = helpers.defaultNullOpts.mkAttrsOf (listOf (maybeRaw 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`. - Example: - cpp = [ - "std::cout << \"%s\" << std::endl;" - ] - ''; + 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. - extractVarStatements = - helpers.defaultNullOpts.mkNullable (with types; attrsOf str) - '' - { - "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. + Example: - Example: - go = "%s := %s // poggers" - ''; - }; + ```nix + { + # add a custom printf statement for cpp + cpp = [ "std::cout << \"%s\" << std::endl;" ]; + } + ``` - config = - let - cfg = config.plugins.refactoring; - in - 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}) - ''; - }; + [folder]: https://github.com/ThePrimeagen/refactoring.nvim/blob/master/lua/refactoring/tests/debug/printf + ''; + + print_var_statements = helpers.defaultNullOpts.mkAttrsOf (listOf (maybeRaw 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`. + + 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: + + ```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 + ''; + + extract_var_statements = helpers.defaultNullOpts.mkAttrsOf str "{ }" '' + When performing an `extract_var` refactor operation, you can custom how the new variable would be declared by setting configuration + like the below example. + + Example: + + ```nix + { + # overriding extract statement for go + go = "%s := %s // poggers"; + } + ``` + ''; + }; } diff --git a/tests/test-sources/plugins/utils/refactoring.nix b/tests/test-sources/plugins/utils/refactoring.nix index e9e65a6ed3..c490880e8d 100644 --- a/tests/test-sources/plugins/utils/refactoring.nix +++ b/tests/test-sources/plugins/utils/refactoring.nix @@ -3,23 +3,56 @@ plugins.refactoring.enable = true; }; - defaults = { + example = { plugins.refactoring = { enable = true; - promptFuncReturnType = { - go = true; - }; - promptFuncParamType = { - go = true; - }; - printVarStatements = { - cpp = [ "printf(\"a custom statement %%s %s\", %s)" ]; - }; - printfStatements = { - cpp = [ "std::cout << \"%s\" << std::endl;" ]; + + settings = { + prompt_func_return_type = { + go = true; + }; + prompt_func_param_type = { + go = true; + }; + printf_statements = { + cpp = [ "std::cout << \"%s\" << std::endl;" ]; + }; + print_var_statements = { + cpp = [ "printf(\"a custom statement %%s %s\", %s)" ]; + }; + extract_var_statements = { + go = "%s := %s // poggers"; + }; }; - extractVarStatements = { - 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 = { }; }; }; };