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,54 +1,64 @@
{ lib, pkgs, ... }@attrs:
let
helpers = import ../../helpers.nix { inherit lib; };
in with helpers; with lib;
{
mkCmpSourcePlugin = { name, extraPlugins ? [], useDefaultPackage ? true, ... }: mkPlugin attrs {
inherit name;
extraPlugins = extraPlugins ++ (lists.optional useDefaultPackage pkgs.vimPlugins.${name});
description = "Enable ${name}";
};
lib,
pkgs,
...
} @ attrs: let
helpers = import ../../helpers.nix {inherit lib;};
in
with helpers;
with lib; {
mkCmpSourcePlugin = {
name,
extraPlugins ? [],
useDefaultPackage ? true,
...
}:
mkPlugin attrs {
inherit name;
extraPlugins = extraPlugins ++ (lists.optional useDefaultPackage pkgs.vimPlugins.${name});
description = "Enable ${name}";
};
pluginAndSourceNames = {
"luasnip" = "cmp_luasnip";
"snippy" = "cmp-snippy";
"ultisnips" = "cmp-nvim-ultisnips";
"vsnip" = "cmp-vsnip";
"buffer" = "cmp-buffer";
"calc" = "cmp-calc";
"dictionary" = "cmp-dictionary";
"digraphs" = "cmp-digraphs";
"omni" = "cmp-omni";
"spell" = "cmp-spell";
"nvim_lsp" = "cmp-nvim-lsp";
"nvim_lsp_document_symbol" = "cmp-nvim-lsp-document-symbol";
"nvim_lsp_signature_help" = "cmp-nvim-lsp-signature-help";
"vim_lsp" = "cmp-vim-lsp";
"path" = "cmp-path";
"git" = "cmp-git";
"conventionalcommits" = "cmp-conventionalcommits";
"cmdline" = "cmp-cmdline";
"cmp-cmdline-history" = "cmp-cmdline-history";
"fuzzy_buffer" = "cmp-fuzzy-buffer";
"fuzzy_path" = "cmp-fuzzy-path";
"rg" = "cmp-rg";
"fish" = "cmp-fish";
"tmux" = "cmp-tmux";
"zsh" = "cmp-zsh";
"crates" = "crates-nvim";
"npm" = "cmp-npm";
"cmp-clippy" = "cmp-clippy";
"cmp_tabnine" = "cmp-tabnine";
"copilot" = "cmp-copilot";
"dap" = "cmp-dap";
"emoji" = "cmp-emoji";
"greek" = "cmp-greek";
"latex_symbols" = "cmp-latex-symbols";
"look" = "cmp-look";
"nvim_lua" = "cmp-nvim-lua";
"pandoc_references" = "cmp-pandoc-references";
"cmp_pandoc" = "cmp-pandoc-nvim";
"treesitter" = "cmp-treesitter";
"vimwiki-tags" = "cmp-vimwiki-tags";
};
}
pluginAndSourceNames = {
"luasnip" = "cmp_luasnip";
"snippy" = "cmp-snippy";
"ultisnips" = "cmp-nvim-ultisnips";
"vsnip" = "cmp-vsnip";
"buffer" = "cmp-buffer";
"calc" = "cmp-calc";
"dictionary" = "cmp-dictionary";
"digraphs" = "cmp-digraphs";
"omni" = "cmp-omni";
"spell" = "cmp-spell";
"nvim_lsp" = "cmp-nvim-lsp";
"nvim_lsp_document_symbol" = "cmp-nvim-lsp-document-symbol";
"nvim_lsp_signature_help" = "cmp-nvim-lsp-signature-help";
"vim_lsp" = "cmp-vim-lsp";
"path" = "cmp-path";
"git" = "cmp-git";
"conventionalcommits" = "cmp-conventionalcommits";
"cmdline" = "cmp-cmdline";
"cmp-cmdline-history" = "cmp-cmdline-history";
"fuzzy_buffer" = "cmp-fuzzy-buffer";
"fuzzy_path" = "cmp-fuzzy-path";
"rg" = "cmp-rg";
"fish" = "cmp-fish";
"tmux" = "cmp-tmux";
"zsh" = "cmp-zsh";
"crates" = "crates-nvim";
"npm" = "cmp-npm";
"cmp-clippy" = "cmp-clippy";
"cmp_tabnine" = "cmp-tabnine";
"copilot" = "cmp-copilot";
"dap" = "cmp-dap";
"emoji" = "cmp-emoji";
"greek" = "cmp-greek";
"latex_symbols" = "cmp-latex-symbols";
"look" = "cmp-look";
"nvim_lua" = "cmp-nvim-lua";
"pandoc_references" = "cmp-pandoc-references";
"cmp_pandoc" = "cmp-pandoc-nvim";
"treesitter" = "cmp-treesitter";
"vimwiki-tags" = "cmp-vimwiki-tags";
};
}

