2023-01-25 19:46:49 +01:00
|
|
|
{
|
2023-02-20 11:42:13 +01:00
|
|
|
lib,
|
2023-11-06 15:04:08 +01:00
|
|
|
helpers,
|
|
|
|
config,
|
|
|
|
pkgs,
|
2023-02-20 11:42:13 +01:00
|
|
|
...
|
|
|
|
}:
|
2023-11-06 15:04:08 +01:00
|
|
|
with lib; {
|
2023-02-20 11:42:13 +01:00
|
|
|
options.plugins.treesitter-refactor = let
|
|
|
|
disable = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
description = "List of languages to disable the module on";
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
enable =
|
|
|
|
mkEnableOption
|
|
|
|
"treesitter-refactor (requires plugins.treesitter.enable to be true)";
|
|
|
|
|
|
|
|
package = helpers.mkPackageOption "treesitter-refactor" pkgs.vimPlugins.nvim-treesitter-refactor;
|
|
|
|
|
|
|
|
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.
|
|
|
|
'';
|
2023-01-05 15:23:23 +01:00
|
|
|
};
|
2023-02-20 11:42:13 +01:00
|
|
|
};
|
|
|
|
highlightCurrentScope = {
|
|
|
|
inherit disable;
|
2023-10-09 07:58:51 -05:00
|
|
|
enable = mkEnableOption "highlighting the block from the current scope where the cursor is";
|
2023-02-20 11:42:13 +01:00
|
|
|
};
|
|
|
|
smartRename = {
|
|
|
|
inherit disable;
|
2023-01-05 15:23:23 +01:00
|
|
|
enable =
|
|
|
|
mkEnableOption
|
2023-02-20 11:42:13 +01:00
|
|
|
"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.
|
|
|
|
'';
|
2023-01-05 15:23:23 +01:00
|
|
|
|
2023-02-20 11:42:13 +01:00
|
|
|
keymaps = {
|
|
|
|
gotoDefinition = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = "gnd";
|
|
|
|
description = "go to the definition of the symbol under the cursor";
|
|
|
|
};
|
|
|
|
gotoDefinitionLspFallback = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2023-01-05 15:23:23 +01:00
|
|
|
description = ''
|
2023-02-20 11:42:13 +01:00
|
|
|
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
|
|
|
|
mapping fo `lua require'nvim-treesitter.refactor.navigation(nil, fallback_function)<cr>`.
|
2023-01-05 15:23:23 +01:00
|
|
|
'';
|
|
|
|
};
|
2024-02-14 20:37:43 +00:00
|
|
|
listDefinitions = mkOption {
|
2023-02-20 11:42:13 +01:00
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = "gnD";
|
|
|
|
description = "list all definitions from the current file";
|
2023-01-05 15:23:23 +01:00
|
|
|
};
|
2024-02-14 20:37:43 +00:00
|
|
|
listDefinitionsToc = mkOption {
|
2023-02-20 11:42:13 +01:00
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = "gO";
|
|
|
|
description = ''
|
|
|
|
list all definitions from the current file like a table of contents (similar to the one
|
|
|
|
you see when pressing |gO| in help files).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
gotoNextUsage = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = "<a-*>";
|
|
|
|
description = "go to next usage of identifier under the cursor";
|
|
|
|
};
|
|
|
|
gotoPreviousUsage = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = "<a-#>";
|
|
|
|
description = "go to previous usage of identifier";
|
2023-01-05 15:23:23 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2023-02-20 11:42:13 +01:00
|
|
|
};
|
2023-01-05 15:23:23 +01:00
|
|
|
|
2024-02-14 20:37:43 +00:00
|
|
|
imports = [
|
|
|
|
# Added 2024-02-07
|
|
|
|
(mkRenamedOptionModule
|
|
|
|
["plugins" "treesitter-refactor" "navigation" "keymaps" "listDefinitons"]
|
|
|
|
["plugins" "treesitter-refactor" "navigation" "keymaps" "listDefinitions"])
|
|
|
|
# Added 2024-02-07
|
|
|
|
(mkRenamedOptionModule
|
|
|
|
["plugins" "treesitter-refactor" "navigation" "keymaps" "listDefinitonsToc"]
|
|
|
|
["plugins" "treesitter-refactor" "navigation" "keymaps" "listDefinitionsToc"])
|
|
|
|
];
|
|
|
|
|
2023-02-20 11:42:13 +01:00
|
|
|
config = let
|
|
|
|
cfg = config.plugins.treesitter-refactor;
|
|
|
|
in
|
2023-01-05 15:23:23 +01:00
|
|
|
mkIf cfg.enable {
|
2023-04-06 15:10:08 +02:00
|
|
|
warnings = mkIf (!config.plugins.treesitter.enable) [
|
|
|
|
"Nixvim: treesitter-refactor needs treesitter to function as intended"
|
|
|
|
];
|
|
|
|
|
2023-02-20 11:42:13 +01:00
|
|
|
extraPlugins = [cfg.package];
|
2023-01-19 10:45:15 +00:00
|
|
|
|
2023-01-05 15:23:23 +01:00
|
|
|
plugins.treesitter.moduleConfig.refactor = {
|
|
|
|
highlight_definitions = {
|
|
|
|
inherit (cfg.highlightDefinitions) enable disable;
|
|
|
|
clear_on_cursor_move = cfg.highlightDefinitions.clearOnCursorMove;
|
|
|
|
};
|
|
|
|
highlight_current_scope = cfg.highlightCurrentScope;
|
|
|
|
smart_rename = {
|
|
|
|
inherit (cfg.smartRename) enable disable;
|
2023-02-20 11:42:13 +01:00
|
|
|
keymaps = {smart_rename = cfg.smartRename.keymaps.smartRename;};
|
2023-01-05 15:23:23 +01:00
|
|
|
};
|
|
|
|
navigation = {
|
|
|
|
inherit (cfg.navigation) enable disable;
|
2023-02-20 11:42:13 +01:00
|
|
|
keymaps = let
|
|
|
|
cfgK = cfg.navigation.keymaps;
|
|
|
|
in {
|
|
|
|
goto_definition = cfgK.gotoDefinition;
|
|
|
|
goto_definition_lsp_fallback = cfgK.gotoDefinitionLspFallback;
|
2024-02-14 20:37:43 +00:00
|
|
|
list_definitions = cfgK.listDefinitions;
|
|
|
|
list_definitions_toc = cfgK.listDefinitionsToc;
|
2023-02-20 11:42:13 +01:00
|
|
|
goto_next_usage = cfgK.gotoNextUsage;
|
|
|
|
goto_previous_usage = cfgK.gotoPreviousUsage;
|
|
|
|
};
|
2023-01-05 15:23:23 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|