treesitter-refactor: package option + formatting

This commit is contained in:
Alexander Nortung 2023-01-17 21:50:22 +01:00
parent 4e116aad44
commit 7cd4a44462

View file

@ -1,105 +1,115 @@
{ { pkgs
pkgs, , config
config, , lib
lib, , ...
...
}: }:
with lib; { with lib; {
options.plugins.treesitter-refactor = let options.plugins.treesitter-refactor =
disable = mkOption { let
type = types.listOf types.str; disable = mkOption {
default = []; type = types.listOf types.str;
description = "List of languages to disable the module on"; default = [ ];
}; description = "List of languages to disable the module on";
in { };
enable = in
mkEnableOption {
"Enable treesitter-refactor (requires plugins.treesitter.enable to be true)";
highlightDefinitions = {
inherit disable;
enable = enable =
mkEnableOption mkEnableOption
"Highlights definition and usages of the current symbol under the cursor."; "Enable treesitter-refactor (requires plugins.treesitter.enable to be true)";
clearOnCursorMove = mkOption {
type = types.bool; package = mkOption {
default = true; type = types.package;
description = '' default = pkgs.vimPlugins.nvim-treesitter-refactor;
Controls if highlights should be cleared when the cursor is moved. If your 'updatetime' description = "Plugin to use for treesitter-refactor";
is around `100` you can set this to false to have a less laggy experience. };
highlightDefinitions = {
inherit disable;
enable =
mkEnableOption
"Highlights definition and usages of the current symbol under the cursor.";
clearOnCursorMove = mkOption {
type = types.bool;
default = true;
description = ''
Controls if highlights should be cleared when the cursor is moved. If your 'updatetime'
is around `100` you can set this to false to have a less laggy experience.
'';
};
};
highlightCurrentScope = {
inherit disable;
enable = mkEnableOption "Highlights the block from the current scope where the cursor is.";
};
smartRename = {
inherit disable;
enable =
mkEnableOption
"Renames the symbol under the cursor within the current scope (and current file).";
keymaps = {
smartRename = mkOption {
type = types.nullOr types.str;
default = "grr";
description = "rename symbol under the cursor";
};
};
};
navigation = {
inherit disable;
enable = mkEnableOption ''
Provides "go to definition" for the symbol under the cursor,
and lists the definitions from the current file.
''; '';
};
};
highlightCurrentScope = {
inherit disable;
enable = mkEnableOption "Highlights the block from the current scope where the cursor is.";
};
smartRename = {
inherit disable;
enable =
mkEnableOption
"Renames the symbol under the cursor within the current scope (and current file).";
keymaps = {
smartRename = mkOption {
type = types.nullOr types.str;
default = "grr";
description = "rename symbol under the cursor";
};
};
};
navigation = {
inherit disable;
enable = mkEnableOption ''
Provides "go to definition" for the symbol under the cursor,
and lists the definitions from the current file.
'';
keymaps = { keymaps = {
gotoDefinition = mkOption { gotoDefinition = mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
default = "gnd"; default = "gnd";
description = "go to the definition of the symbol under the cursor"; description = "go to the definition of the symbol under the cursor";
}; };
gotoDefinitionLspFallback = mkOption { gotoDefinitionLspFallback = mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
default = null; default = null;
description = '' description = ''
go to the definition of the symbol under the cursor or use vim.lsp.buf.definition if go to the definition of the symbol under the cursor or use vim.lsp.buf.definition if
the symbol can not be resolved. You can use your own fallback function if create a the symbol can not be resolved. You can use your own fallback function if create a
mapping fo `lua require'nvim-treesitter.refactor.navigation(nil, fallback_function)<cr>`. mapping fo `lua require'nvim-treesitter.refactor.navigation(nil, fallback_function)<cr>`.
''; '';
}; };
listDefinitons = mkOption { listDefinitons = mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
default = "gnD"; default = "gnD";
description = "list all definitions from the current file"; description = "list all definitions from the current file";
}; };
listDefinitonsToc = mkOption { listDefinitonsToc = mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
default = "gO"; default = "gO";
description = '' description = ''
list all definitions from the current file like a table of contents (similar to the one list all definitions from the current file like a table of contents (similar to the one
you see when pressing |gO| in help files). you see when pressing |gO| in help files).
''; '';
}; };
gotoNextUsage = mkOption { gotoNextUsage = mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
default = "<a-*>"; default = "<a-*>";
description = "go to next usage of identifier under the cursor"; description = "go to next usage of identifier under the cursor";
}; };
gotoPreviousUsage = mkOption { gotoPreviousUsage = mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
default = "<a-#>"; default = "<a-#>";
description = "go to previous usage of identifier"; description = "go to previous usage of identifier";
};
}; };
}; };
}; };
};
config = let config =
cfg = config.plugins.treesitter-refactor; let
in cfg = config.plugins.treesitter-refactor;
in
mkIf cfg.enable { mkIf cfg.enable {
extraPlugins = with pkgs.vimPlugins; [nvim-treesitter-refactor]; extraPlugins = [ cfg.package ];
plugins.treesitter.moduleConfig.refactor = { plugins.treesitter.moduleConfig.refactor = {
highlight_definitions = { highlight_definitions = {
inherit (cfg.highlightDefinitions) enable disable; inherit (cfg.highlightDefinitions) enable disable;
@ -108,20 +118,22 @@ with lib; {
highlight_current_scope = cfg.highlightCurrentScope; highlight_current_scope = cfg.highlightCurrentScope;
smart_rename = { smart_rename = {
inherit (cfg.smartRename) enable disable; inherit (cfg.smartRename) enable disable;
keymaps = {smart_rename = cfg.smartRename.keymaps.smartRename;}; keymaps = { smart_rename = cfg.smartRename.keymaps.smartRename; };
}; };
navigation = { navigation = {
inherit (cfg.navigation) enable disable; inherit (cfg.navigation) enable disable;
keymaps = let keymaps =
cfgK = cfg.navigation.keymaps; let
in { cfgK = cfg.navigation.keymaps;
goto_definition = cfgK.gotoDefinition; in
goto_definition_lsp_fallback = cfgK.gotoDefinitionLspFallback; {
list_definitions = cfgK.listDefinitons; goto_definition = cfgK.gotoDefinition;
list_definitions_toc = cfgK.listDefinitonsToc; goto_definition_lsp_fallback = cfgK.gotoDefinitionLspFallback;
goto_next_usage = cfgK.gotoNextUsage; list_definitions = cfgK.listDefinitons;
goto_previous_usage = cfgK.gotoPreviousUsage; list_definitions_toc = cfgK.listDefinitonsToc;
}; goto_next_usage = cfgK.gotoNextUsage;
goto_previous_usage = cfgK.gotoPreviousUsage;
};
}; };
}; };
}; };