hide diagnostics in netrw previews

This commit is contained in:
Ray Elliott 2026-10-28 18:45:54 +00:00
commit 6a5e785a9f
4 changed files with 10 additions and 0 deletions

1
LOG.md
View file

@ -216,6 +216,7 @@ Record every decision here with a short rationale. Append new entries; do not re
- 2026-10-28: Automated Phase 14 checks passed for file/directory transitions, manual close and reopen, all four file-open actions, tree expansion and collapse, rapid cursor movement, spaces, Unicode, symlinks, empty and unreadable directories, and the 200-entry cap. A PTY-backed launch on a directory confirmed Neovim 0.12 enters the configured netrw tree, so no special `filetype=directory` handling is required. Separate-tab, deleted-entry, and real SSH checks remain as interactive validation. - 2026-10-28: Automated Phase 14 checks passed for file/directory transitions, manual close and reopen, all four file-open actions, tree expansion and collapse, rapid cursor movement, spaces, Unicode, symlinks, empty and unreadable directories, and the 200-entry cap. A PTY-backed launch on a directory confirmed Neovim 0.12 enters the configured netrw tree, so no special `filetype=directory` handling is required. Separate-tab, deleted-entry, and real SSH checks remain as interactive validation.
- 2026-10-28: An isolated lifecycle rerun exposed netrw's focus hop into an existing preview window while replacing a directory summary through its native preview function. The extension now explicitly restores the netrw window after that call, preserving tree-focused `j`/`k` navigation. Leave cleanup waits 20 ms before checking the settled current window and ignores callbacks raised while the native preview call is active, then closes only after a real explorer exit. The transient re-entrancy guard is not preview-mode state, and the cleanup timer is released when the netrw buffer is wiped. - 2026-10-28: An isolated lifecycle rerun exposed netrw's focus hop into an existing preview window while replacing a directory summary through its native preview function. The extension now explicitly restores the netrw window after that call, preserving tree-focused `j`/`k` navigation. Leave cleanup waits 20 ms before checking the settled current window and ignores callbacks raised while the native preview call is active, then closes only after a real explorer exit. The transient re-entrancy guard is not preview-mode state, and the cleanup timer is released when the netrw buffer is wiped.
- 2026-10-28: Fixed a reproducible Neovim 0.12 Tree-sitter race during rapid cross-language netrw previews. Native `:pedit` unloads the previous preview buffer while its asynchronous parser may still be running, producing `TSNode:range()` errors. Preview-only file buffers are now kept loaded but unlisted for the rest of the Neovim session, with Tree-sitter highlighting suspended in favor of Vim syntax; avoiding parser detachment is necessary because delayed unloading reproduces the same race. Pre-existing buffer state is preserved, while entering a previewed file for real editing restores listed-buffer behavior and Tree-sitter immediately. An 80-step Markdown/Lua/JSON preview stress test, edit restoration check, retained-buffer check, and pre-existing-buffer check all pass. - 2026-10-28: Fixed a reproducible Neovim 0.12 Tree-sitter race during rapid cross-language netrw previews. Native `:pedit` unloads the previous preview buffer while its asynchronous parser may still be running, producing `TSNode:range()` errors. Preview-only file buffers are now kept loaded but unlisted for the rest of the Neovim session, with Tree-sitter highlighting suspended in favor of Vim syntax; avoiding parser detachment is necessary because delayed unloading reproduces the same race. Pre-existing buffer state is preserved, while entering a previewed file for real editing restores listed-buffer behavior and Tree-sitter immediately. An 80-step Markdown/Lua/JSON preview stress test, edit restoration check, retained-buffer check, and pre-existing-buffer check all pass.
- 2026-10-28: Disabled diagnostic rendering in netrw file preview buffers. The preview metadata records each buffer's prior diagnostic state and restores it when the file is opened for editing, keeping ephemeral previews quiet without overriding buffers where diagnostics were already disabled.
## Project-Local Configuration ## Project-Local Configuration

View file

