Refactor plugin layout, add AI autocomplete and direnv, update docs

This commit is contained in:
RingOfStorms (Joshua Bell) 2026-01-22 16:54:45 -06:00
parent 3517caecde
commit cc9a5dc0f5
20 changed files with 1195 additions and 414 deletions

View file

@ -1,111 +0,0 @@
return {
"hrsh7th/nvim-cmp",
event = "InsertEnter",
dependencies = {
-- Snippet Engine & its associated nvim-cmp source
{
"L3MON4D3/LuaSnip",
dependencies = {
{
"rafamadriz/friendly-snippets",
config = function()
require("luasnip.loaders.from_vscode").lazy_load()
end,
},
},
},
"saadparwaiz1/cmp_luasnip",
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
{
"zbirenbaum/copilot.lua",
cmd = "Copilot",
event = "InsertEnter",
opts = {
copilot_node_command = (NIX and NIX.nodejs_24_path and (NIX.nodejs_24_path .. "/bin/node")) or "node",
},
main = "copilot",
},
{ "zbirenbaum/copilot-cmp", opts = {}, main = "copilot_cmp" },
},
config = function()
-- See `:help cmp`
local cmp = require("cmp")
local luasnip = require("luasnip")
luasnip.config.setup({})
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
completion = { completeopt = "menu,menuone,noinsert" },
mapping = cmp.mapping.preset.insert({
-- Scroll the documentation window [b]ack / [f]orward
["<C-u>"] = cmp.mapping.scroll_docs(-4),
["<C-d>"] = cmp.mapping.scroll_docs(4),
["<C-e>"] = cmp.mapping.abort(),
["<esc>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.abort()
if cmp.get_active_entry() == nil then
-- TODO this is still being weird... if I go into active entry then back up and press esc it causes havoc
fallback()
end
else
fallback()
end
end),
-- ["<esc>"] = cmp.mapping.abort(),
-- Select the [n]ext item
["<C-j>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_locally_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { "i", "s" }),
-- Select the [p]revious item
["<C-k>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
["<C-y>"] = cmp.mapping.confirm({ select = true }),
["<C-c>"] = cmp.mapping.complete({}),
}),
sources = {
{
name = "copilot",
priority = 9,
-- keyword_length = 1,
-- filter = function(keyword)
-- -- Check if keyword length is some number and not just whitespace
-- if #keyword < 2 or keyword:match("^%s*$") then
-- return false
-- end
-- return true
-- end,
-- max_item_count = 3,
},
{ name = "nvim_lsp", priority = 8, max_item_count = 100 },
{ name = "luasnip", priority = 7, max_item_count = 5 },
-- This source provides file path completions, helping you to complete file paths in your code
{ name = "path", priority = 7, max_item_count = 3 },
-- This source provides completion items from the current buffer, meaning it suggests words that have already been typed in the same file.
{ name = "buffer", priority = 6, max_item_count = 5 },
-- Rust crates.io integration
{ name = "crates" },
},
})
end,
}

View file

@ -1,45 +0,0 @@
return {
"numToStr/Comment.nvim",
dependencies = {
{
-- This will auto change the commentstring option in files that could have varying
-- comment modes like in jsx/markdown/files with embedded languages
"JoosepAlviste/nvim-ts-context-commentstring",
init = function()
-- skip backwards compatibility routines and speed up loading
vim.g.skip_ts_context_commentstring_module = true
end,
config = function()
require("ts_context_commentstring").setup({})
end,
},
},
config = function()
require("Comment").setup({
pre_hook = function()
return vim.bo.commentstring
end,
mappings = {
basic = false,
extra = false,
},
})
vim.cmd("filetype plugin on")
end,
keys = {
{
"<leader>/",
"<Plug>(comment_toggle_linewise_visual)",
'<ESC><CMD>lua require("Comment.api").locked("toggle.linewise")(vim.fn.visualmode())<CR>',
mode = { "x" },
desc = "Toggle comments on selection",
},
{
"<leader>/",
"V<Plug>(comment_toggle_linewise_visual)",
'<ESC><CMD>lua require("Comment.api").locked("toggle.linewise")(vim.fn.visualmode())<CR>',
mode = { "n" },
desc = "Toggle comments on line",
},
},
}

