Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,17 @@ repos:
files: ^(configs/|shell/)
stages: [pre-commit]

# The nvim config's Lua, each spec driven in a headless Neovim. A spec
# loads the plugins lazy installed, and passes saying SKIP on a machine
# where nvim has not started yet, so lazy installed none.
- id: nvim-specs
name: nvim specs (headless Neovim)
entry: task test:nvim
language: system
pass_filenames: false
files: ^(configs/common/\.config/nvim/|tests/nvim/)
stages: [pre-commit]

# Tests a broken run would satisfy: every assertion a negative claim about
# an external effect, with nothing pinning how the run ended. A command
# that died before reaching the write leaves exactly that state. An
Expand Down
8 changes: 8 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ tasks:
cmds:
- uv run pytest tests/e2e --docker {{.CLI_ARGS}}

# Each spec drives a clean headless Neovim against the config's own Lua and the
# plugins lazy installed, and exits non-zero on a failure. Every spec runs, so
# one run reports each that failed.
test:nvim:
desc: The nvim config's Lua specs, each in a headless Neovim
cmds:
- status=0; for spec in tests/nvim/*_spec.lua; do nvim --headless -u NONE -l "$spec" || status=1; done; exit $status

test:watch:
desc: Re-run the suite on file changes (requires entr)
cmds:
Expand Down
2 changes: 2 additions & 0 deletions configs/common/.config/nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ if not profiles.is_vscode then
require('core.autocmds')
-- Custom floating terminal (Space t t). VSCode has its own terminal.
require('core.floaterminal')
-- The pull request beside a diff prs opened. Nothing where prs did not start nvim.
require('core.pull-request-panel').setup()
require('lsp')
end
34 changes: 32 additions & 2 deletions configs/common/.config/nvim/lua/core/profiles.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-- Which plugins load, which is now only a question when Neovim is embedded in
-- VSCode through vscode-neovim. Everywhere else the whole set loads.
-- Which kind of Neovim this is, and which plugins load in it. Two kinds load
-- less than the whole set: one embedded in VSCode through vscode-neovim, and one
-- prs started to show a pull request's diff.
--
-- An allowlist rather than a blocklist, because the spec list is not fully
-- enumerable here: colorscheme-manager.lua synthesizes specs at startup by
Expand Down Expand Up @@ -29,13 +30,42 @@ local vscode_enabled = {
['typos'] = true,
}

-- prs starts nvim in a repo's checkout to show one pull request's diff, with
-- PRS_DIFF_DOCUMENT naming the pull request's markdown document and
-- PRS_DIFF_THREADS its review threads. Both are read once and cleared, so an
-- nvim started from this one, such as lazygit's editor, is an ordinary nvim.
local function taken(name)
local value = vim.env[name]
vim.env[name] = nil
if value == nil or value == '' then
return nil
end
return value
end

local document, threads = taken('PRS_DIFF_DOCUMENT'), taken('PRS_DIFF_THREADS')

---@type { document: string, threads: string? }?
M.pull_request_diff = document and { document = document, threads = threads } or nil

-- Each keeps state for the directory nvim started in, which in a pull request's
-- diff is the repo's own checkout.
local pull_request_diff_disabled = {
-- Saving at exit would replace the repo's session with the diff's buffers,
-- which are gone once nvim exits.
['auto-session'] = true,
}

--- Plugin condition function for lazy.nvim defaults.cond
---@param plugin LazyPlugin
---@return boolean
function M.plugin_enabled(plugin)
if M.is_vscode then
return vscode_enabled[plugin.name] == true
end
if M.pull_request_diff then
return not pull_request_diff_disabled[plugin.name]
end
return true
end

Expand Down
Loading
Loading