Merge branch 'main' into snacks-integrations

This commit is contained in:
raf 2025-04-27 03:09:25 +00:00 committed by GitHub
commit 5259d1887e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 548 additions and 333 deletions

View file

@ -17,7 +17,7 @@
mkEnableOption ""
// {
default = true;
description = "Whether to enable this autocommand";
description = "Whether to enable this autocommand.";
};
event = mkOption {
@ -31,7 +31,7 @@
type = nullOr (listOf str);
default = null;
example = ["*.lua" "*.vim"];
description = "The file pattern(s) that determine when the autocommand applies).";
description = "The file pattern(s) that determine when the autocommand applies.";
};
callback = mkOption {
@ -44,13 +44,16 @@
end
''''
'';
description = "The file pattern(s) that determine when the autocommand applies.";
description = "Lua function to be called when the event(s) are triggered.";
};
command = mkOption {
type = nullOr str;
default = null;
description = "Vim command string instead of a Lua function.";
description = ''
Vim command to be executed when the event(s) are triggered.
Cannot be defined if the `callback` option is already defined.
'';
};
group = mkOption {
@ -70,7 +73,7 @@
once = mkOption {
type = bool;
default = false;
description = "Whether autocommand run only once.";
description = "Whether to run the autocommand only once.";
};
nested = mkOption {
@ -87,7 +90,7 @@
mkEnableOption ""
// {
default = true;
description = "Whether to enable this autogroup";
description = "Whether to enable this autocommand group.";
};
name = mkOption {
@ -118,8 +121,8 @@ in {
autocommands together. Groups allow multiple autocommands to be cleared
or redefined collectively, preventing duplicate definitions.
Each autogroup consists of a name, a boolean indicating whether to clear
existing autocommands, and a list of associated autocommands.
Each autogroup consists of a name and a boolean indicating whether to clear
existing autocommands.
'';
};
@ -129,8 +132,8 @@ in {
description = ''
A list of Neovim autocommands to be registered.
Each entry defines an autocommand, specifying events, patterns, optional
callbacks, commands, groups, and execution settings.
Each entry defines an autocommand, specifying events, patterns, a callback or Vim
command, an optional group, a description, and execution settings.
'';
};
};

View file

@ -5,15 +5,14 @@
}: let
inherit (lib.options) mkOption;
inherit (lib.types) nullOr attrsOf listOf submodule bool ints str enum;
inherit (lib.strings) hasPrefix concatLines;
inherit (lib.strings) concatLines;
inherit (lib.attrsets) mapAttrsToList;
inherit (lib.nvim.dag) entryBetween;
inherit (lib.nvim.lua) toLuaObject;
inherit (lib.nvim.types) hexColor;
mkColorOption = target:
mkOption {
type = nullOr hexColor;
type = nullOr str;
default = null;
example = "#ebdbb2";
description = ''

View file

@ -30,7 +30,16 @@
in {
config = mkIf cfg.enable {
vim = {
startPlugins = ["chatgpt-nvim"];
startPlugins = [
"chatgpt-nvim"
# Dependencies
"nui-nvim"
"plenary-nvim"
];
# ChatGPT.nvim explicitly depends on Telescope.
telescope.enable = true;
pluginRC.chagpt = entryAnywhere ''
require("chatgpt").setup(${toLuaObject cfg.setupOpts})

View file

@ -9,7 +9,14 @@ in {
setupOpts = mkPluginSetupOption "codecompanion-nvim" {
opts = {
send_code = mkEnableOption "code from being sent to the LLM.";
send_code =
mkEnableOption ""
// {
default = true;
description = ''
Whether to enable code being sent to the LLM.
'';
};
log_level = mkOption {
type = enum ["DEBUG" "INFO" "ERROR" "TRACE"];
@ -30,7 +37,10 @@ in {
mkEnableOption ""
// {
default = true;
description = "a diff view to see the changes made by the LLM.";
description = ''
Whether to enable a diff view
to see the changes made by the LLM.
'';
};
close_chat_at = mkOption {
@ -64,7 +74,12 @@ in {
};
chat = {
auto_scroll = mkEnableOption "automatic page scrolling.";
auto_scroll =
mkEnableOption ""
// {
default = true;
description = "Whether to enable automatic page scrolling.";
};
show_settings = mkEnableOption ''
LLM settings to appear at the top of the chat buffer.
@ -85,14 +100,18 @@ in {
mkEnableOption ""
// {
default = true;
description = "references in the chat buffer.";
description = ''
Whether to enable references in the chat buffer.
'';
};
show_token_count =
mkEnableOption ""
// {
default = true;
description = "the token count for each response.";
description = ''
Whether to enable the token count for each response.
'';
};
intro_message = mkOption {
@ -155,7 +174,10 @@ in {
mkEnableOption ""
// {
default = true;
description = "showing default actions in the action palette.";
description = ''
Whether to enable showing default
actions in the action palette.
'';
};
show_default_prompt_library =
@ -163,7 +185,8 @@ in {
// {
default = true;
description = ''
showing default prompt library in the action palette.
Whether to enable showing default
prompt library in the action palette.
'';
};
};

View file

@ -22,6 +22,11 @@ in {
};
treesitter.enable = true;
autocomplete.nvim-cmp = {
sources = {codecompanion-nvim = "[codecompanion]";};
sourcePlugins = ["codecompanion-nvim"];
};
};
};
}

View file

@ -28,6 +28,8 @@ in {
end
end
end
nvf_lint = ${toLuaObject cfg.lint_function}
'';
};
})
@ -38,8 +40,8 @@ in {
{
event = ["BufWritePost"];
callback = mkLuaInline ''
function()
require("lint").try_lint()
function(args)
nvf_lint(args.buf)
end
'';
}

View file

@ -1,7 +1,8 @@
{lib, ...}: let
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.options) mkOption mkEnableOption literalExpression;
inherit (lib.types) nullOr attrsOf listOf str either submodule bool enum;
inherit (lib.nvim.types) luaInline;
inherit (lib.generators) mkLuaInline;
linterType = submodule {
options = {
@ -69,6 +70,23 @@
default = null;
description = "Parser function";
};
required_files = mkOption {
type = nullOr (listOf str);
default = null;
example = ["eslint.config.js"];
description = ''
Required files to lint. These files must exist relative to the cwd
of the linter or else this linter will be skipped
::: {.note}
This option is an nvf extension that only takes effect if you
use the `nvf_lint()` lua function.
See {option}`vim.diagnostics.nvim-lint.lint_function`.
:::
'';
};
};
};
in {
@ -117,5 +135,53 @@ in {
};
lint_after_save = mkEnableOption "autocmd to lint after each save" // {default = true;};
lint_function = mkOption {
type = luaInline;
default = mkLuaInline ''
function(buf)
local ft = vim.api.nvim_get_option_value("filetype", { buf = buf })
local linters = require("lint").linters
local linters_from_ft = require("lint").linters_by_ft[ft]
-- if no linter is configured for this filetype, stops linting
if linters_from_ft == nil then return end
for _, name in ipairs(linters_from_ft) do
local linter = linters[name]
assert(linter, 'Linter with name `' .. name .. '` not available')
if type(linter) == "function" then
linter = linter()
end
-- for require("lint").lint() to work, linter.name must be set
linter.name = linter.name or name
local cwd = linter.required_files
-- if no configuration files are configured, lint
if cwd == nil then
require("lint").lint(linter)
else
-- if configuration files are configured and present in the project, lint
for _, fn in ipairs(cwd) do
local path = vim.fs.joinpath(linter.cwd or vim.fn.getcwd(), fn);
if vim.uv.fs_stat(path) then
require("lint").lint(linter)
break
end
end
end
end
end
'';
example = literalExpression ''
mkLuaInline '''
function(buf)
require("lint").try_lint()
end
'''
'';
description = "Define the global function nvf_lint which is used by nvf to lint.";
};
};
}

View file

@ -9,7 +9,6 @@
in {
config = mkIf cfg.enable {
vim = {
startPlugins = ["gitlinker-nvim"];
lazy.plugins = {
"gitlinker-nvim" = {
package = "gitlinker-nvim";

View file

@ -53,24 +53,20 @@
# TODO: specify packages
defaultDiagnosticsProvider = ["eslint_d"];
diagnosticsProviders = {
eslint_d = {
package = pkgs.eslint_d;
eslint_d = let
pkg = pkgs.eslint_d;
in {
package = pkg;
config = {
# HACK: change if nvim-lint gets a dynamic enable thing
parser = mkLuaInline ''
function(output, bufnr, cwd)
local markers = { "eslint.config.js", "eslint.config.mjs",
".eslintrc", ".eslintrc.json", ".eslintrc.js", ".eslintrc.yml", }
for _, filename in ipairs(markers) do
local path = vim.fs.join(cwd, filename)
if vim.loop.fs_stat(path) then
return require("lint.linters.eslint_d").parser(output, bufnr, cwd)
end
end
return {}
end
'';
cmd = getExe pkg;
required_files = [
"eslint.config.js"
"eslint.config.mjs"
".eslintrc"
".eslintrc.json"
".eslintrc.js"
".eslintrc.yml"
];
};
};
};
@ -153,16 +149,9 @@ in {
vim.diagnostics.nvim-lint = {
enable = true;
linters_by_ft.astro = cfg.extraDiagnostics.types;
linters = mkMerge (map (
name: {
${name} =
diagnosticsProviders.${name}.config
// {
cmd = getExe diagnosticsProviders.${name}.package;
};
}
)
cfg.extraDiagnostics.types);
linters =
mkMerge (map (name: {${name} = diagnosticsProviders.${name}.config;})
cfg.extraDiagnostics.types);
};
})
]);

View file

@ -13,7 +13,7 @@
inherit (lib.strings) optionalString;
inherit (lib.nvim.lua) expToLua;
inherit (lib.nvim.types) mkGrammarOption;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.dag) entryAfter;
cfg = config.vim.languages.dart;
ftcfg = cfg.flutter-tools;
@ -81,16 +81,25 @@ in {
description = "Enable flutter-tools for flutter support";
};
flutterPackage = mkOption {
type = nullOr package;
default = pkgs.flutter;
description = "Flutter package, or null to detect the flutter path at runtime instead.";
};
enableNoResolvePatch = mkOption {
type = bool;
default = true;
default = false;
description = ''
Whether to patch flutter-tools so that it doesn't resolve
symlinks when detecting flutter path.
This is required if you want to use a flutter package built with nix.
If you are using a flutter SDK installed from a different source
and encounter the error "`dart` missing from PATH", disable this option.
::: {.note}
This is required if `flutterPackage` is set to null and the flutter
package in your `PATH` was built with Nix. If you are using a flutter
SDK installed from a different source and encounter the error "`dart`
missing from `PATH`", leave this option disabled.
:::
'';
};
@ -122,25 +131,32 @@ in {
};
};
config = mkIf cfg.enable (mkMerge [
config.vim = mkIf cfg.enable (mkMerge [
(mkIf cfg.treesitter.enable {
vim.treesitter.enable = true;
vim.treesitter.grammars = [cfg.treesitter.package];
treesitter.enable = true;
treesitter.grammars = [cfg.treesitter.package];
})
(mkIf cfg.lsp.enable {
vim.lsp.lspconfig.enable = true;
vim.lsp.lspconfig.sources.dart-lsp = servers.${cfg.lsp.server}.lspConfig;
lsp.lspconfig.enable = true;
lsp.lspconfig.sources.dart-lsp = servers.${cfg.lsp.server}.lspConfig;
})
(mkIf ftcfg.enable {
vim.startPlugins =
if ftcfg.enableNoResolvePatch
then ["flutter-tools-patched"]
else ["flutter-tools-nvim"];
lsp.enable = true;
vim.pluginRC.flutter-tools = entryAnywhere ''
startPlugins = [
(
if ftcfg.enableNoResolvePatch
then "flutter-tools-patched"
else "flutter-tools-nvim"
)
"plenary-nvim"
];
pluginRC.flutter-tools = entryAfter ["lsp-setup"] ''
require('flutter-tools').setup {
${optionalString (ftcfg.flutterPackage != null) "flutter_path = \"${ftcfg.flutterPackage}/bin/flutter\","}
lsp = {
color = { -- show the derived colours for dart variables
enabled = ${boolToString ftcfg.color.enable}, -- whether or not to highlight color variables at all, only supported on flutter >= 2.10
@ -152,7 +168,6 @@ in {
capabilities = capabilities,
on_attach = default_on_attach;
flags = lsp_flags,
},
${optionalString cfg.dap.enable ''
debugger = {

View file

@ -5,7 +5,7 @@
...
}: let
inherit (builtins) attrNames;
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.options) mkEnableOption mkOption literalMD;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.meta) getExe;
inherit (lib.lists) isList;
@ -84,7 +84,14 @@ in {
};
format = {
enable = mkEnableOption "Go formatting" // {default = config.vim.languages.enableFormat;};
enable =
mkEnableOption "Go formatting"
// {
default = !cfg.lsp.enable && config.vim.languages.enableFormat;
defaultText = literalMD ''
disabled if Go LSP is enabled, otherwise follows {option}`vim.languages.enableFormat`
'';
};
type = mkOption {
description = "Go formatter to use";

View file

@ -9,7 +9,7 @@
inherit (lib.modules) mkIf mkMerge;
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.lists) isList;
inherit (lib.types) bool enum either package listOf str;
inherit (lib.types) bool enum either package listOf str nullOr;
inherit (lib.nvim.lua) expToLua toLuaObject;
inherit (lib.nvim.types) diagnostics mkGrammarOption mkPluginSetupOption;
inherit (lib.nvim.dag) entryAnywhere;
@ -117,7 +117,18 @@ in {
'';
};
setupOpts = mkPluginSetupOption "render-markdown" {};
setupOpts = mkPluginSetupOption "render-markdown" {
file_types = lib.mkOption {
type = nullOr (listOf str);
default = null;
description = ''
List of buffer filetypes to enable this plugin in.
This will cause the plugin to attach to new buffers who
have any of these filetypes.
'';
};
};
};
};

View file

@ -99,7 +99,7 @@
# idk if this is the best way to install/run debugpy
package = pkgs.python3.withPackages (ps: with ps; [debugpy]);
dapConfig = ''
dap.adapters.python = function(cb, config)
dap.adapters.debugpy = function(cb, config)
if config.request == 'attach' then
---@diagnostic disable-next-line: undefined-field
local port = (config.connect or config).port
@ -128,7 +128,7 @@
dap.configurations.python = {
{
-- The first three options are required by nvim-dap
type = 'python'; -- the type here established the link to the adapter definition: `dap.adapters.python`
type = 'debugpy'; -- the type here established the link to the adapter definition: `dap.adapters.debugpy`
request = 'launch';
name = "Launch file";

View file

@ -55,21 +55,14 @@
package = pkg;
config = {
cmd = getExe pkg;
# HACK: change if nvim-lint gets a dynamic enable thing
parser = mkLuaInline ''
function(output, bufnr, cwd)
local markers = { "eslint.config.js", "eslint.config.mjs",
".eslintrc", ".eslintrc.json", ".eslintrc.js", ".eslintrc.yml", }
for _, filename in ipairs(markers) do
local path = vim.fs.join(cwd, filename)
if vim.loop.fs_stat(path) then
return require("lint.linters.eslint_d").parser(output, bufnr, cwd)
end
end
return {}
end
'';
required_files = [
"eslint.config.js"
"eslint.config.mjs"
".eslintrc"
".eslintrc.json"
".eslintrc.js"
".eslintrc.yml"
];
};
};
};

View file

@ -91,27 +91,20 @@
# TODO: specify packages
defaultDiagnosticsProvider = ["eslint_d"];
diagnosticsProviders = {
eslint_d = {
package = pkgs.eslint_d;
config = let
pkg = pkgs.eslint_d;
in {
eslint_d = let
pkg = pkgs.eslint_d;
in {
package = pkg;
config = {
cmd = getExe pkg;
# HACK: change if nvim-lint gets a dynamic enable thing
parser = mkLuaInline ''
function(output, bufnr, cwd)
local markers = { "eslint.config.js", "eslint.config.mjs",
".eslintrc", ".eslintrc.json", ".eslintrc.js", ".eslintrc.yml", }
for _, filename in ipairs(markers) do
local path = vim.fs.join(cwd, filename)
if vim.loop.fs_stat(path) then
return require("lint.linters.eslint_d").parser(output, bufnr, cwd)
end
end
return {}
end
'';
required_files = [
"eslint.config.js"
"eslint.config.mjs"
".eslintrc"
".eslintrc.json"
".eslintrc.js"
".eslintrc.yml"
];
};
};
};
@ -221,10 +214,9 @@ in {
linters_by_ft.typescript = cfg.extraDiagnostics.types;
linters_by_ft.typescriptreact = cfg.extraDiagnostics.types;
linters = mkMerge (map (name: {
${name}.cmd = getExe diagnosticsProviders.${name}.package;
})
cfg.extraDiagnostics.types);
linters =
mkMerge (map (name: {${name} = diagnosticsProviders.${name}.config;})
cfg.extraDiagnostics.types);
};
})

View file

@ -0,0 +1,19 @@
{
config,
lib,
...
}: let
inherit (lib.modules) mkIf;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.lua) toLuaObject;
cfg = config.vim.mini.cursorword;
in {
vim = mkIf cfg.enable {
startPlugins = ["mini-cursorword"];
pluginRC.mini-ai = entryAnywhere ''
require("mini.cursorword").setup(${toLuaObject cfg.setupOpts})
'';
};
}

View file

@ -0,0 +1,9 @@
{lib, ...}: let
inherit (lib.options) mkEnableOption;
inherit (lib.nvim.types) mkPluginSetupOption;
in {
options.vim.mini.cursorword = {
enable = mkEnableOption "mini.cursorword";
setupOpts = mkPluginSetupOption "mini.cursorword" {};
};
}

View file

@ -0,0 +1,6 @@
{
imports = [
./cursorword.nix
./config.nix
];
}

View file

@ -11,6 +11,7 @@
./colors
./comment
./completion
./cursorword
./diff
./doc
./extra

View file

@ -18,6 +18,7 @@
./oil-nvim
./outline
./preview
./sleuth
./snacks-nvim
./surround
./telescope

View file

@ -0,0 +1,10 @@
{
config,
lib,
...
}: let
inherit (lib.modules) mkIf;
cfg = config.vim.utility.sleuth;
in {
vim.startPlugins = mkIf cfg.enable ["vim-sleuth"];
}

View file

@ -0,0 +1,6 @@
{
imports = [
./config.nix
./sleuth.nix
];
}

View file

@ -0,0 +1,7 @@
{lib, ...}: let
inherit (lib.options) mkEnableOption;
in {
options.vim.utility.sleuth.enable = mkEnableOption ''
automatically adjusting options such as `shiftwidth` or `expandtab`, using `vim-sleuth`
'';
}

View file

@ -5,7 +5,7 @@
}: let
inherit (builtins) map mapAttrs filter;
inherit (lib.attrsets) mapAttrsToList;
inherit (lib.strings) concatLines concatMapStringsSep;
inherit (lib.strings) concatLines concatMapStringsSep optionalString;
inherit (lib.trivial) showWarnings;
inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.dag) entryAfter mkLuarcSection resolveDag entryAnywhere;
@ -72,6 +72,14 @@ in {
dag = cfg.luaConfigRC;
mapResult = result:
concatLines [
(optionalString (cfg.additionalRuntimePaths != []) ''
vim.opt.runtimepath:append(${toLuaObject cfg.additionalRuntimePaths})
'')
(optionalString cfg.enableLuaLoader ''
if vim.loader then
vim.loader.enable()
end
'')
cfg.luaConfigPre
(concatMapStringsSep "\n" mkLuarcSection result)
cfg.luaConfigPost

View file

@ -1,15 +1,7 @@
{
config,
lib,
...
}: let
{lib, ...}: let
inherit (lib.options) mkOption literalMD literalExpression;
inherit (lib.strings) optionalString;
inherit (lib.types) str bool int enum attrsOf lines listOf either path submodule anything;
inherit (lib.nvim.types) dagOf;
inherit (lib.nvim.lua) listToLuaTable;
cfg = config.vim;
in {
options.vim = {
enableLuaLoader = mkOption {
@ -286,21 +278,7 @@ in {
luaConfigPre = mkOption {
type = str;
default = ''
${optionalString (cfg.additionalRuntimePaths != []) ''
-- The following list is generated from `vim.additionalRuntimePaths`
-- and is used to append additional runtime paths to the
-- `runtimepath` option.
vim.opt.runtimepath:append(${listToLuaTable cfg.additionalRuntimePaths})
''}
${optionalString cfg.enableLuaLoader ''
if vim.loader then
vim.loader.enable()
end
''}
'';
default = "";
defaultText = literalMD ''
By default, this option will **append** paths in
[](#opt-vim.additionalRuntimePaths)