From ead8b36786239646b2e481b54a07426239b47df0 Mon Sep 17 00:00:00 2001 From: Adam0 Date: Thu, 6 Aug 2026 22:11:58 -0400 Subject: [PATCH] Add Rust dyninput support --- modules/pkgs/default.nix | 1 + modules/pkgs/neovim/dyninput-nvim.nix | 33 ++++++++++ .../tui/neovim/components/autocomplete.nix | 6 ++ .../programs/tui/neovim/languages/rust.nix | 65 +++++++++++++++++-- 4 files changed, 101 insertions(+), 4 deletions(-) create mode 100644 modules/pkgs/neovim/dyninput-nvim.nix diff --git a/modules/pkgs/default.nix b/modules/pkgs/default.nix index 7d0aa85..a2283f3 100644 --- a/modules/pkgs/default.nix +++ b/modules/pkgs/default.nix @@ -11,6 +11,7 @@ dashboard-gh-notify dashboard-vcs-status djvutorga-adapter + dyninput-nvim gotify-optimize-images jj-conflict-nvim man-preview diff --git a/modules/pkgs/neovim/dyninput-nvim.nix b/modules/pkgs/neovim/dyninput-nvim.nix new file mode 100644 index 0000000..1ae7075 --- /dev/null +++ b/modules/pkgs/neovim/dyninput-nvim.nix @@ -0,0 +1,33 @@ +{ + perSystem = { + # keep-sorted start + lib, + pkgs, + # keep-sorted end + ... + }: let + inherit (pkgs) fetchFromGitHub; + inherit (pkgs.vimUtils) buildVimPlugin; + in { + packages.dyninput-nvim = buildVimPlugin { + pname = "dyninput.nvim"; + version = "0-unstable-2023-08-10"; + + src = fetchFromGitHub { + owner = "nvimdev"; + repo = "dyninput.nvim"; + rev = "2d5bef4c23d8da303556ac507416a1f9e6ea3a77"; + hash = "sha256-0jZ/hDGw58fp9G2HTcLETRh+vfQHwJBprIUxUc0gGrI="; + }; + + dependencies = [pkgs.vimPlugins.nvim-treesitter]; + + meta = with lib; { + description = "Context-aware character input for Neovim"; + homepage = "https://github.com/nvimdev/dyninput.nvim"; + license = licenses.mit; + platforms = platforms.all; + }; + }; + }; +} diff --git a/modules/programs/tui/neovim/components/autocomplete.nix b/modules/programs/tui/neovim/components/autocomplete.nix index 4a7789a..aa917ca 100644 --- a/modules/programs/tui/neovim/components/autocomplete.nix +++ b/modules/programs/tui/neovim/components/autocomplete.nix @@ -17,6 +17,12 @@ autopairs.nvim-autopairs.enable = true; snippets.luasnip.enable = true; + lazy.plugins."dyninput.nvim" = { + package = pkgs.dyninput-nvim; + setupModule = "dyninput"; + lazy = false; + }; + autocomplete.blink-cmp = { enable = true; friendly-snippets.enable = true; diff --git a/modules/programs/tui/neovim/languages/rust.nix b/modules/programs/tui/neovim/languages/rust.nix index 2fc7b85..137c378 100644 --- a/modules/programs/tui/neovim/languages/rust.nix +++ b/modules/programs/tui/neovim/languages/rust.nix @@ -1,5 +1,14 @@ { - flake.modules.homeManager.neovim = {pkgs, ...}: { + flake.modules.homeManager.neovim = { + # keep-sorted start + lib, + pkgs, + # keep-sorted end + ... + }: let + inherit (lib) getExe; + inherit (lib.generators) mkLuaInline; + in { programs.nvf.settings.vim = { languages.rust = { enable = true; @@ -15,9 +24,57 @@ }; }; - lsp.servers."rust-analyzer".settings."rust-analyzer".rustfmt.overrideCommand = [ - "${pkgs.rustfmt}/bin/rustfmt" - ]; + lazy.plugins."dyninput.nvim".setupOpts.rust = let + dyninputRule = language: rule: mkLuaInline "require('dyninput.lang.${language}').${rule}"; + + doubleColon = mkLuaInline '' + function(opt) + if require("dyninput.lang.rust").double_colon(opt) then + return true + end + + local line = vim.api.nvim_buf_get_text( + opt.buf, + opt.lnum - 1, + 0, + opt.lnum - 1, + opt.col, + {} + )[1] + + local segment = line:match("([%a_][%w_]*)$") + local prefix = segment and line:sub(1, #line - #segment) or "" + + if segment and ( + vim.tbl_contains({ "crate", "self", "Self", "super" }, segment) + or segment:match("^%u[%w_]+$") + or prefix:match("::%s*$") + or prefix:match("=%s*$") + or prefix:match("^%s*use%s+") + ) then + return true + end + + return false + end + ''; + in { + # keep-sorted start block=yes newline_separated=yes + "-" = [ + [" -> " (dyninputRule "rust" "thin_arrow")] + ["_" (dyninputRule "misc" "snake_case")] + ]; + + ":" = [ + ["::" doubleColon] + [": " (dyninputRule "rust" "single_colon")] + ]; + + "=" = [" => " (dyninputRule "rust" "fat_arrow")]; + # keep-sorted end + }; + + lsp.servers."rust-analyzer".settings."rust-analyzer".rustfmt.overrideCommand = [(getExe pkgs.rustfmt)]; }; }; } -- 2.51.2