View file

@ -0,0 +1,74 @@
-- Completion engine using nvim-cmp
-- Keeping nvim-cmp for now due to blink.cmp stability issues
return {
{
"hrsh7th/nvim-cmp",
event = "InsertEnter",
dependencies = {
"L3MON4D3/LuaSnip",
"saadparwaiz1/cmp_luasnip",
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"rafamadriz/friendly-snippets",
},
config = function()
local cmp = require("cmp")
local luasnip = require("luasnip")
-- Load snippets
require("luasnip.loaders.from_vscode").lazy_load()
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
completion = {
completeopt = "menu,menuone,noinsert",
},
mapping = cmp.mapping.preset.insert({
["<C-j>"] = cmp.mapping.select_next_item(),
["<C-k>"] = cmp.mapping.select_prev_item(),
["<C-y>"] = cmp.mapping.confirm({ select = true }),
["<C-c>"] = cmp.mapping.complete(),
["<C-u>"] = cmp.mapping.scroll_docs(-4),
["<C-d>"] = cmp.mapping.scroll_docs(4),
["<C-e>"] = cmp.mapping.abort(),
["<Esc>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.abort()
end
fallback() -- Still exit insert mode after aborting
end, { "i", "s" }),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp", priority = 8 },
{ name = "luasnip", priority = 7 },
{ name = "path", priority = 7 },
{ name = "buffer", priority = 6 },
}),
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
})
end,
},
-- LuaSnip for snippet expansion
{
"L3MON4D3/LuaSnip",
lazy = true,
build = (function()
if vim.fn.has("win32") == 1 or vim.fn.executable("make") == 0 then
return
end
return "make install_jsregexp"
end)(),
opts = {
history = true,
delete_check_events = "TextChanged",
},
},
}

View file

@ -0,0 +1,21 @@
-- trouble.nvim - Pretty diagnostics, references, and quickfix lists
return {
"folke/trouble.nvim",
cmd = "Trouble",
opts = {
focus = false,
auto_preview = true,
modes = {
symbols = {
win = { position = "right", width = 40 },
},
},
},
keys = {
{ "<leader>xx", "<cmd>Trouble diagnostics toggle<cr>", desc = "Diagnostics (Trouble)" },
{ "<leader>xX", "<cmd>Trouble diagnostics toggle filter.buf=0<cr>", desc = "Buffer Diagnostics (Trouble)" },
{ "<leader>xs", "<cmd>Trouble symbols toggle focus=false<cr>", desc = "Symbols (Trouble)" },
{ "<leader>xq", "<cmd>Trouble qflist toggle<cr>", desc = "Quickfix (Trouble)" },
{ "<leader>xl", "<cmd>Trouble loclist toggle<cr>", desc = "Location List (Trouble)" },
},
}

7
lua/plugins/direnv.lua Normal file
View file

@ -0,0 +1,7 @@
-- direnv.vim - Auto-load project environment variables
-- This enables project devShells to provide LSPs and tools automatically
return {
"direnv/direnv.vim",
lazy = false, -- Must load early before LSP
priority = 90,
}

12
lua/plugins/lazydev.lua Normal file
View file

@ -0,0 +1,12 @@
-- lazydev.nvim - Faster Lua/Neovim development
-- Replaces neodev.nvim (which is archived)
return {
"folke/lazydev.nvim",
ft = "lua",
opts = {
library = {
-- Load luv types when vim.uv is used
{ path = "${3rd}/luv/library", words = { "vim%.uv" } },
},
},
}

View file

