From 9b0446c5f62c302893b42c0a7f3d2a514f50d89a Mon Sep 17 00:00:00 2001 From: Johannes Kresner Date: Thu, 5 Nov 2026 15:04:29 +0100 Subject: [PATCH] feat: initial commit - basic config according to spec --- .gitignore | 2 + after/ftplugin/go.lua | 4 ++ after/ftplugin/php.lua | 3 + after/ftplugin/python.lua | 3 + after/ftplugin/rust.lua | 3 + flake.nix | 9 +++ init.lua | 40 +++++++++++ lazy-lock.json | 38 +++++++++++ lsp/jsonls.lua | 7 ++ lsp/lua_ls.lua | 9 +++ lsp/rust_analyzer.lua | 5 ++ lsp/yamlls.lua | 10 +++ lua/core/autocmds.lua | 13 ++++ lua/core/bigfile.lua | 36 ++++++++++ lua/core/keymaps.lua | 16 +++++ lua/core/lsp.lua | 54 +++++++++++++++ lua/core/options.lua | 29 ++++++++ lua/plugins/ai.lua | 93 +++++++++++++++++++++++++ lua/plugins/colorscheme.lua | 34 ++++++++++ lua/plugins/completion.lua | 32 +++++++++ lua/plugins/dap.lua | 106 +++++++++++++++++++++++++++++ lua/plugins/editing.lua | 40 +++++++++++ lua/plugins/files.lua | 16 +++++ lua/plugins/format.lua | 51 ++++++++++++++ lua/plugins/git.lua | 24 +++++++ lua/plugins/lint.lua | 25 +++++++ lua/plugins/lsp.lua | 12 ++++ lua/plugins/markdown.lua | 8 +++ lua/plugins/picker.lua | 87 ++++++++++++++++++++++++ lua/plugins/statusline.lua | 46 +++++++++++++ lua/plugins/test.lua | 44 ++++++++++++ lua/plugins/treesitter.lua | 57 ++++++++++++++++ lua/plugins/whichkey.lua | 21 ++++++ nix/module.nix | 131 ++++++++++++++++++++++++++++++++++++ snippets/.gitkeep | 0 stylua.toml | 6 ++ 36 files changed, 1114 insertions(+) create mode 100644 .gitignore create mode 100644 after/ftplugin/go.lua create mode 100644 after/ftplugin/php.lua create mode 100644 after/ftplugin/python.lua create mode 100644 after/ftplugin/rust.lua create mode 100644 flake.nix create mode 100644 init.lua create mode 100644 lazy-lock.json create mode 100644 lsp/jsonls.lua create mode 100644 lsp/lua_ls.lua create mode 100644 lsp/rust_analyzer.lua create mode 100644 lsp/yamlls.lua create mode 100644 lua/core/autocmds.lua create mode 100644 lua/core/bigfile.lua create mode 100644 lua/core/keymaps.lua create mode 100644 lua/core/lsp.lua create mode 100644 lua/core/options.lua create mode 100644 lua/plugins/ai.lua create mode 100644 lua/plugins/colorscheme.lua create mode 100644 lua/plugins/completion.lua create mode 100644 lua/plugins/dap.lua create mode 100644 lua/plugins/editing.lua create mode 100644 lua/plugins/files.lua create mode 100644 lua/plugins/format.lua create mode 100644 lua/plugins/git.lua create mode 100644 lua/plugins/lint.lua create mode 100644 lua/plugins/lsp.lua create mode 100644 lua/plugins/markdown.lua create mode 100644 lua/plugins/picker.lua create mode 100644 lua/plugins/statusline.lua create mode 100644 lua/plugins/test.lua create mode 100644 lua/plugins/treesitter.lua create mode 100644 lua/plugins/whichkey.lua create mode 100644 nix/module.nix create mode 100644 snippets/.gitkeep create mode 100644 stylua.toml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..726d2d6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +result +.direnv diff --git a/after/ftplugin/go.lua b/after/ftplugin/go.lua new file mode 100644 index 0000000..9e6d4d4 --- /dev/null +++ b/after/ftplugin/go.lua @@ -0,0 +1,4 @@ +vim.bo.expandtab = false +vim.bo.shiftwidth = 4 +vim.bo.tabstop = 4 +vim.bo.softtabstop = 0 diff --git a/after/ftplugin/php.lua b/after/ftplugin/php.lua new file mode 100644 index 0000000..961646c --- /dev/null +++ b/after/ftplugin/php.lua @@ -0,0 +1,3 @@ +vim.bo.shiftwidth = 4 +vim.bo.tabstop = 4 +vim.bo.softtabstop = 4 diff --git a/after/ftplugin/python.lua b/after/ftplugin/python.lua new file mode 100644 index 0000000..961646c --- /dev/null +++ b/after/ftplugin/python.lua @@ -0,0 +1,3 @@ +vim.bo.shiftwidth = 4 +vim.bo.tabstop = 4 +vim.bo.softtabstop = 4 diff --git a/after/ftplugin/rust.lua b/after/ftplugin/rust.lua new file mode 100644 index 0000000..961646c --- /dev/null +++ b/after/ftplugin/rust.lua @@ -0,0 +1,3 @@ +vim.bo.shiftwidth = 4 +vim.bo.tabstop = 4 +vim.bo.softtabstop = 4 diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..d0be9be --- /dev/null +++ b/flake.nix @@ -0,0 +1,9 @@ +{ + description = "Neovim config: Nix provides binaries, Lua provides behaviour"; + + outputs = + { self }: + { + homeManagerModules.default = import ./nix/module.nix self; + }; +} diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..6175b67 --- /dev/null +++ b/init.lua @@ -0,0 +1,40 @@ +vim.loader.enable() + +vim.g.mapleader = " " +vim.g.maplocalleader = "\\" +vim.g.profile = vim.env.NVIM_PROFILE == "slim" and "slim" or "full" + +require("core.options") +require("core.keymaps") +require("core.autocmds") +require("core.bigfile") + +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not vim.uv.fs_stat(lazypath) then + local out = vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "--branch=stable", + "https://github.com/folke/lazy.nvim.git", + lazypath, + }) + if vim.v.shell_error ~= 0 then + vim.api.nvim_echo({ { "Failed to clone lazy.nvim:\n" .. out, "ErrorMsg" } }, true, {}) + return + end +end +vim.opt.rtp:prepend(lazypath) + +require("lazy").setup({ + spec = { { import = "plugins" } }, + install = { colorscheme = { "catppuccin" } }, + checker = { enabled = false }, + change_detection = { notify = false }, + rocks = { enabled = false }, + performance = { + rtp = { + disabled_plugins = { "gzip", "netrwPlugin", "tarPlugin", "tohtml", "tutor", "zipPlugin" }, + }, + }, +}) diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 0000000..b44a84e --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,38 @@ +{ + "SchemaStore.nvim": { "branch": "main", "commit": "4794bb7a4cf66b894f0029c3094b7936a8c0e8fe" }, + "blink.cmp": { "branch": "main", "commit": "78336bc89ee5365633bcf754d93df01678b5c08f" }, + "catppuccin": { "branch": "main", "commit": "edefef779ab08ce1a4a404713e3012b0d202bd35" }, + "conform.nvim": { "branch": "master", "commit": "016802de402556da54c36bd7359b441266b01cdd" }, + "fff.nvim": { "branch": "main", "commit": "b3b8cede0beb95272ebc2c72c648269f9c5228b3" }, + "friendly-snippets": { "branch": "main", "commit": "b2ea5c41a150ba72fb656eedb4ed0a86d138d945" }, + "gitsigns.nvim": { "branch": "main", "commit": "ef707fb93301a9b856f36eae4c8f56f5b988a794" }, + "kanagawa.nvim": { "branch": "master", "commit": "bb85e4bfc8d89b0e62c8fa53ccdd13d12e2f77b3" }, + "lazy.nvim": { "branch": "main", "commit": "306a05526ada86a7b30af95c5cc81ffba93fef97" }, + "mini.ai": { "branch": "main", "commit": "a4f5648dedf435e6306205135d1babb563b55d28" }, + "mini.pairs": { "branch": "main", "commit": "03eb1f0062a2cee5314d1ac3939246e4bb21352e" }, + "mini.statusline": { "branch": "main", "commit": "d7133a9a244a8d93ccee42ff37fb9499af5956fb" }, + "mini.surround": { "branch": "main", "commit": "5357f00aca51a3b43e7775901b1ad9699f8c2678" }, + "minuet-ai.nvim": { "branch": "main", "commit": "50bf63b031c0391e926fdf0b3d044d37846e6e34" }, + "neotest": { "branch": "master", "commit": "27bf921498043f7ecd821d6db68d05de244bbd02" }, + "neotest-golang": { "branch": "main", "commit": "65b2be63c3de00e6f15c05388ebdc8d603dbd727" }, + "neotest-jest": { "branch": "main", "commit": "0e7979d51301dfae5ef839d771bd28cf593fde3f" }, + "neotest-pest": { "branch": "main", "commit": "3388a5f00001303020ce885e18007ccd1835212c" }, + "neotest-phpunit": { "branch": "main", "commit": "40e53c4294726a16f34f1a383a94c570553c6d46" }, + "neotest-python": { "branch": "master", "commit": "1b56ca4ba51c6014f986d6548ee629bdc95589d1" }, + "neotest-rust": { "branch": "main", "commit": "2c9941d4a358839918fac21d20fc8fef0e1ad05f" }, + "neotest-vitest": { "branch": "main", "commit": "b0c265743c877058068dbc40d104ea5d40e6b257" }, + "nvim-dap": { "branch": "master", "commit": "cfa2d58f4537aca6ca83e2de1a0d9f1491121264" }, + "nvim-dap-ui": { "branch": "master", "commit": "cc9dd33aade7f20bae414d0cba163bc60d4d4b43" }, + "nvim-lint": { "branch": "master", "commit": "52107ce2076a27a285af781248e2c59bad817cd0" }, + "nvim-lspconfig": { "branch": "master", "commit": "cc404d425c7752f56b8eaa269107be44d888ea51" }, + "nvim-nio": { "branch": "master", "commit": "edcc181a875301dd21840189aa2f2f9ad69fc172" }, + "nvim-treesitter": { "branch": "main", "commit": "610734c5d3e59761d5f79318d120633374537fa5" }, + "nvim-treesitter-textobjects": { "branch": "main", "commit": "5c7b0263797dfd1bd6202f2b219f3b53a80b2187" }, + "oil.nvim": { "branch": "master", "commit": "d3733d933833a0e59b813ecec99341527adf0c28" }, + "plenary.nvim": { "branch": "master", "commit": "74b06c6c75e4eeb3108ec01852001636d85a932b" }, + "render-markdown.nvim": { "branch": "main", "commit": "8e8795368391036643b622875a6da6a51bcd33f4" }, + "sidekick.nvim": { "branch": "main", "commit": "3d80a47e6375f6d647c9695d3afea6fa1b3275df" }, + "snacks.nvim": { "branch": "main", "commit": "882c996cf28183f4d63640de0b4c02ec886d01f2" }, + "tokyonight.nvim": { "branch": "main", "commit": "cdc07ac78467a233fd62c493de29a17e0cf2b2b6" }, + "which-key.nvim": { "branch": "main", "commit": "3aab2147e74890957785941f0c1ad87d0a44c15a" } +} diff --git a/lsp/jsonls.lua b/lsp/jsonls.lua new file mode 100644 index 0000000..a83ce0d --- /dev/null +++ b/lsp/jsonls.lua @@ -0,0 +1,7 @@ +return { + before_init = function(_, config) + config.settings = vim.tbl_deep_extend("force", config.settings or {}, { + json = { schemas = require("schemastore").json.schemas(), validate = { enable = true } }, + }) + end, +} diff --git a/lsp/lua_ls.lua b/lsp/lua_ls.lua new file mode 100644 index 0000000..aee3856 --- /dev/null +++ b/lsp/lua_ls.lua @@ -0,0 +1,9 @@ +return { + settings = { + Lua = { + runtime = { version = "LuaJIT" }, + workspace = { checkThirdParty = false, library = { vim.env.VIMRUNTIME } }, + telemetry = { enable = false }, + }, + }, +} diff --git a/lsp/rust_analyzer.lua b/lsp/rust_analyzer.lua new file mode 100644 index 0000000..0a5eb8b --- /dev/null +++ b/lsp/rust_analyzer.lua @@ -0,0 +1,5 @@ +return { + settings = { + ["rust-analyzer"] = { check = { command = "clippy" } }, + }, +} diff --git a/lsp/yamlls.lua b/lsp/yamlls.lua new file mode 100644 index 0000000..049b66e --- /dev/null +++ b/lsp/yamlls.lua @@ -0,0 +1,10 @@ +return { + before_init = function(_, config) + config.settings = vim.tbl_deep_extend("force", config.settings or {}, { + yaml = { + schemaStore = { enable = false, url = "" }, -- SchemaStore.nvim supplies them + schemas = require("schemastore").yaml.schemas(), + }, + }) + end, +} diff --git a/lua/core/autocmds.lua b/lua/core/autocmds.lua new file mode 100644 index 0000000..64af0d4 --- /dev/null +++ b/lua/core/autocmds.lua @@ -0,0 +1,13 @@ +local group = vim.api.nvim_create_augroup("core.autocmds", { clear = true }) + +vim.api.nvim_create_autocmd("TextYankPost", { + group = group, + callback = function() + vim.hl.on_yank() + end, +}) + +vim.api.nvim_create_autocmd("VimResized", { + group = group, + command = "tabdo wincmd =", +}) diff --git a/lua/core/bigfile.lua b/lua/core/bigfile.lua new file mode 100644 index 0000000..a97d8e9 --- /dev/null +++ b/lua/core/bigfile.lua @@ -0,0 +1,36 @@ +-- Files above the limit get vim.b.bigfile = true. Treesitter, LSP, linting and +-- AI completion check that flag; syntax and folding are switched off here. +local M = {} + +M.limit = 1024 * 1024 + +local group = vim.api.nvim_create_augroup("core.bigfile", { clear = true }) + +vim.api.nvim_create_autocmd("BufReadPre", { + group = group, + callback = function(ev) + local stat = vim.uv.fs_stat(ev.match) + if stat and stat.size > M.limit then + vim.b[ev.buf].bigfile = true + end + end, +}) + +vim.api.nvim_create_autocmd("FileType", { + group = group, + callback = function(ev) + if not vim.b[ev.buf].bigfile then + return + end + vim.schedule(function() + if vim.api.nvim_buf_is_valid(ev.buf) then + vim.bo[ev.buf].syntax = "" + vim.api.nvim_buf_call(ev.buf, function() + vim.wo.foldmethod = "manual" + end) + end + end) + end, +}) + +return M diff --git a/lua/core/keymaps.lua b/lua/core/keymaps.lua new file mode 100644 index 0000000..214c017 --- /dev/null +++ b/lua/core/keymaps.lua @@ -0,0 +1,16 @@ +-- Plugin-independent maps. Plugin maps live in their spec's `keys`. +local map = vim.keymap.set + +map({ "n", "x" }, "y", '"+y', { desc = "Yank to system clipboard" }) +map({ "n", "x" }, "p", '"+p', { desc = "Paste from system clipboard" }) + +map("n", "bd", "bdelete", { desc = "Delete buffer" }) +map("n", "bo", "%bdelete|edit#|bdelete#", { desc = "Delete other buffers" }) + +map("n", "tw", function() + vim.wo.wrap = not vim.wo.wrap +end, { desc = "Toggle wrap" }) + +map("n", "tD", function() + vim.diagnostic.enable(not vim.diagnostic.is_enabled()) +end, { desc = "Toggle diagnostics" }) diff --git a/lua/core/lsp.lua b/lua/core/lsp.lua new file mode 100644 index 0000000..7187d9a --- /dev/null +++ b/lua/core/lsp.lua @@ -0,0 +1,54 @@ +-- Servers start through native vim.lsp.enable. nvim-lspconfig only supplies +-- defaults; overrides live in lsp/.lua. Called from plugins/lsp.lua. +local M = {} + +M.servers = { + "nixd", + "lua_ls", + "bashls", + "yamlls", + "jsonls", + "marksman", + "rust_analyzer", + "gopls", + "vtsls", + "eslint", + "basedpyright", + "ruff", + "intelephense", +} + +local function restart() + vim.cmd(vim.fn.exists(":lsp") == 2 and "lsp restart" or "LspRestart") +end + +function M.setup() + vim.api.nvim_create_autocmd("LspAttach", { + group = vim.api.nvim_create_augroup("core.lsp", { clear = true }), + callback = function(ev) + local client = vim.lsp.get_client_by_id(ev.data.client_id) + if not client then + return + end + if vim.b[ev.buf].bigfile then + vim.schedule(function() + vim.lsp.buf_detach_client(ev.buf, client.id) + end) + return + end + if client.name == "ruff" then + client.server_capabilities.hoverProvider = false -- basedpyright owns hover + end + + local function map(lhs, rhs, desc) + vim.keymap.set("n", lhs, rhs, { buffer = ev.buf, desc = desc }) + end + map("li", "checkhealth vim.lsp", "LSP info") + map("lr", restart, "Restart LSP servers") + end, + }) + + vim.lsp.enable(M.servers) +end + +return M diff --git a/lua/core/options.lua b/lua/core/options.lua new file mode 100644 index 0000000..e9a10a1 --- /dev/null +++ b/lua/core/options.lua @@ -0,0 +1,29 @@ +local o = vim.opt + +o.number = true +o.relativenumber = true +o.signcolumn = "yes" +o.termguicolors = true +o.showmode = false -- mini.statusline shows it + +o.expandtab = true +o.shiftwidth = 2 +o.tabstop = 2 +o.softtabstop = 2 + +o.undofile = true -- undodir defaults to stdpath("state")/undo +o.swapfile = false + +o.scrolloff = 8 +o.splitright = true +o.splitbelow = true +o.ignorecase = true +o.smartcase = true + +o.foldlevel = 99 -- treesitter sets foldexpr per buffer +o.updatetime = 250 + +-- Clipboard is not synced. Over SSH, "+ goes through OSC 52. +if vim.env.SSH_TTY then + vim.g.clipboard = "osc52" +end diff --git a/lua/plugins/ai.lua b/lua/plugins/ai.lua new file mode 100644 index 0000000..d247982 --- /dev/null +++ b/lua/plugins/ai.lua @@ -0,0 +1,93 @@ +-- Completion: minuet against a local llama-server, no cloud fallback. +-- Agent: sidekick hosts my own agent CLI in a terminal split. +local full = vim.g.profile == "full" +local endpoint = vim.env.MINUET_ENDPOINT or "http://127.0.0.1:8012" + +local function allowed(buf) + buf = buf or vim.api.nvim_get_current_buf() + local name = vim.api.nvim_buf_get_name(buf) + local base = vim.fs.basename(name) + return not ( + vim.b[buf].bigfile + or vim.bo[buf].filetype == "gitcommit" + or base:match("^%.env") + or name:match("/secrets/") + ) +end + +local function agent(fn, opts) + return function() + require("sidekick.cli")[fn](vim.tbl_extend("force", { name = "agent" }, opts or {})) + end +end + +return { + { + "milanglacier/minuet-ai.nvim", + cond = full, + lazy = true, -- loaded by blink.cmp + dependencies = { "nvim-lua/plenary.nvim" }, + keys = { + { "ta", "Minuet blink toggle", desc = "Toggle AI completion" }, + }, + opts = { + provider = "openai_fim_compatible", + n_completions = 1, + context_window = 4096, + throttle = 1000, + debounce = 400, + request_timeout = 3, + enable_predicates = { + function() + return allowed() + end, + }, + provider_options = { + openai_fim_compatible = { + name = "llama.cpp", + api_key = "TERM", -- llama-server needs no key; any set env var works + end_point = endpoint .. "/v1/completions", + model = "qwen2.5-coder:3b", + optional = { max_tokens = 56, top_p = 0.9 }, + template = { + prompt = function(before, after, _) + return "<|fim_prefix|>" .. before .. "<|fim_suffix|>" .. after .. "<|fim_middle|>" + end, + suffix = false, + }, + }, + }, + }, + }, + { + "folke/sidekick.nvim", + cond = full, + keys = { + { "", function() require("sidekick.cli").focus() end, desc = "Focus agent", mode = { "n", "t", "i", "x" } }, + { "aa", agent("toggle", { focus = true }), desc = "Toggle agent" }, + { "as", function() require("sidekick.cli").select() end, desc = "Select CLI session" }, + { "at", agent("send", { msg = "{this}" }), desc = "Send this", mode = { "n", "x" } }, + { "af", agent("send", { msg = "{file}" }), desc = "Send file" }, + { "av", agent("send", { msg = "{selection}" }), desc = "Send selection", mode = "x" }, + { "ap", agent("prompt"), desc = "Pick prompt", mode = { "n", "x" } }, + { "ad", function() require("sidekick.cli").close() end, desc = "Detach session" }, + }, + opts = { + nes = { enabled = false }, -- needs Copilot + cli = { + watch = true, + mux = { enabled = false }, + win = { layout = "right", split = { width = 80 } }, + tools = { + agent = { cmd = vim.split(vim.env.NVIM_AGENT_CMD or "agent", " ", { trimempty = true }) }, + }, + prompts = { + review = "Review the current git diff (run `git diff`) for bugs, risks and simplifications.", + explain = "Explain {this}", + fix = "Fix these diagnostics in {file}:\n{diagnostics}", + tests = "Write tests for {this}", + }, + }, + }, + }, +} diff --git a/lua/plugins/colorscheme.lua b/lua/plugins/colorscheme.lua new file mode 100644 index 0000000..bd1e417 --- /dev/null +++ b/lua/plugins/colorscheme.lua @@ -0,0 +1,34 @@ +-- All three installed; only the active one loads. lazy.nvim loads the others +-- on :colorscheme. +local schemes = { "catppuccin", "tokyonight", "kanagawa" } + +local function cycle() + local current = vim.g.colors_name or "" + local idx = 1 + for i, name in ipairs(schemes) do + if current:find("^" .. name) then + idx = i + end + end + local next = schemes[idx % #schemes + 1] + vim.cmd.colorscheme(next) + vim.notify("colorscheme: " .. next) +end + +return { + { + "catppuccin/nvim", + name = "catppuccin", + lazy = false, + priority = 1000, + init = function() + vim.keymap.set("n", "tc", cycle, { desc = "Cycle colorscheme" }) + end, + config = function() + require("catppuccin").setup({}) + vim.cmd.colorscheme("catppuccin") + end, + }, + { "folke/tokyonight.nvim", lazy = true }, + { "rebelot/kanagawa.nvim", lazy = true }, +} diff --git a/lua/plugins/completion.lua b/lua/plugins/completion.lua new file mode 100644 index 0000000..9d31c9b --- /dev/null +++ b/lua/plugins/completion.lua @@ -0,0 +1,32 @@ +return { + { + "saghen/blink.cmp", + version = "1.*", + cond = vim.g.profile == "full", + event = { "InsertEnter", "CmdlineEnter" }, + dependencies = { "rafamadriz/friendly-snippets", "milanglacier/minuet-ai.nvim" }, + opts = function() + return { + keymap = { + preset = "default", + [""] = require("minuet").make_blink_map(), + }, + snippets = { preset = "default" }, -- built-in vim.snippet + sources = { + default = { "lsp", "path", "snippets", "buffer", "minuet" }, + providers = { + minuet = { + name = "minuet", + module = "minuet.blink", + async = true, + timeout_ms = 3000, + score_offset = 50, + }, + }, + }, + completion = { trigger = { prefetch_on_insert = false } }, + fuzzy = { implementation = "prefer_rust" }, + } + end, + }, +} diff --git a/lua/plugins/dap.lua b/lua/plugins/dap.lua new file mode 100644 index 0000000..e002b99 --- /dev/null +++ b/lua/plugins/dap.lua @@ -0,0 +1,106 @@ +-- Adapter paths come from the home-manager module (NVIM_* variables). +local function setup_adapters(dap) + local env = vim.env + + -- Rust + dap.adapters.codelldb = { type = "executable", command = env.NVIM_CODELLDB or "codelldb" } + dap.configurations.rust = { + { + name = "Launch binary", + type = "codelldb", + request = "launch", + program = function() + return vim.fn.input("Binary: ", vim.fn.getcwd() .. "/target/debug/", "file") + end, + cwd = "${workspaceFolder}", + }, + } + + -- Go + dap.adapters.delve = { + type = "server", + port = "${port}", + executable = { command = "dlv", args = { "dap", "-l", "127.0.0.1:${port}" } }, + } + dap.configurations.go = { + { name = "Debug file", type = "delve", request = "launch", program = "${file}" }, + { name = "Debug package", type = "delve", request = "launch", program = "${fileDirname}" }, + { name = "Debug test", type = "delve", request = "launch", mode = "test", program = "${fileDirname}" }, + } + + -- TypeScript / JavaScript + dap.adapters["pwa-node"] = { + type = "server", + host = "127.0.0.1", + port = "${port}", + executable = { command = "js-debug", args = { "${port}", "127.0.0.1" } }, + } + local js = { + { name = "Launch file", type = "pwa-node", request = "launch", program = "${file}", cwd = "${workspaceFolder}" }, + { name = "Attach", type = "pwa-node", request = "attach", processId = require("dap.utils").pick_process }, + } + for _, ft in ipairs({ "javascript", "typescript", "javascriptreact", "typescriptreact" }) do + dap.configurations[ft] = js + end + + -- Python + dap.adapters.python = { + type = "executable", + command = env.NVIM_DEBUGPY_PYTHON or "python3", + args = { "-m", "debugpy.adapter" }, + } + dap.configurations.python = { + { + name = "Launch file", + type = "python", + request = "launch", + program = "${file}", + pythonPath = function() + local venv = env.VIRTUAL_ENV or (vim.fn.getcwd() .. "/.venv") + local py = venv .. "/bin/python" + return vim.fn.executable(py) == 1 and py or "python3" + end, + }, + } + + -- PHP (Xdebug) + dap.adapters.php = { + type = "executable", + command = env.NVIM_NODE or "node", + args = { env.NVIM_PHP_DEBUG }, + } + dap.configurations.php = { + { name = "Listen for Xdebug", type = "php", request = "launch", port = 9003 }, + } +end + +local function dap(fn) + return function() + require("dap")[fn]() + end +end + +return { + { + "mfussenegger/nvim-dap", + cond = vim.g.profile == "full", + dependencies = { "rcarriga/nvim-dap-ui", "nvim-neotest/nvim-nio" }, + keys = { + { "db", dap("toggle_breakpoint"), desc = "Toggle breakpoint" }, + { "dc", dap("continue"), desc = "Continue" }, + { "di", dap("step_into"), desc = "Step into" }, + { "do", dap("step_over"), desc = "Step over" }, + { "dO", dap("step_out"), desc = "Step out" }, + { "dq", dap("terminate"), desc = "Terminate" }, + { "du", function() require("dapui").toggle() end, desc = "Toggle debug UI" }, + }, + config = function() + local d, ui = require("dap"), require("dapui") + ui.setup() + d.listeners.after.event_initialized.dapui = ui.open + d.listeners.before.event_terminated.dapui = ui.close + d.listeners.before.event_exited.dapui = ui.close + setup_adapters(d) + end, + }, +} diff --git a/lua/plugins/editing.lua b/lua/plugins/editing.lua new file mode 100644 index 0000000..d07e28d --- /dev/null +++ b/lua/plugins/editing.lua @@ -0,0 +1,40 @@ +return { + { + "nvim-mini/mini.ai", + event = "VeryLazy", + dependencies = { "nvim-treesitter/nvim-treesitter-textobjects" }, + config = function() + local ai = require("mini.ai") + ai.setup({ + n_lines = 500, + custom_textobjects = { + f = ai.gen_spec.treesitter({ a = "@function.outer", i = "@function.inner" }), + c = ai.gen_spec.treesitter({ a = "@class.outer", i = "@class.inner" }), + }, + -- No bracket motions (QWERTZ). + mappings = { goto_left = "", goto_right = "" }, + }) + end, + }, + { + "nvim-mini/mini.surround", + event = "VeryLazy", + -- gz prefix so the built-in `s` stays untouched. + opts = { + mappings = { + add = "gza", + delete = "gzd", + find = "gzf", + find_left = "gzF", + highlight = "gzh", + replace = "gzr", + update_n_lines = "gzn", + }, + }, + }, + { + "nvim-mini/mini.pairs", + event = "InsertEnter", + opts = {}, + }, +} diff --git a/lua/plugins/files.lua b/lua/plugins/files.lua new file mode 100644 index 0000000..a276723 --- /dev/null +++ b/lua/plugins/files.lua @@ -0,0 +1,16 @@ +return { + { + "stevearc/oil.nvim", + cmd = "Oil", + keys = { { "-", "Oil", desc = "Open parent directory" } }, + init = function() + -- Load at startup only when nvim was opened on a directory. + local arg = vim.fn.argc() == 1 and vim.fn.argv(0) + local stat = arg and vim.uv.fs_stat(arg) + if stat and stat.type == "directory" then + require("lazy").load({ plugins = { "oil.nvim" } }) + end + end, + opts = { default_file_explorer = true }, + }, +} diff --git a/lua/plugins/format.lua b/lua/plugins/format.lua new file mode 100644 index 0000000..be91fb6 --- /dev/null +++ b/lua/plugins/format.lua @@ -0,0 +1,51 @@ +return { + { + "stevearc/conform.nvim", + cond = vim.g.profile == "full", + event = "BufWritePre", + cmd = "ConformInfo", + keys = { + { + "lf", + function() + require("conform").format({ async = true, lsp_format = "fallback" }) + end, + desc = "Format buffer", + }, + { + "tF", + function() + vim.b.disable_autoformat = not vim.b.disable_autoformat + vim.notify("format on save: " .. (vim.b.disable_autoformat and "off" or "on")) + end, + desc = "Toggle format on save (buffer)", + }, + }, + opts = { + formatters_by_ft = { + nix = { "nixfmt" }, + lua = { "stylua" }, + sh = { "shfmt" }, + bash = { "shfmt" }, + yaml = { "prettierd" }, + json = { "prettierd" }, + jsonc = { "prettierd" }, + markdown = { "prettierd" }, + rust = { "rustfmt" }, + go = { "goimports", "gofumpt" }, + javascript = { "prettierd" }, + javascriptreact = { "prettierd" }, + typescript = { "prettierd" }, + typescriptreact = { "prettierd" }, + python = { "ruff_format" }, + php = { "php_cs_fixer" }, + }, + format_on_save = function(buf) + if vim.b[buf].disable_autoformat or vim.b[buf].bigfile then + return + end + return { timeout_ms = 1000, lsp_format = "fallback" } + end, + }, + }, +} diff --git a/lua/plugins/git.lua b/lua/plugins/git.lua new file mode 100644 index 0000000..aaaccc1 --- /dev/null +++ b/lua/plugins/git.lua @@ -0,0 +1,24 @@ +return { + { + "lewis6991/gitsigns.nvim", + event = { "BufReadPre", "BufNewFile" }, + opts = { + on_attach = function(buf) + local gs = require("gitsigns") + local function map(mode, lhs, rhs, desc) + vim.keymap.set(mode, lhs, rhs, { buffer = buf, desc = desc }) + end + map("n", "gs", gs.stage_hunk, "Stage hunk") + map("n", "gr", gs.reset_hunk, "Reset hunk") + map("x", "gs", function() + gs.stage_hunk({ vim.fn.line("."), vim.fn.line("v") }) + end, "Stage selection") + map("x", "gr", function() + gs.reset_hunk({ vim.fn.line("."), vim.fn.line("v") }) + end, "Reset selection") + map("n", "gb", gs.blame_line, "Blame line") + map("n", "gp", gs.preview_hunk, "Preview hunk") + end, + }, + }, +} diff --git a/lua/plugins/lint.lua b/lua/plugins/lint.lua new file mode 100644 index 0000000..3a2f7f3 --- /dev/null +++ b/lua/plugins/lint.lua @@ -0,0 +1,25 @@ +-- Only linters that don't run as an LSP. +return { + { + "mfussenegger/nvim-lint", + cond = vim.g.profile == "full", + event = { "BufReadPost", "BufNewFile", "BufWritePost" }, + config = function() + local lint = require("lint") + lint.linters_by_ft = { go = { "golangcilint" } } + + vim.api.nvim_create_autocmd({ "BufReadPost", "BufWritePost", "InsertLeave" }, { + group = vim.api.nvim_create_augroup("plugins.lint", { clear = true }), + callback = function(ev) + if vim.b[ev.buf].bigfile then + return + end + lint.try_lint() + if vim.bo[ev.buf].filetype == "php" and vim.fs.root(ev.buf, "phpstan.neon") then + lint.try_lint("phpstan") + end + end, + }) + end, + }, +} diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua new file mode 100644 index 0000000..dc50261 --- /dev/null +++ b/lua/plugins/lsp.lua @@ -0,0 +1,12 @@ +return { + { + "neovim/nvim-lspconfig", + cond = vim.g.profile == "full", + event = { "BufReadPre", "BufNewFile" }, + dependencies = { "b0o/SchemaStore.nvim" }, + config = function() + require("core.lsp").setup() + end, + }, + { "b0o/SchemaStore.nvim", lazy = true }, +} diff --git a/lua/plugins/markdown.lua b/lua/plugins/markdown.lua new file mode 100644 index 0000000..82bf366 --- /dev/null +++ b/lua/plugins/markdown.lua @@ -0,0 +1,8 @@ +return { + { + "MeanderingProgrammer/render-markdown.nvim", + cond = vim.g.profile == "full", + ft = "markdown", + opts = {}, + }, +} diff --git a/lua/plugins/picker.lua b/lua/plugins/picker.lua new file mode 100644 index 0000000..88a4a88 --- /dev/null +++ b/lua/plugins/picker.lua @@ -0,0 +1,87 @@ +-- snacks.nvim: only picker, lazygit, terminal and image are used. +-- fff handles files and grep in the full profile; if its native library was +-- not built (or in slim), those maps fall back to snacks.picker. +local full = vim.g.profile == "full" + +local fff_built +local function use_fff() + if fff_built == nil then + fff_built = false + local plugin = full and require("lazy.core.config").plugins["fff.nvim"] + if plugin then + local ext = jit.os == "OSX" and "dylib" or "so" + fff_built = vim.uv.fs_stat(plugin.dir .. "/target/release/libfff_nvim." .. ext) ~= nil + end + end + return fff_built +end + +local function files() + if use_fff() then + require("fff").find_files() + else + Snacks.picker.files() + end +end + +local function grep() + if use_fff() then + require("fff").live_grep() + else + Snacks.picker.grep() + end +end + +local keys = { + { "ff", files, desc = "Find files" }, + { "fg", grep, desc = "Live grep" }, + { "fw", function() Snacks.picker.grep_word() end, desc = "Grep word under cursor", mode = { "n", "x" } }, + { "fb", function() Snacks.picker.buffers() end, desc = "Buffers" }, + { "fh", function() Snacks.picker.help() end, desc = "Help" }, + { "fk", function() Snacks.picker.keymaps() end, desc = "Keymaps" }, + { "fd", function() Snacks.picker.diagnostics() end, desc = "Diagnostics" }, + { "", function() Snacks.terminal.toggle(nil, { win = { position = "float" } }) end, desc = "Toggle terminal", mode = { "n", "t" } }, + { "", function() Snacks.terminal.toggle(nil, { win = { position = "float" } }) end, desc = "which_key_ignore", mode = { "n", "t" } }, +} +if full then + table.insert(keys, { "fs", function() Snacks.picker.lsp_workspace_symbols() end, desc = "Workspace symbols" }) +end +if vim.fn.executable("lazygit") == 1 then + table.insert(keys, { "gg", function() Snacks.lazygit() end, desc = "Lazygit" }) +end + +local picker = {} +if full then + -- sends selected files or grep hits to the running agent. + picker = { + actions = { + sidekick_send = function(...) + return require("sidekick.cli.picker.snacks").send(...) + end, + }, + win = { input = { keys = { [""] = { "sidekick_send", mode = { "n", "i" } } } } }, + } +end + +return { + { + "folke/snacks.nvim", + lazy = false, + priority = 1000, + keys = keys, + opts = { + picker = picker, + lazygit = {}, + terminal = {}, + image = { enabled = full }, + }, + }, + { + "dmtrKovalenko/fff.nvim", + cond = full, + lazy = true, + -- Only the Lua library; the workspace also has bins that fail to link. + build = "cargo build --release -p fff-nvim --lib", + opts = {}, + }, +} diff --git a/lua/plugins/statusline.lua b/lua/plugins/statusline.lua new file mode 100644 index 0000000..f2585f7 --- /dev/null +++ b/lua/plugins/statusline.lua @@ -0,0 +1,46 @@ +local function lsp_names() + local names = vim.tbl_map(function(c) + return c.name + end, vim.lsp.get_clients({ bufnr = 0 })) + return table.concat(names, ",") +end + +local function agent_marker() + if not package.loaded["sidekick"] then + return "" + end + local ok, sessions = pcall(function() + return require("sidekick.status").cli() + end) + return (ok and sessions and #sessions > 0) and "agent" or "" +end + +return { + { + "nvim-mini/mini.statusline", + lazy = false, + config = function() + local sl = require("mini.statusline") + sl.setup({ + content = { + active = function() + local mode, mode_hl = sl.section_mode({ trunc_width = 120 }) + local git = sl.section_git({ trunc_width = 40 }) + local diagnostics = sl.section_diagnostics({ trunc_width = 75 }) + local filename = sl.section_filename({ trunc_width = 140 }) + local location = sl.section_location({ trunc_width = 75 }) + return sl.combine_groups({ + { hl = mode_hl, strings = { mode } }, + { hl = "MiniStatuslineDevinfo", strings = { git, diagnostics } }, + "%<", + { hl = "MiniStatuslineFilename", strings = { filename } }, + "%=", + { hl = "MiniStatuslineFileinfo", strings = { agent_marker(), lsp_names() } }, + { hl = mode_hl, strings = { location } }, + }) + end, + }, + }) + end, + }, +} diff --git a/lua/plugins/test.lua b/lua/plugins/test.lua new file mode 100644 index 0000000..f6aa827 --- /dev/null +++ b/lua/plugins/test.lua @@ -0,0 +1,44 @@ +local function nt(fn) + return function() + fn(require("neotest")) + end +end + +return { + { + "nvim-neotest/neotest", + cond = vim.g.profile == "full", + dependencies = { + "nvim-neotest/nvim-nio", + "nvim-lua/plenary.nvim", + "nvim-treesitter/nvim-treesitter", + "rouge8/neotest-rust", + "fredrikaverpil/neotest-golang", + "marilari88/neotest-vitest", + "nvim-neotest/neotest-jest", + "nvim-neotest/neotest-python", + "V13Axel/neotest-pest", + "olimorris/neotest-phpunit", + }, + keys = { + { "tt", nt(function(n) n.run.run() end), desc = "Run nearest test" }, + { "tf", nt(function(n) n.run.run(vim.fn.expand("%")) end), desc = "Run test file" }, + { "ts", nt(function(n) n.summary.toggle() end), desc = "Test summary" }, + { "to", nt(function(n) n.output.open({ enter = true }) end), desc = "Test output" }, + { "td", nt(function(n) n.run.run({ strategy = "dap" }) end), desc = "Debug nearest test" }, + }, + config = function() + require("neotest").setup({ + adapters = { + require("neotest-rust"), + require("neotest-golang")({}), + require("neotest-vitest"), + require("neotest-jest")({}), + require("neotest-python")({ dap = { justMyCode = false } }), + require("neotest-pest"), + require("neotest-phpunit"), + }, + }) + end, + }, +} diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua new file mode 100644 index 0000000..9462491 --- /dev/null +++ b/lua/plugins/treesitter.lua @@ -0,0 +1,57 @@ +-- nvim-treesitter (main branch) only installs parsers. Highlighting, folds and +-- indent are started natively per buffer. +local parsers = { + slim = { "lua", "nix", "bash", "yaml", "json", "markdown" }, + full = { + "lua", + "vim", + "vimdoc", + "query", + "nix", + "bash", + "yaml", + "json", + "toml", + "markdown", + "markdown_inline", + "rust", + "go", + "gomod", + "typescript", + "tsx", + "javascript", + "python", + "php", + "html", + "css", + "dockerfile", + "gitcommit", + "diff", + }, +} + +return { + { + "nvim-treesitter/nvim-treesitter", + branch = "main", + lazy = false, -- main branch does not support lazy loading + build = ":TSUpdate", + config = function() + require("nvim-treesitter").install(parsers[vim.g.profile]) + + vim.api.nvim_create_autocmd("FileType", { + group = vim.api.nvim_create_augroup("plugins.treesitter", { clear = true }), + callback = function(ev) + if vim.b[ev.buf].bigfile or not pcall(vim.treesitter.start, ev.buf) then + return + end + vim.bo[ev.buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" + vim.wo.foldmethod = "expr" + vim.wo.foldexpr = "v:lua.vim.treesitter.foldexpr()" + end, + }) + end, + }, + -- Supplies @function/@class queries; mini.ai builds the text objects. + { "nvim-treesitter/nvim-treesitter-textobjects", branch = "main", lazy = true }, +} diff --git a/lua/plugins/whichkey.lua b/lua/plugins/whichkey.lua new file mode 100644 index 0000000..b4d89af --- /dev/null +++ b/lua/plugins/whichkey.lua @@ -0,0 +1,21 @@ +local groups = { + { "f", group = "Find" }, + { "g", group = "Git" }, + { "t", group = "Test and toggles" }, + { "b", group = "Buffers" }, +} +if vim.g.profile == "full" then + vim.list_extend(groups, { + { "l", group = "LSP" }, + { "d", group = "Debug" }, + { "a", group = "AI agent" }, + }) +end + +return { + { + "folke/which-key.nvim", + event = "VeryLazy", + opts = { spec = groups }, + }, +} diff --git a/nix/module.nix b/nix/module.nix new file mode 100644 index 0000000..4e099ec --- /dev/null +++ b/nix/module.nix @@ -0,0 +1,131 @@ +src: +{ + config, + lib, + pkgs, + ... +}: +let + cfg = config.programs.nvim-config; + full = cfg.profile == "full"; + + # Slim also needs tree-sitter and a C compiler so its few parsers can compile. + baseTools = with pkgs; [ + ripgrep + fd + git + tree-sitter + stdenv.cc + ]; + + # rustup supplies cargo, rustfmt, clippy and rust-analyzer (and the nightly + # toolchain fff builds with), so those are not listed separately. + fullTools = with pkgs; [ + lazygit + rustup + cargo-nextest + llama-cpp + + nixd + nixfmt + lua-language-server + stylua + bash-language-server + shfmt + shellcheck + yaml-language-server + vscode-langservers-extracted + marksman + prettierd + + go + gopls + gotools + gofumpt + golangci-lint + delve + + vtsls + vscode-js-debug + + basedpyright + ruff + + intelephense # unfree: the host must allow it + phpPackages.php-cs-fixer + phpPackages.phpstan + ]; + + # Kept out of home.packages to avoid colliding with other pythons/nodes. + debugpy = pkgs.python3.withPackages (ps: [ ps.debugpy ]); + lldb = pkgs.vscode-extensions.vadimcn.vscode-lldb; + phpDebug = pkgs.vscode-extensions.xdebug.php-debug; +in +{ + options.programs.nvim-config = { + enable = lib.mkEnableOption "the nvim-config Neovim setup"; + + profile = lib.mkOption { + type = lib.types.enum [ + "full" + "slim" + ]; + default = "full"; + description = "full for dev machines, slim for servers."; + }; + + checkout = lib.mkOption { + type = lib.types.nullOr lib.types.str; + default = null; + example = "/Users/johannes/Repos/nvim"; + description = '' + Absolute path to a local checkout. When set, ~/.config/nvim links to it + out of store so edits apply without a switch. When null, it links to + the flake source in the Nix store. + ''; + }; + + minuetEndpoint = lib.mkOption { + type = lib.types.str; + default = "http://127.0.0.1:8012"; + description = "Base URL of the llama-server used for AI completion."; + }; + + agent = { + command = lib.mkOption { + type = lib.types.str; + default = "agent"; + description = "Command sidekick.nvim runs for the agent tool."; + }; + package = lib.mkOption { + type = lib.types.nullOr lib.types.package; + default = null; + description = "Package providing the agent binary."; + }; + }; + }; + + config = lib.mkIf cfg.enable { + home.packages = [ + pkgs.neovim + ] + ++ baseTools + ++ lib.optionals full fullTools + ++ lib.optional (full && cfg.agent.package != null) cfg.agent.package; + + home.sessionVariables = { + NVIM_PROFILE = cfg.profile; + } + // lib.optionalAttrs full { + MINUET_ENDPOINT = cfg.minuetEndpoint; + NVIM_AGENT_CMD = cfg.agent.command; + NVIM_CODELLDB = "${lldb}/share/vscode/extensions/vadimcn.vscode-lldb/adapter/codelldb"; + NVIM_DEBUGPY_PYTHON = "${debugpy}/bin/python3"; + NVIM_PHP_DEBUG = "${phpDebug}/share/vscode/extensions/xdebug.php-debug/out/phpDebug.js"; + NVIM_NODE = "${pkgs.nodejs}/bin/node"; + }; + + xdg.configFile."nvim".source = + if cfg.checkout != null then config.lib.file.mkOutOfStoreSymlink cfg.checkout else src; + }; +} diff --git a/snippets/.gitkeep b/snippets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/stylua.toml b/stylua.toml new file mode 100644 index 0000000..6090f42 --- /dev/null +++ b/stylua.toml @@ -0,0 +1,6 @@ +column_width = 120 +line_endings = "Unix" +indent_type = "Spaces" +indent_width = 2 +quote_style = "AutoPreferDouble" +call_parentheses = "Always"