1
0
Fork 0
mirror of https://github.com/nix-community/nixvim.git synced 2025-11-08 11:36:07 +01:00

plugins/ts-context-commentstring: migrate to mkNeovimPlugin

Signed-off-by: saygo-png <saygo.mail@proton.me>
This commit is contained in:
saygo-png 2025-10-05 04:28:16 +02:00 committed by Austin Horstman
parent ca7f98d936
commit b633c99196
3 changed files with 201 additions and 45 deletions

View file

@ -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 {
settingsExample = {
enable_autocmd = false;
languages = {
haskell = "-- %s";
nix = {
__default = "# %s";
__multiline = "/* %s */";
};
};
};
extraConfig = cfg: {
warnings = lib.nixvim.mkWarnings "plugins.ts-context-commentstring" {
when = !config.plugins.treesitter.enable;
message = "This plugin needs treesitter to function as intended.";
};
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})
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;
};
};
}

View file

@ -0,0 +1,4 @@
{
deprecateExtraOptions = true;
optionsRenamedToSettings = [ "languages" ];
}

View file

@ -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 = "<!-- %s -->";
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 = "<!-- %s -->";
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 = "<!-- %s -->";
terraform = {
__default = "# %s";
__multiline = "/* %s */";
};
twig = "{# %s #}";
typescript = {
__default = "// %s";
__multiline = "/* %s */";
};
typst = {
__default = "// %s";
__multiline = "/* %s */";
};
vim = ''" %s'';
vue = "<!-- %s -->";
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 = "<!-- %s -->";
};
};
not_nested_languages = {
htmldjango = true;
};
config.__raw = "{}";
};
};
};
};
}