treewide: Reformat with nixfmt

This commit is contained in:
traxys 2024-05-05 19:39:35 +02:00
parent c6281260dc
commit 62f32bfc71
459 changed files with 28139 additions and 26377 deletions

View file

@ -5,9 +5,11 @@
pkgs,
...
}:
with lib; let
with lib;
let
cfg = config.plugins.treesitter;
in {
in
{
options = {
plugins.treesitter = {
enable = mkEnableOption "tree-sitter syntax highlighting";
@ -25,17 +27,19 @@ in {
};
ensureInstalled = mkOption {
type = with types; oneOf [(enum ["all"]) (listOf str)];
type =
with types;
oneOf [
(enum [ "all" ])
(listOf str)
];
default = "all";
description = "Either \"all\" or a list of languages";
};
gccPackage = mkOption {
type = with types; nullOr package;
default =
if cfg.nixGrammars
then null
else pkgs.gcc;
default = if cfg.nixGrammars then null else pkgs.gcc;
example = null;
description = ''
Which package (if any) to be added as the GCC compiler.
@ -46,10 +50,7 @@ in {
parserInstallDir = mkOption {
type = types.nullOr types.str;
default =
if cfg.nixGrammars
then null
else "$XDG_DATA_HOME/nvim/treesitter";
default = if cfg.nixGrammars then null else "$XDG_DATA_HOME/nvim/treesitter";
description = ''
Location of the parsers to be installed by the plugin (only needed when nixGrammars is disabled).
This default might not work on your own install, please make sure that $XDG_DATA_HOME is set if you want to use the default. Otherwise, change it to something that will work for you!
@ -58,37 +59,40 @@ in {
ignoreInstall = mkOption {
type = types.listOf types.str;
default = [];
default = [ ];
description = "List of parsers to ignore installing (for \"all\")";
};
disabledLanguages = mkOption {
type = types.listOf types.str;
default = [];
default = [ ];
description = "A list of languages to disable";
};
customCaptures = mkOption {
type = types.attrsOf types.str;
default = {};
default = { };
description = "Custom capture group highlighting";
};
incrementalSelection = let
keymap = default:
mkOption {
type = types.str;
inherit default;
incrementalSelection =
let
keymap =
default:
mkOption {
type = types.str;
inherit default;
};
in
{
enable = mkEnableOption "incremental selection based on the named nodes from the grammar";
keymaps = {
initSelection = keymap "gnn";
nodeIncremental = keymap "grn";
scopeIncremental = keymap "grc";
nodeDecremental = keymap "grm";
};
in {
enable = mkEnableOption "incremental selection based on the named nodes from the grammar";
keymaps = {
initSelection = keymap "gnn";
nodeIncremental = keymap "grn";
scopeIncremental = keymap "grc";
nodeDecremental = keymap "grm";
};
};
indent = mkEnableOption "tree-sitter based indentation";
@ -101,10 +105,13 @@ in {
Register specific parsers to one or several filetypes.
The keys are the parser names and the values are either one or several filetypes.
'';
default = {};
default = { };
example = {
cpp = "onelab";
python = ["myFiletype" "anotherFiletype"];
python = [
"myFiletype"
"anotherFiletype"
];
};
};
@ -116,61 +123,45 @@ in {
moduleConfig = mkOption {
type = types.attrsOf types.anything;
default = {};
default = { };
description = "This is the configuration for extra modules. It should not be used directly";
};
nixvimInjections =
mkEnableOption
"nixvim specific injections, like lua highlighting in extraConfigLua";
nixvimInjections = mkEnableOption "nixvim specific injections, like lua highlighting in extraConfigLua";
};
};
config = let
tsOptions =
{
config =
let
tsOptions = {
highlight = {
inherit (cfg) enable;
disable =
if (cfg.disabledLanguages != [])
then cfg.disabledLanguages
else null;
disable = if (cfg.disabledLanguages != [ ]) then cfg.disabledLanguages else null;
custom_captures =
if (cfg.customCaptures != {})
then cfg.customCaptures
else null;
custom_captures = if (cfg.customCaptures != { }) then cfg.customCaptures else null;
};
incremental_selection =
if cfg.incrementalSelection.enable
then {
enable = true;
keymaps = {
init_selection = cfg.incrementalSelection.keymaps.initSelection;
node_incremental = cfg.incrementalSelection.keymaps.nodeIncremental;
scope_incremental = cfg.incrementalSelection.keymaps.scopeIncremental;
node_decremental = cfg.incrementalSelection.keymaps.nodeDecremental;
};
}
else null;
if cfg.incrementalSelection.enable then
{
enable = true;
keymaps = {
init_selection = cfg.incrementalSelection.keymaps.initSelection;
node_incremental = cfg.incrementalSelection.keymaps.nodeIncremental;
scope_incremental = cfg.incrementalSelection.keymaps.scopeIncremental;
node_decremental = cfg.incrementalSelection.keymaps.nodeDecremental;
};
}
else
null;
indent =
if cfg.indent
then {
enable = true;
}
else null;
indent = if cfg.indent then { enable = true; } else null;
ensure_installed =
if cfg.nixGrammars
then []
else cfg.ensureInstalled;
ensure_installed = if cfg.nixGrammars then [ ] else cfg.ensureInstalled;
ignore_install = cfg.ignoreInstall;
parser_install_dir = cfg.parserInstallDir;
}
// cfg.moduleConfig;
in
} // cfg.moduleConfig;
in
mkIf cfg.enable {
extraConfigLua =
(optionalString (cfg.parserInstallDir != null) ''
@ -179,7 +170,7 @@ in {
+ ''
require('nvim-treesitter.configs').setup(${helpers.toLuaObject tsOptions})
''
+ (optionalString (cfg.languageRegister != {}) ''
+ (optionalString (cfg.languageRegister != { }) ''
__parserFiletypeMappings = ${helpers.toLuaObject cfg.languageRegister}
for parser_name, ft in pairs(__parserFiletypeMappings) do
@ -210,9 +201,7 @@ in {
};
extraPlugins =
if cfg.nixGrammars
then [(cfg.package.withPlugins (_: cfg.grammarPackages))]
else [cfg.package];
if cfg.nixGrammars then [ (cfg.package.withPlugins (_: cfg.grammarPackages)) ] else [ cfg.package ];
extraPackages = with pkgs; [
tree-sitter
nodejs