@ -667,6 +667,7 @@ file 3.2K 2026-10-27 12:55 telescope.lua
- [x] Test spaces, Unicode, symlinks, unreadable entries, and large directories - [x] Test spaces, Unicode, symlinks, unreadable entries, and large directories
- [x] Test rapid cursor movement for flicker, stale timers, and excess filesystem work - [x] Test rapid cursor movement for flicker, stale timers, and excess filesystem work
- [x] Prevent Tree-sitter parser races during rapid cross-language file preview replacement and restore highlighting on edit - [x] Prevent Tree-sitter parser races during rapid cross-language file preview replacement and restore highlighting on edit
- [x] Hide diagnostics in file previews and restore their prior per-buffer state on edit
- [ ] Test the workflow in an actual SSH session - [ ] Test the workflow in an actual SSH session
- [ ] Confirm stock netrw remains understandable when this configuration is unavailable - [ ] Confirm stock netrw remains understandable when this configuration is unavailable

View file

@ -113,6 +113,7 @@ entries, and symbolic links are displayed without following them recursively.
File previews use Vim's syntax highlighting while Tree-sitter is suspended to File previews use Vim's syntax highlighting while Tree-sitter is suspended to
avoid asynchronous parser races during rapid replacement; normal Tree-sitter avoid asynchronous parser races during rapid replacement; normal Tree-sitter
highlighting resumes automatically when a previewed file is opened for editing. highlighting resumes automatically when a previewed file is opened for editing.
Diagnostics are hidden in previews and restored to their prior state on edit.
Preview-only file buffers remain loaded but unlisted until Neovim exits, avoiding Preview-only file buffers remain loaded but unlisted until Neovim exits, avoiding
the parser detachment that triggers this Neovim 0.12 race. the parser detachment that triggers this Neovim 0.12 race.

View file

@ -65,6 +65,7 @@ local function restore_preview_buffer(buf, for_editing)
vim.bo[buf].bufhidden = metadata.bufhidden vim.bo[buf].bufhidden = metadata.bufhidden
vim.bo[buf].buflisted = for_editing or metadata.buflisted vim.bo[buf].buflisted = for_editing or metadata.buflisted
vim.bo[buf].syntax = metadata.syntax vim.bo[buf].syntax = metadata.syntax
vim.diagnostic.enable(metadata.diagnostics_enabled, { bufnr = buf })
if metadata.treesitter_active then if metadata.treesitter_active then
pcall(vim.treesitter.start, buf) pcall(vim.treesitter.start, buf)
end end
@ -447,6 +448,7 @@ local function show_native_preview(state, entry)
bufhidden = vim.bo[existing_buf].bufhidden, bufhidden = vim.bo[existing_buf].bufhidden,
syntax = vim.bo[existing_buf].syntax, syntax = vim.bo[existing_buf].syntax,
treesitter_active = vim.treesitter.highlighter.active[existing_buf] ~= nil, treesitter_active = vim.treesitter.highlighter.active[existing_buf] ~= nil,
diagnostics_enabled = vim.diagnostic.is_enabled({ bufnr = existing_buf }),
} or nil } or nil
local ok, shown = pcall(native_preview, entry) local ok, shown = pcall(native_preview, entry)
@ -466,12 +468,17 @@ local function show_native_preview(state, entry)
and existing.loaded and existing.loaded
and existing.treesitter_active and existing.treesitter_active
or vim.treesitter.highlighter.active[preview_buf] ~= nil, or vim.treesitter.highlighter.active[preview_buf] ~= nil,
diagnostics_enabled = existing ~= nil
and existing.buf == preview_buf
and existing.diagnostics_enabled
or vim.diagnostic.is_enabled({ bufnr = preview_buf }),
} }
vim.bo[preview_buf].bufhidden = 'hide' vim.bo[preview_buf].bufhidden = 'hide'
vim.bo[preview_buf].buflisted = preview_buffers[preview_buf].buflisted vim.bo[preview_buf].buflisted = preview_buffers[preview_buf].buflisted
vim.b[preview_buf].netrw_live_preview_buffer = true vim.b[preview_buf].netrw_live_preview_buffer = true
pcall(vim.treesitter.stop, preview_buf) pcall(vim.treesitter.stop, preview_buf)
vim.diagnostic.enable(false, { bufnr = preview_buf })
local filetype = vim.bo[preview_buf].filetype local filetype = vim.bo[preview_buf].filetype
if filetype ~= '' then if filetype ~= '' then