diff --git a/plugins/by-name/ts-context-commentstring/default.nix b/plugins/by-name/ts-context-commentstring/default.nix index c63dc0ac..9ebebf6a 100644 --- a/plugins/by-name/ts-context-commentstring/default.nix +++ b/plugins/by-name/ts-context-commentstring/default.nix @@ -1,24 +1,22 @@ { lib, - helpers, config, - pkgs, + options, ... }: -with lib; -{ - options.plugins.ts-context-commentstring = lib.nixvim.plugins.neovim.extraOptionsOptions // { - enable = mkEnableOption "nvim-ts-context-commentstring"; +lib.nixvim.plugins.mkNeovimPlugin { + name = "ts-context-commentstring"; + package = "nvim-ts-context-commentstring"; + moduleName = "ts_context_commentstring"; + description = "Treesitter plugin for setting the commentstring based on the cursor location in a file."; + maintainers = [ ]; - package = lib.mkPackageOption pkgs "ts-context-commentstring" { - default = [ - "vimPlugins" - "nvim-ts-context-commentstring" - ]; - }; + # TODO: introduced 2025-10-05: remove after 26.05 + inherit (import ./deprecations.nix) deprecateExtraOptions optionsRenamedToSettings; - skipTsContextCommentStringModule = mkOption { - type = types.bool; + extraOptions = { + skipTsContextCommentStringModule = lib.mkOption { + type = lib.types.bool; default = true; description = '' Whether to skip backwards compatibility routines and speed up loading. @@ -26,40 +24,34 @@ with lib; example = false; }; - disableAutoInitialization = helpers.defaultNullOpts.mkBool false '' + disableAutoInitialization = lib.nixvim.defaultNullOpts.mkBool false '' Whether to disable auto-initialization. ''; - - languages = helpers.mkNullOrOption (with types; attrsOf (either str (attrsOf str))) '' - Allows you to add support for more languages. - - See `:h ts-context-commentstring-commentstring-configuration` for more information. - ''; }; - config = - let - cfg = config.plugins.ts-context-commentstring; - in - mkIf cfg.enable { - warnings = lib.nixvim.mkWarnings "plugins.ts-context-commentstring" { - when = !config.plugins.treesitter.enable; - message = "This plugin needs treesitter to function as intended."; + settingsExample = { + enable_autocmd = false; + languages = { + haskell = "-- %s"; + nix = { + __default = "# %s"; + __multiline = "/* %s */"; }; - - extraPlugins = [ cfg.package ]; - - globals = with cfg; { - skip_ts_context_commentstring_module = skipTsContextCommentStringModule; - loaded_ts_context_commentstring = disableAutoInitialization; - }; - - extraConfigLua = - let - setupOptions = with cfg; { inherit languages; } // cfg.extraOptions; - in - '' - require('ts_context_commentstring').setup(${lib.nixvim.toLuaObject setupOptions}) - ''; }; + }; + + extraConfig = cfg: { + warnings = lib.nixvim.mkWarnings "plugins.ts-context-commentstring" { + when = !config.plugins.treesitter.enable; + message = '' + This plugin needs Treesitter to function as intended. + Please, enable it by setting `${options.plugins.treesitter.enable}` to `true`. + ''; + }; + + globals = { + skip_ts_context_commentstring_module = cfg.skipTsContextCommentStringModule; + loaded_ts_context_commentstring = cfg.disableAutoInitialization; + }; + }; } diff --git a/plugins/by-name/ts-context-commentstring/deprecations.nix b/plugins/by-name/ts-context-commentstring/deprecations.nix new file mode 100644 index 00000000..dd7a6ba6 --- /dev/null +++ b/plugins/by-name/ts-context-commentstring/deprecations.nix @@ -0,0 +1,4 @@ +{ + deprecateExtraOptions = true; + optionsRenamedToSettings = [ "languages" ]; +} diff --git a/tests/test-sources/plugins/by-name/ts-context-commentstring/default.nix b/tests/test-sources/plugins/by-name/ts-context-commentstring/default.nix index 9e3c74a4..a5cf69b7 100644 --- a/tests/test-sources/plugins/by-name/ts-context-commentstring/default.nix +++ b/tests/test-sources/plugins/by-name/ts-context-commentstring/default.nix @@ -6,5 +6,165 @@ }; }; - # This plugin has no option + example = { + plugins = { + treesitter.enable = true; + ts-context-commentstring = { + enable = true; + settings = { + enable_autocmd = false; + languages = { + haskell = "-- %s"; + nix = { + __default = "# %s"; + __multiline = "/* %s */"; + }; + }; + }; + }; + }; + }; + + defaults = { + plugins = { + treesitter.enable = true; + ts-context-commentstring = { + enable = true; + settings = { + enable_autocmd = true; + + custom_calculation.__raw = "nil"; + + commentary_integration = { + Commentary = "gc"; + CommentaryLine = "gcc"; + ChangeCommentary = "cgc"; + CommentaryUndo = "gcu"; + }; + + languages = { + astro = ""; + c = "/* %s */"; + cpp = { + __default = "// %s"; + __multiline = "/* %s */"; + }; + css = "/* %s */"; + cue = "// %s"; + gleam = "// %s"; + glimmer = "{{! %s }}"; + go = { + __default = "// %s"; + __multiline = "/* %s */"; + }; + graphql = "# %s"; + haskell = "-- %s"; + handlebars = "{{! %s }}"; + hcl = { + __default = "# %s"; + __multiline = "/* %s */"; + }; + html = ""; + htmldjango = { + __default = "{# %s #}"; + __multiline = "{% comment %} %s {% endcomment %}"; + }; + ini = "; %s"; + lua = { + __default = "-- %s"; + __multiline = "--[[ %s ]]"; + }; + nix = { + __default = "# %s"; + __multiline = "/* %s */"; + }; + php = { + __default = "// %s"; + __multiline = "/* %s */"; + }; + python = { + __default = "# %s"; + __multiline = ''""" %s """''; + }; + rego = "# %s"; + rescript = { + __default = "// %s"; + __multiline = "/* %s */"; + }; + scss = { + __default = "// %s"; + __multiline = "/* %s */"; + }; + sh = "# %s"; + bash = "# %s"; + solidity = { + __default = "// %s"; + __multiline = "/* %s */"; + }; + sql = "-- %s"; + svelte = ""; + terraform = { + __default = "# %s"; + __multiline = "/* %s */"; + }; + twig = "{# %s #}"; + typescript = { + __default = "// %s"; + __multiline = "/* %s */"; + }; + typst = { + __default = "// %s"; + __multiline = "/* %s */"; + }; + vim = ''" %s''; + vue = ""; + zsh = "# %s"; + kotlin = { + __default = "// %s"; + __multiline = "/* %s */"; + }; + roc = "# %s"; + + tsx = { + __default = "// %s"; + __multiline = "/* %s */"; + jsx_element = "{/* %s */}"; + jsx_fragment = "{/* %s */}"; + jsx_attribute = { + __default = "// %s"; + __multiline = "/* %s */"; + }; + comment = { + __default = "// %s"; + __multiline = "/* %s */"; + }; + call_expression = { + __default = "// %s"; + __multiline = "/* %s */"; + }; + statement_block = { + __default = "// %s"; + __multiline = "/* %s */"; + }; + spread_element = { + __default = "// %s"; + __multiline = "/* %s */"; + }; + }; + + templ = { + __default = "// %s"; + component_block = ""; + }; + }; + + not_nested_languages = { + htmldjango = true; + }; + + config.__raw = "{}"; + }; + }; + }; + }; }