added formatter + reformat existing codebase (#175)

This commit is contained in:
Gaétan Lepage 2023-02-20 11:42:13 +01:00 committed by GitHub
parent 0bf4313f22
commit 264de8cefb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
96 changed files with 3727 additions and 3341 deletions

View file

@ -1,10 +1,13 @@
{ pkgs, lib, config, ... }:
with lib;
let
cfg = config.plugins.treesitter;
helpers = import ../helpers.nix { inherit lib; };
in
{
pkgs,
lib,
config,
...
}:
with lib; let
cfg = config.plugins.treesitter;
helpers = import ../helpers.nix {inherit lib;};
in {
options = {
plugins.treesitter = {
enable = mkEnableOption "tree-sitter syntax highlighting";
@ -22,7 +25,7 @@ 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";
};
@ -32,8 +35,7 @@ in
default =
if cfg.nixGrammars
then null
else "$XDG_DATA_HOME/nvim/treesitter"
;
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!
@ -42,38 +44,37 @@ 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 {
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";
@ -87,24 +88,31 @@ in
moduleConfig = mkOption {
type = types.attrsOf types.anything;
default = { };
default = {};
description = "This is the configuration for extra modules. It should not be used directly";
};
};
};
config =
let
tsOptions = {
config = let
tsOptions =
{
highlight = {
enable = 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 {
if cfg.incrementalSelection.enable
then {
enable = true;
keymaps = {
init_selection = cfg.incrementalSelection.keymaps.initSelection;
@ -112,29 +120,39 @@ in
scope_incremental = cfg.incrementalSelection.keymaps.scopeIncremental;
node_decremental = cfg.incrementalSelection.keymaps.nodeDecremental;
};
} else null;
}
else null;
indent =
if cfg.indent then {
if cfg.indent
then {
enable = true;
} else null;
}
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) ''
vim.opt.runtimepath:append("${cfg.parserInstallDir}")
'') + ''
require('nvim-treesitter.configs').setup(${helpers.toLuaObject tsOptions})
'';
extraConfigLua =
(optionalString (cfg.parserInstallDir != null) ''
vim.opt.runtimepath:append("${cfg.parserInstallDir}")
'')
+ ''
require('nvim-treesitter.configs').setup(${helpers.toLuaObject tsOptions})
'';
extraPlugins = with pkgs; if cfg.nixGrammars then
[ (cfg.package.withPlugins (_: cfg.grammarPackages)) ]
else [ cfg.package ];
extraPackages = [ pkgs.tree-sitter pkgs.nodejs ];
extraPlugins = with pkgs;
if cfg.nixGrammars
then [(cfg.package.withPlugins (_: cfg.grammarPackages))]
else [cfg.package];
extraPackages = [pkgs.tree-sitter pkgs.nodejs];
options = mkIf cfg.folding {
foldmethod = "expr";
@ -142,4 +160,3 @@ in
};
};
}