View file

@ -1,19 +1,20 @@
{ pkgs, config, lib, ... }@args:
with lib;
let
{
pkgs,
config,
lib,
...
} @ args:
with lib; let
cfg = config.plugins.nvim-cmp;
helpers = import ../../helpers.nix { inherit lib; };
helpers = import ../../helpers.nix {inherit lib;};
mkNullOrOption = helpers.mkNullOrOption;
cmpLib = import ./cmp-helpers.nix args;
# functionName should be a string
# parameters should be a list of strings
wrapWithFunction = functionName: parameters:
let
parameterString = strings.concatStringsSep "," parameters;
in
''${functionName}(${parameterString})'';
in
{
wrapWithFunction = functionName: parameters: let
parameterString = strings.concatStringsSep "," parameters;
in ''${functionName}(${parameterString})'';
in {
options.plugins.nvim-cmp = {
enable = mkEnableOption "nvim-cmp";
@ -21,7 +22,7 @@ in
performance = mkOption {
default = null;
type = types.nullOr (types.submodule ({ ... }: {
type = types.nullOr (types.submodule ({...}: {
options = {
debounce = mkOption {
type = types.nullOr types.int;
@ -36,14 +37,14 @@ in
};
preselect = mkOption {
type = types.nullOr (types.enum [ "Item" "None" ]);
type = types.nullOr (types.enum ["Item" "None"]);
default = null;
example = ''"Item"'';
};
snippet = mkOption {
default = null;
type = types.nullOr (types.submodule ({ ... }: {
type = types.nullOr (types.submodule ({...}: {
options = {
expand = mkOption {
type = types.nullOr types.str;
@ -61,7 +62,7 @@ in
};
mappingPresets = mkOption {
default = [ ];
default = [];
type = types.listOf (types.enum [
"insert"
"cmdline"
@ -75,7 +76,7 @@ in
mapping = mkOption {
default = null;
type = types.nullOr (types.attrsOf (types.either types.str (types.submodule ({ ... }: {
type = types.nullOr (types.attrsOf (types.either types.str (types.submodule ({...}: {
options = {
action = mkOption {
type = types.nonEmptyStr;
@ -116,7 +117,7 @@ in
completion = mkOption {
default = null;
type = types.nullOr (types.submodule ({ ... }: {
type = types.nullOr (types.submodule ({...}: {
options = {
keyword_length = mkOption {
default = null;
@ -145,7 +146,7 @@ in
confirmation = mkOption {
default = null;
type = types.nullOr (types.submodule ({ ... }: {
type = types.nullOr (types.submodule ({...}: {
options = {
get_commit_characters = mkOption {
default = null;
@ -158,7 +159,7 @@ in
formatting = mkOption {
default = null;
type = types.nullOr (types.submodule ({ ... }: {
type = types.nullOr (types.submodule ({...}: {
options = {
fields = mkOption {
default = null;
@ -176,7 +177,7 @@ in
matching = mkOption {
default = null;
type = types.nullOr (types.submodule ({ ... }: {
type = types.nullOr (types.submodule ({...}: {
options = {
disallow_fuzzy_matching = mkOption {
default = null;
@ -196,7 +197,7 @@ in
sorting = mkOption {
default = null;
type = types.nullOr (types.submodule ({ ... }: {
type = types.nullOr (types.submodule ({...}: {
options = {
priority_weight = mkOption {
default = null;
@ -218,54 +219,53 @@ in
'';
};
sources =
let
source_config = types.submodule ({ ... }: {
options = {
name = mkOption {
type = types.str;
description = "The name of the source.";
example = ''"buffer"'';
};
option = mkOption {
default = null;
type = with types; nullOr (attrsOf anything);
description = "If direct lua code is needed use helpers.mkRaw";
};
keyword_length = mkOption {
default = null;
type = types.nullOr types.int;
};
keyword_pattern = mkOption {
default = null;
type = types.nullOr types.int;
};
trigger_characters = mkOption {
default = null;
type = with types; nullOr (listOf str);
};
priority = mkOption {
default = null;
type = types.nullOr types.int;
};
max_item_count = mkOption {
default = null;
type = types.nullOr types.int;
};
group_index = mkOption {
default = null;
type = types.nullOr types.int;
};
sources = let
source_config = types.submodule ({...}: {
options = {
name = mkOption {
type = types.str;
description = "The name of the source.";
example = ''"buffer"'';
};
});
in
option = mkOption {
default = null;
type = with types; nullOr (attrsOf anything);
description = "If direct lua code is needed use helpers.mkRaw";
};
keyword_length = mkOption {
default = null;
type = types.nullOr types.int;
};
keyword_pattern = mkOption {
default = null;
type = types.nullOr types.int;
};
trigger_characters = mkOption {
default = null;
type = with types; nullOr (listOf str);
};
priority = mkOption {
default = null;
type = types.nullOr types.int;
};
max_item_count = mkOption {
default = null;
type = types.nullOr types.int;
};
group_index = mkOption {
default = null;
type = types.nullOr types.int;
};
};
});
in
mkOption {
default = null;
type = with types; nullOr (either (listOf source_config) (listOf (listOf source_config)));
@ -286,7 +286,7 @@ in
view = mkOption {
default = null;
type = types.nullOr (types.submodule ({ ... }: {
type = types.nullOr (types.submodule ({...}: {
options = {
entries = mkOption {
default = null;
@ -296,20 +296,19 @@ in
}));
};
window =
let
# Reusable options
border = with types; mkNullOrOption (either str (listOf str)) null;
winhighlight = mkNullOrOption types.str null;
zindex = mkNullOrOption types.int null;
in
window = let
# Reusable options
border = with types; mkNullOrOption (either str (listOf str)) null;
winhighlight = mkNullOrOption types.str null;
zindex = mkNullOrOption types.int null;
in
mkOption {
default = null;
type = types.nullOr (types.submodule ({ ... }: {
type = types.nullOr (types.submodule ({...}: {
options = {
completion = mkOption {
default = null;
type = types.nullOr (types.submodule ({ ... }: {
type = types.nullOr (types.submodule ({...}: {
options = {
inherit border winhighlight zindex;
col_offset = mkNullOrOption types.int "Offsets the completion window relative to the cursor";
@ -320,7 +319,7 @@ in
documentation = mkOption {
default = null;
type = types.nullOr (types.submodule ({ ... }: {
type = types.nullOr (types.submodule ({...}: {
options = {
inherit border winhighlight zindex;
max_width = mkNullOrOption types.int "Window's max width";
@ -336,68 +335,99 @@ in
experimental = mkNullOrOption types.attrs "Experimental features";
};
config =
let
options = {
enabled = cfg.enable;
performance = cfg.performance;
preselect = if (isNull cfg.preselect) then null else helpers.mkRaw "cmp.PreselectMode.${cfg.preselect}";
config = let
options = {
enabled = cfg.enable;
performance = cfg.performance;
preselect =
if (isNull cfg.preselect)
then null
else helpers.mkRaw "cmp.PreselectMode.${cfg.preselect}";
# Not very readable sorry
# If null then null
# If an attribute is a string, just treat it as lua code for that mapping
# If an attribute is a module, create a mapping with cmp.mapping() using the action as the first input and the modes as the second.
mapping =
let
mappings =
if (isNull cfg.mapping) then null
else
mapAttrs
(bind: mapping: helpers.mkRaw (if isString mapping then mapping
else "cmp.mapping(${mapping.action}${optionalString (mapping.modes != null && length mapping.modes >= 1) ("," + (helpers.toLuaObject mapping.modes))})"))
cfg.mapping;
luaMappings = (helpers.toLuaObject mappings);
wrapped = lists.fold (presetName: prevString: ''cmp.mapping.preset.${presetName}(${prevString})'') luaMappings cfg.mappingPresets;
in
helpers.mkRaw wrapped;
# Not very readable sorry
# If null then null
# If an attribute is a string, just treat it as lua code for that mapping
# If an attribute is a module, create a mapping with cmp.mapping() using the action as the first input and the modes as the second.
mapping = let
mappings =
if (isNull cfg.mapping)
then null
else
mapAttrs
(bind: mapping:
helpers.mkRaw (
if isString mapping
then mapping
else "cmp.mapping(${mapping.action}${optionalString (mapping.modes != null && length mapping.modes >= 1) ("," + (helpers.toLuaObject mapping.modes))})"
))
cfg.mapping;
luaMappings = helpers.toLuaObject mappings;
wrapped = lists.fold (presetName: prevString: ''cmp.mapping.preset.${presetName}(${prevString})'') luaMappings cfg.mappingPresets;
in
helpers.mkRaw wrapped;
snippet = {
expand = if (isNull cfg.snippet || isNull cfg.snippet.expand) then null else helpers.mkRaw cfg.snippet.expand;
};
snippet = {
expand =
if (isNull cfg.snippet || isNull cfg.snippet.expand)
then null
else helpers.mkRaw cfg.snippet.expand;
};
completion = if (isNull cfg.completion) then null else {
completion =
if (isNull cfg.completion)
then null
else {
keyword_length = cfg.completion.keyword_length;
keyword_pattern = cfg.completion.keyword_pattern;
autocomplete = if (isNull cfg.completion.autocomplete) then null else mkRaw cfg.completion.autocomplete;
autocomplete =
if (isNull cfg.completion.autocomplete)
then null
else mkRaw cfg.completion.autocomplete;
completeopt = cfg.completion.completeopt;
};
confirmation = if (isNull cfg.confirmation) then null else {
confirmation =
if (isNull cfg.confirmation)
then null
else {
get_commit_characters =
if (isString cfg.confirmation.get_commit_characters) then helpers.mkRaw cfg.confirmation.get_commit_characters
if (isString cfg.confirmation.get_commit_characters)
then helpers.mkRaw cfg.confirmation.get_commit_characters
else cfg.confirmation.get_commit_characters;
};
formatting = if (isNull cfg.formatting) then null else {
formatting =
if (isNull cfg.formatting)
then null
else {
fields = cfg.formatting.fields;
format = if (isNull cfg.formatting.format) then null else helpers.mkRaw cfg.formatting.format;
format =
if (isNull cfg.formatting.format)
then null
else helpers.mkRaw cfg.formatting.format;
};
matching = cfg.matching;
matching = cfg.matching;
sorting = if (isNull cfg.sorting) then null else {
sorting =
if (isNull cfg.sorting)
then null
else {
priority_weight = cfg.sorting.priority_weight;
comparators = if (isNull cfg.sorting.comparators) then null else helpers.mkRaw cfg.sorting.comparators;
comparators =
if (isNull cfg.sorting.comparators)
then null
else helpers.mkRaw cfg.sorting.comparators;
};
sources = cfg.sources;
view = cfg.view;
window = cfg.window;
experimental = cfg.experimental;
};
in
sources = cfg.sources;
view = cfg.view;
window = cfg.window;
experimental = cfg.experimental;
};
in
mkIf cfg.enable {
extraPlugins = [ cfg.package ];
extraPlugins = [cfg.package];
extraConfigLua = helpers.wrapDo ''
local cmp = require('cmp')
@ -406,21 +436,23 @@ in
# If auto_enable_sources is set to true, figure out which are provided by the user
# and enable the corresponding plugins.
plugins =
let
flattened_sources = if (isNull cfg.sources) then [ ] else flatten cfg.sources;
# Take only the names from the sources provided by the user
found_sources = lists.unique (lists.map (source: source.name) flattened_sources);
# A list of known source names
known_source_names = attrNames cmpLib.pluginAndSourceNames;
plugins = let
flattened_sources =
if (isNull cfg.sources)
then []
else flatten cfg.sources;
# Take only the names from the sources provided by the user
found_sources = lists.unique (lists.map (source: source.name) flattened_sources);
# A list of known source names
known_source_names = attrNames cmpLib.pluginAndSourceNames;
attrs_enabled = listToAttrs (map
(name: {
name = cmpLib.pluginAndSourceNames.${name};
value.enable = mkIf (elem name found_sources) true;
})
known_source_names);
in
attrs_enabled = listToAttrs (map
(name: {
name = cmpLib.pluginAndSourceNames.${name};
value.enable = mkIf (elem name found_sources) true;
})
known_source_names);
in
mkIf cfg.auto_enable_sources attrs_enabled;
};
}

View file

@ -1,12 +1,16 @@
{ lib, pkgs, ... }@attrs:
with lib;
let
{
lib,
pkgs,
...
} @ attrs:
with lib; let
cmpLib = import ../cmp-helpers.nix attrs;
cmpSourcesPluginNames = lib.attrValues cmpLib.pluginAndSourceNames;
pluginModules = lists.map (name: cmpLib.mkCmpSourcePlugin { inherit name; }) cmpSourcesPluginNames;
in
{
pluginModules = lists.map (name: cmpLib.mkCmpSourcePlugin {inherit name;}) cmpSourcesPluginNames;
in {
# For extra cmp plugins
imports = [
] ++ pluginModules;
imports =
[
]
++ pluginModules;
}