@ -0,0 +1,61 @@
-- Local AI autocomplete using llama.vim
-- Supports sweep-next-edit-1.5B and other FIM-capable models via llama-server
--
-- Usage:
-- 1. Start llama-server with your model:
-- llama-server -m sweep-next-edit-Q8_0.gguf --port 8012 --fim-qwen-7b-default
-- 2. Neovim will auto-detect the server and enable completions
-- 3. Use Tab to accept, Shift-Tab for first line, Ctrl-F to toggle
-- 4. Toggle on/off with <leader>,a
-- Check if llama-server is running (sync, for cond check)
local function is_llama_server_running()
-- Quick sync check - only used at startup
local result = vim.system(
{ "curl", "-s", "-o", "/dev/null", "-w", "%{http_code}", "--connect-timeout", "0.5", "http://127.0.0.1:8012/health" },
{ text = true }
):wait()
return result.code == 0 and result.stdout and result.stdout:match("200")
end
-- Cache the server status at load time
local server_available = nil
return {
"ggml-org/llama.vim",
-- Only load if llama-server is running, or load lazily via command
cond = function()
if server_available == nil then
server_available = is_llama_server_running()
end
return server_available
end,
event = "InsertEnter",
init = function()
-- Default configuration
vim.g.llama_config = {
endpoint = "http://127.0.0.1:8012/infill",
auto_fim = true, -- Enable since we only load when server is available
show_info = 1,
-- Keymaps are handled by the plugin:
-- Tab - accept completion
-- Shift-Tab - accept first line only
-- Ctrl-F - toggle FIM manually
}
vim.notify("llama.vim: server detected, AI completions enabled", vim.log.levels.INFO)
end,
keys = {
{
"<leader>,a",
function()
-- Toggle auto_fim
if vim.g.llama_config then
vim.g.llama_config.auto_fim = not vim.g.llama_config.auto_fim
local status = vim.g.llama_config.auto_fim and "enabled" or "disabled"
vim.notify("llama.vim auto-complete " .. status, vim.log.levels.INFO)
end
end,
desc = "Toggle AI autocomplete (llama.vim)",
},
},
}

View file

