Skip to content

Commit

Permalink
helpers: move rawType to helpers.nixvimTypes (nix-community#871)
Browse files Browse the repository at this point in the history
This is done in preparation of adding new (lua) types to help the
documentation.
  • Loading branch information
traxys authored Jan 1, 2024
1 parent 2f13e3a commit af41ea2
Show file tree
Hide file tree
Showing 38 changed files with 80 additions and 75 deletions.
2 changes: 1 addition & 1 deletion lib/autocmd-helpers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ in rec {
A textual description of this autocommand.
'';

callback = helpers.mkNullOrOption (with types; either str helpers.rawType) ''
callback = helpers.mkNullOrOption (with types; either str helpers.nixvimTypes.rawLua) ''
A function or a string.
- if a string, the name of a Vimscript function to call when this autocommand is triggered.
- Otherwise, a Lua function which is called when this autocommand is triggered.
Expand Down
21 changes: 13 additions & 8 deletions lib/helpers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ with lib; rec {
);

defaultNullOpts = let
maybeRaw = t: lib.types.either t rawType;
maybeRaw = t: lib.types.either t nixvimTypes.rawLua;
in rec {
mkNullable = type: default: desc:
mkNullOrOption type (
Expand Down Expand Up @@ -404,13 +404,18 @@ with lib; rec {
end
'';

rawType = mkOptionType {
name = "rawType";
description = "raw lua code";
descriptionClass = "noun";
merge = mergeEqualOption;
check = isRawType;
};
nixvimTypes =
{
rawLua = mkOptionType {
name = "rawType";
description = "raw lua code";
descriptionClass = "noun";
merge = mergeEqualOption;
check = isRawType;
};
}
# Allow to do `with nixvimTypes;` instead of `with types;`
// types;

isRawType = v: lib.isAttrs v && lib.hasAttr "__raw" v && lib.isString v.__raw;
}
2 changes: 1 addition & 1 deletion modules/commands.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ with lib; let
nargs = helpers.mkNullOrOption (types.enum ["0" "1" "*" "?" "+"]) ''
The number of arguments to expect, see :h command-nargs.
'';
complete = helpers.mkNullOrOption (with types; either str helpers.rawType) ''
complete = helpers.mkNullOrOption (with types; either str helpers.nixvimTypes.rawLua) ''
Tab-completion behaviour, see :h command-complete.
'';
range = helpers.mkNullOrOption (with types; oneOf [bool int (enum ["%"])]) ''
Expand Down
2 changes: 1 addition & 1 deletion modules/filetype.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ with lib; let
# Raw filetype
str
# Function to set the filetype
helpers.rawType
helpers.nixvimTypes.rawLua
# ["filetype" {priority = xx;}]
(listOf (either str (submodule {
options = {
Expand Down
2 changes: 1 addition & 1 deletion plugins/bufferlines/bufferline.nix
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ in {
with types;
either
(enum ["none" "ordinal" "buffer_id" "both"])
helpers.rawType
helpers.nixvimTypes.rawLua
)
"none"
''
Expand Down
2 changes: 1 addition & 1 deletion plugins/completion/copilot-lua.nix
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ in {

filetypes =
helpers.defaultNullOpts.mkNullable
(with types; attrsOf (either bool helpers.rawType))
(with types; attrsOf (either bool helpers.nixvimTypes.rawLua))
''
{
yaml = false;
Expand Down
2 changes: 1 addition & 1 deletion plugins/completion/nvim-cmp/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ in {
(
with types;
either
helpers.rawType
helpers.nixvimTypes.rawLua
(enum (attrNames snippetEngines))
)
''
Expand Down
2 changes: 1 addition & 1 deletion plugins/dap/dap-python.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ in {
By default the `VIRTUAL_ENV` and `CONDA_PREFIX` environment variables are used if present.
'';

testRunner = helpers.mkNullOrOption (types.either types.str helpers.rawType) ''
testRunner = helpers.mkNullOrOption (types.either types.str helpers.nixvimTypes.rawLua) ''
The name of test runner to use by default.
The default value is dynamic and depends on `pytest.ini` or `manage.py` markers.
If neither is found "unittest" is used.
Expand Down
10 changes: 5 additions & 5 deletions plugins/filetrees/nvim-tree.nix
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ in {
(
types.either
(types.enum ["name" "case_sensitive" "modification_time" "extension"])
helpers.rawType
helpers.nixvimTypes.rawLua
)
"name"
''
Expand Down Expand Up @@ -317,7 +317,7 @@ in {

onAttach =
helpers.defaultNullOpts.mkNullable
(with types; either (enum ["default"]) helpers.rawType)
(with types; either (enum ["default"]) helpers.nixvimTypes.rawLua)
"default"
''
Function ran when creating the nvim-tree buffer.
Expand Down Expand Up @@ -378,7 +378,7 @@ in {

padding =
helpers.defaultNullOpts.mkNullable
(either ints.unsigned helpers.rawType)
(either ints.unsigned helpers.nixvimTypes.rawLua)
"1"
"Extra padding to the right.";
};
Expand Down Expand Up @@ -466,7 +466,7 @@ in {
rootFolderLabel =
helpers.defaultNullOpts.mkNullable
# Type
(with types; oneOf [str bool helpers.rawType])
(with types; oneOf [str bool helpers.nixvimTypes.rawLua])
# Default
":~:s?$?/..?"
# Description
Expand Down Expand Up @@ -740,7 +740,7 @@ in {

picker =
helpers.defaultNullOpts.mkNullable
(types.either types.str helpers.rawType)
(types.either types.str helpers.nixvimTypes.rawLua)
"default"
''
Change the default window picker, can be a string `"default"` or a function.
Expand Down
4 changes: 2 additions & 2 deletions plugins/git/gitlinker.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ with lib; {
'';

actionCallback =
helpers.defaultNullOpts.mkNullable (with types; either str helpers.rawType)
helpers.defaultNullOpts.mkNullable (with types; either str helpers.nixvimTypes.rawLua)
"copy_to_clipboard"
''
Callback for what to do with the url.
Expand All @@ -47,7 +47,7 @@ with lib; {
(
either
str
helpers.rawType
helpers.nixvimTypes.rawLua
)
)
''
Expand Down
4 changes: 2 additions & 2 deletions plugins/languages/lint.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ with lib; let
};

args = {
type = listOf (either str helpers.rawType);
type = listOf (either str helpers.nixvimTypes.rawLua);
description = ''
List of arguments.
Can contain functions with zero arguments that will be evaluated once the linter is used.
Expand Down Expand Up @@ -229,7 +229,7 @@ in {

callback = mkOption {
type = with types;
nullOr (either str helpers.rawType);
nullOr (either str helpers.nixvimTypes.rawLua);
default = defaultCallback;
description = "What action to perform for linting";
};
Expand Down
2 changes: 1 addition & 1 deletion plugins/languages/nvim-jdtls.nix
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ in {

rootDir =
helpers.defaultNullOpts.mkNullable
(types.either types.str helpers.rawType)
(types.either types.str helpers.nixvimTypes.rawLua)
''{ __raw = "require('jdtls.setup').find_root({'.git', 'mvnw', 'gradlew'})"; }''
''
This is the default if not provided, you can remove it. Or adjust as needed.
Expand Down
4 changes: 2 additions & 2 deletions plugins/languages/treesitter/rainbow-delimiters.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ with lib; {
with types;
attrsOf (
either
helpers.rawType
helpers.nixvimTypes.rawLua
(enum ["global" "local" "noop"])
)
)
Expand Down Expand Up @@ -106,7 +106,7 @@ with lib; {
log = {
file =
helpers.defaultNullOpts.mkNullable
(with types; either str helpers.rawType)
(with types; either str helpers.nixvimTypes.rawLua)
''
{
__raw = "vim.fn.stdpath('log') .. '/rainbow-delimiters.log'";
Expand Down
2 changes: 1 addition & 1 deletion plugins/languages/vim-slime.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ in

defaultConfig =
helpers.defaultNullOpts.mkNullable
(with types; attrsOf (either str helpers.rawType))
(with types; attrsOf (either str helpers.nixvimTypes.rawLua))
"null"
''
Pre-filled prompt answer.
Expand Down
4 changes: 2 additions & 2 deletions plugins/lsp/fidget.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ with lib; let
with types;
oneOf [
str
helpers.rawType
helpers.nixvimTypes.rawLua
(listOf str)
(attrsOf (either str ints.unsigned))
]
Expand Down Expand Up @@ -593,7 +593,7 @@ in {

path =
helpers.defaultNullOpts.mkNullable
(with types; either str helpers.rawType)
(with types; either str helpers.nixvimTypes.rawLua)
''{__raw = "string.format('%s/fidget.nvim.log', vim.fn.stdpath('cache'))";}''
''
Where Fidget writes its logs to.
Expand Down
2 changes: 1 addition & 1 deletion plugins/lsp/language-servers/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ with lib; let
nullOr
(
listOf
(either str helpers.rawType)
(either str helpers.nixvimTypes.rawLua)
);
description = ''
An array of abosolute or workspace-relative paths that will be added to the workspace
Expand Down
2 changes: 1 addition & 1 deletion plugins/lsp/language-servers/efmls-configs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ in {
miscFormatters = languageTools "misc" "formatters";

mkChooseOption = lang: kind: possible: let
toolType = with types; either (enum possible) helpers.rawType;
toolType = with types; either (enum possible) helpers.nixvimTypes.rawLua;
in
mkOption {
type = with types; either toolType (listOf toolType);
Expand Down
2 changes: 1 addition & 1 deletion plugins/lsp/language-servers/pylsp.nix
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ in {
overrides =
helpers.defaultNullOpts.mkNullable
(types.listOf
(types.oneOf [types.bool types.str helpers.rawType]))
(types.oneOf [types.bool types.str helpers.nixvimTypes.rawLua]))
"[true]"
''
Specifies a list of alternate or supplemental command-line options.
Expand Down
2 changes: 1 addition & 1 deletion plugins/lsp/wtf.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ in {
Default AI popup type.
'';

openaiApiKey = helpers.mkNullOrOption (with types; either str helpers.rawType) ''
openaiApiKey = helpers.mkNullOrOption (with types; either str helpers.nixvimTypes.rawLua) ''
An alternative way to set your API key.
'';

Expand Down
12 changes: 6 additions & 6 deletions plugins/pluginmanagers/packer.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ in {
helpers.mkNullOrOption
(oneOf [
str
helpers.rawType
(listOf (either str helpers.rawType))
helpers.nixvimTypes.rawLua
(listOf (either str helpers.nixvimTypes.rawLua))
])
"Post-install hook";

Expand All @@ -67,11 +67,11 @@ in {
"Luarocks dependencies";

config =
helpers.mkNullOrOption (either str helpers.rawType)
helpers.mkNullOrOption (either str helpers.nixvimTypes.rawLua)
"Code to run after this plugin is loaded";

setup =
helpers.mkNullOrOption (either str helpers.rawType)
helpers.mkNullOrOption (either str helpers.nixvimTypes.rawLua)
"Code to be run before this plugin is loaded";

cmd =
Expand All @@ -98,8 +98,8 @@ in {
helpers.mkNullOrOption
(oneOf [
str
helpers.rawType
(listOf (either str helpers.rawType))
helpers.nixvimTypes.rawLua
(listOf (either str helpers.nixvimTypes.rawLua))
])
"Conditional test to load this plugin";

Expand Down
8 changes: 4 additions & 4 deletions plugins/snippets/luasnip/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ in {
[
str
path
helpers.rawType
helpers.nixvimTypes.rawLua
(listOf (oneOf
[
str
path
helpers.rawType
helpers.nixvimTypes.rawLua
]))
]);
};
Expand Down Expand Up @@ -122,12 +122,12 @@ in {
[
str
path
helpers.rawType
helpers.nixvimTypes.rawLua
(listOf (oneOf
[
str
path
helpers.rawType
helpers.nixvimTypes.rawLua
]))
]
)
Expand Down
2 changes: 1 addition & 1 deletion plugins/statuslines/lualine.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ with lib; let
(submodule {
options = {
name = mkOption {
type = types.either types.str helpers.rawType;
type = types.either types.str helpers.nixvimTypes.rawLua;
description = "Component name or function";
default = defaultName;
};
Expand Down
6 changes: 3 additions & 3 deletions plugins/telescope/file-browser.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ in {

theme = helpers.mkNullOrOption types.str "Custom theme, will use your global theme by default.";

path = helpers.defaultNullOpts.mkNullable (types.either types.str helpers.rawType) "vim.loop.cwd()" ''
path = helpers.defaultNullOpts.mkNullable (types.either types.str helpers.nixvimTypes.rawLua) "vim.loop.cwd()" ''
Directory to browse files from.
`vim.fn.expanded` automatically.
'';

cwd = helpers.defaultNullOpts.mkNullable (types.either types.str helpers.rawType) "vim.loop.cwd()" ''
cwd = helpers.defaultNullOpts.mkNullable (types.either types.str helpers.nixvimTypes.rawLua) "vim.loop.cwd()" ''
Directory to browse folders from.
`vim.fn.expanded` automatically.
'';
Expand Down Expand Up @@ -131,7 +131,7 @@ in {
mappings =
helpers.mkNullOrOption (
with types;
attrsOf (attrsOf (either str helpers.rawType))
attrsOf (attrsOf (either str helpers.nixvimTypes.rawLua))
) ''
`fb_actions` mappings.
Mappings can also be a lua function.
Expand Down
2 changes: 1 addition & 1 deletion plugins/utils/auto-save.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ in {
executionMessage = {
message =
helpers.defaultNullOpts.mkNullable
(with types; either str helpers.rawType)
(with types; either str helpers.nixvimTypes.rawLua)
''
{
__raw = \'\'
Expand Down
4 changes: 2 additions & 2 deletions plugins/utils/auto-session.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ in {

rootDir =
helpers.defaultNullOpts.mkNullable
(with types; either str helpers.rawType)
(with types; either str helpers.nixvimTypes.rawLua)
"{__raw = \"vim.fn.stdpath 'data' .. '/sessions/'\";}"
''
Root directory for session files.
Expand Down Expand Up @@ -128,7 +128,7 @@ in {
sessionControl = {
controlDir =
helpers.defaultNullOpts.mkNullable
(with types; either str helpers.rawType)
(with types; either str helpers.nixvimTypes.rawLua)
"\"vim.fn.stdpath 'data' .. '/auto_session/'\""
''
Auto session control dir, for control files, like alternating between two sessions
Expand Down
Loading

0 comments on commit af41ea2

Please sign in to comment.