@ -11,12 +11,12 @@ vim.g.rustaceanvim = {
return {
-- LSP helper plugins for various languages
{ "folke/neodev.nvim", event = { "BufRead *.lua", "BufRead *.vim" }, opts = {}, main = "neodev" },
-- lazydev.nvim handles Lua/Neovim development (configured in lazydev.lua)
-- { TODO come back to this, do I actually use any features provided here? I was losing out on rust-analyzer stuff when this was on and it was added below...
-- "mrcjkb/rustaceanvim",
-- -- uses ftplugins to enable itself lazily already
-- lazy = false,
-- },
-- }
-- TODO add some hotkeys for opening the popup menus on crates
{ "Saecki/crates.nvim", event = "BufRead Cargo.toml", tag = "stable", opts = {}, main = "crates" },
{
@ -31,7 +31,6 @@ return {
"neovim/nvim-lspconfig",
event = "BufEnter",
dependencies = {
{ "hrsh7th/nvim-cmp" },
{ "b0o/schemastore.nvim" },
-- Automatically install LSPs and related tools to stdpath for Neovim
{ "williamboman/mason.nvim", enabled = not NIX, config = true }, -- NOTE: Must be loaded before dependants
@ -71,6 +70,7 @@ return {
})
local capabilities = vim.lsp.protocol.make_client_capabilities()
-- Extend capabilities with cmp-nvim-lsp for better completion support
U.safeRequire("cmp_nvim_lsp", function(c)
capabilities = vim.tbl_deep_extend("force", capabilities, c.default_capabilities())
end)
@ -96,26 +96,18 @@ return {
completion = {
callSnippet = "Replace",
},
workspace = {
checkThirdParty = false,
library = {
vim.env.VIMRUNTIME,
vim.api.nvim_get_runtime_file("", true),
vim.fn.expand("$VIMRUNTIME/lua"),
vim.fn.expand("$VIMRUNTIME/lua/vim/lsp"),
},
telemetry = { enable = false },
diagnostics = {
globals = {
"vim",
"require",
"NIX",
"U",
-- Hammerspoon for macos
"hs",
},
-- lazydev.nvim handles workspace library configuration
diagnostics = {
globals = {
"vim",
"require",
"NIX",
"U",
-- Hammerspoon for macos
"hs",
},
},
telemetry = { enable = false },
},
},
},
@ -214,6 +206,52 @@ return {
pcall(vim.keymap.del, m.mode, m.lhs)
end
-- Smart LSP detection: notify user when LSP is missing for a filetype
-- This helps guide users to add LSPs to their project devShell
local expected_lsp_for_filetype = {
rust = { name = "rust-analyzer", binary = "rust-analyzer" },
typescript = { name = "ts_ls", binary = "typescript-language-server" },
typescriptreact = { name = "ts_ls", binary = "typescript-language-server" },
javascript = { name = "ts_ls", binary = "typescript-language-server" },
javascriptreact = { name = "ts_ls", binary = "typescript-language-server" },
python = { name = "pylsp", binary = "pylsp" },
go = { name = "gopls", binary = "gopls" },
svelte = { name = "svelte", binary = "svelteserver" },
css = { name = "cssls", binary = "vscode-css-language-server" },
html = { name = "html", binary = "vscode-html-language-server" },
json = { name = "jsonls", binary = "vscode-json-language-server" },
yaml = { name = "yamlls", binary = "yaml-language-server" },
toml = { name = "taplo", binary = "taplo" },
markdown = { name = "marksman", binary = "marksman" },
xml = { name = "lemminx", binary = "lemminx" },
-- lua and nix are always available from core deps
}
local lsp_warned = {}
vim.api.nvim_create_autocmd("FileType", {
group = vim.api.nvim_create_augroup("myconfig-lsp-detect", { clear = true }),
callback = function(args)
local ft = args.match
local expected = expected_lsp_for_filetype[ft]
if expected and not lsp_warned[ft] then
-- Check if the binary is available
if vim.fn.executable(expected.binary) ~= 1 then
lsp_warned[ft] = true
vim.defer_fn(function()
vim.notify(
string.format(
"LSP '%s' for %s not found.\nAdd '%s' to your project devShell.",
expected.name,
ft,
expected.binary
),
vim.log.levels.WARN
)
end, 500)
end
end
end,
})
if NIX then
local lsp_servers = vim.tbl_keys(servers or {})
for _, server_name in ipairs(lsp_servers) do

63
lua/plugins/mini.lua Normal file
View file

@ -0,0 +1,63 @@
-- mini.nvim - Collection of minimal, fast, and composable Lua modules
-- Replaces: vim-surround, Comment.nvim, nvim-ts-context-commentstring
return {
"echasnovski/mini.nvim",
event = "VeryLazy",
config = function()
-- Surround: Add/delete/replace surroundings (brackets, quotes, etc.)
-- Mappings: gsa (add), gsd (delete), gsr (replace), gsf (find), gsF (find_left)
require("mini.surround").setup({
mappings = {
add = "gsa", -- Add surrounding in Normal and Visual modes
delete = "gsd", -- Delete surrounding
replace = "gsr", -- Replace surrounding
find = "gsf", -- Find surrounding (to the right)
find_left = "gsF", -- Find surrounding (to the left)
highlight = "gsh", -- Highlight surrounding
update_n_lines = "gsn", -- Update `n_lines`
},
})
-- Comment: Smart commenting with treesitter support
-- gc{motion} in Normal, gc in Visual to toggle comments
require("mini.comment").setup({
-- Hooks for custom comment handling (e.g., JSX/TSX)
options = {
custom_commentstring = function()
-- Use treesitter commentstring if available
return require("ts_context_commentstring").calculate_commentstring() or vim.bo.commentstring
end,
},
})
-- Auto pairs: Automatically close brackets, quotes, etc.
require("mini.pairs").setup()
-- Enhanced text objects: Better text objects for quotes, brackets, etc.
-- Adds: aq/iq (quotes), ab/ib (brackets), af/if (function), etc.
require("mini.ai").setup()
-- Preserve <leader>/ for comment toggle (matches old Comment.nvim binding)
vim.keymap.set("n", "<leader>/", function()
return require("mini.comment").operator() .. "_"
end, { expr = true, desc = "Toggle comment on line" })
vim.keymap.set("x", "<leader>/", function()
return require("mini.comment").operator()
end, { expr = true, desc = "Toggle comment on selection" })
end,
dependencies = {
-- Keep ts-context-commentstring for JSX/TSX/embedded languages
{
"JoosepAlviste/nvim-ts-context-commentstring",
lazy = true,
init = function()
-- Skip backwards compatibility routines
vim.g.skip_ts_context_commentstring_module = true
end,
opts = {
enable_autocmd = false, -- mini.comment handles this
},
},
},
}

View file

@ -1,4 +0,0 @@
return {
"tpope/vim-surround",
event = "VeryLazy",
}

View file

@ -1,6 +1,8 @@
return {
"nvim-treesitter/nvim-treesitter",
dependencies = { "windwp/nvim-ts-autotag", "JoosepAlviste/nvim-ts-context-commentstring" },
dependencies = { "windwp/nvim-ts-autotag" },
lazy = false, -- nvim-treesitter does not support lazy-loading per docs
build = ":TSUpdate",
init = function()
U.cmd_executable("tree-sitter", {
[false] = function()
@ -8,48 +10,70 @@ return {
end,
})
end,
event = "BufRead",
cmd = {
"TSBufDisable",
"TSBufEnable",
"TSBufToggle",
"TSDisable",
"TSEnable",
"TSToggle",
"TSInstall",
"TSInstallInfo",
"TSInstallSync",
"TSModuleInfo",
"TSUninstall",
"TSUpdate",
"TSUpdateSync",
},
opts = function()
local nonNixOpts = {}
config = function()
-- New nvim-treesitter API (post-rewrite)
-- Setup is optional and only needed for non-default install directory
local ts = require("nvim-treesitter")
-- In nix mode, parsers are provided by the nix store, no installation needed
if not NIX then
nonNixOpts = {
ensure_installed = "all",
auto_install = true,
}
-- Install common parsers (async)
ts.install({
"bash",
"c",
"css",
"dockerfile",
"go",
"html",
"javascript",
"json",
"lua",
"markdown",
"markdown_inline",
"nix",
"python",
"rust",
"svelte",
"toml",
"tsx",
"typescript",
"vim",
"vimdoc",
"yaml",
})
end
return U.assign({
highlight = {
enable = true,
use_languagetree = true,
disable = function(lang, bufnr)
if lang == "sql" then
return true
end
return vim.api.nvim_buf_line_count(bufnr) > 4000
end,
additional_vim_regex_highlighting = false,
},
incremental_selection = { enable = true },
indent = { enable = true },
autotag = { enable = true },
}, nonNixOpts)
end,
config = function(_, opts)
require("nvim-treesitter.configs").setup(opts)
-- Enable treesitter highlighting for all filetypes
vim.api.nvim_create_autocmd("FileType", {
group = vim.api.nvim_create_augroup("myconfig-treesitter-highlight", { clear = true }),
callback = function(args)
local bufnr = args.buf
local ft = args.match
-- Skip large files
if vim.api.nvim_buf_line_count(bufnr) > 4000 then
return
end
-- Skip sql (often has issues)
if ft == "sql" then
return
end
-- Enable treesitter highlighting
pcall(vim.treesitter.start, bufnr)
end,
})
-- Enable treesitter-based folding
vim.api.nvim_create_autocmd("FileType", {
group = vim.api.nvim_create_augroup("myconfig-treesitter-fold", { clear = true }),
callback = function(args)
local win = vim.api.nvim_get_current_win()
vim.wo[win][0].foldexpr = "v:lua.vim.treesitter.foldexpr()"
vim.wo[win][0].foldmethod = "expr"
vim.wo[win][0].foldenable = false -- Start with folds open
end,
})
end,
}

View file

@ -22,6 +22,7 @@ return {
{ "<leader>l", group = "LSP" },
{ "<leader>lf", group = "LSP Find" },
{ "<leader>t", group = "Tabs" },
{ "<leader>x", group = "Trouble/Diagnostics" },
},
},
},

View file

@ -4,8 +4,8 @@ local function script_path()
end
-- Extract the directory name from the script path
local directory_name = script_path():match(".*/(.*)/")
for _, file in ipairs(vim.fn.readdir(script_path(), [[v:val =~ '\.lua$']])) do
if file ~= "init.lua" then
for _, file in ipairs(vim.fn.readdir(script_path())) do
if file ~= "init.lua" and file:match("%.lua$") then
local neighbor = string.sub(file, 0, -5)
require(directory_name .. "." .. neighbor)
end