remove decoration from netrw previews

This commit is contained in:
Ray Elliott 2026-10-28 18:48:13 +00:00
commit 44385e1b3d
4 changed files with 33 additions and 9 deletions

1
LOG.md
View file

@ -217,6 +217,7 @@ Record every decision here with a short rationale. Append new entries; do not re
- 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: 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.
- 2026-10-28: Made netrw file previews intentionally plain after CSS and HTML exposed residual colour. The remaining decoration was Vim regex syntax plus indent-blankline extmarks, not diagnostics or Tree-sitter. Preview buffers now clear `syntax` and disable their buffer-local indent guides, then restore both recorded states on real edit.
## Project-Local Configuration

View file

@ -668,6 +668,7 @@ file 3.2K 2026-10-27 12:55 telescope.lua
- [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] Hide diagnostics in file previews and restore their prior per-buffer state on edit
- [x] Suppress remaining Vim syntax and indent-guide decoration in file previews, restoring prior state on edit
- [ ] Test the workflow in an actual SSH session
- [ ] Confirm stock netrw remains understandable when this configuration is unavailable

View file

@ -110,10 +110,10 @@ Regular files use netrw's native preview. Directories show a read-only summary o
their immediate children, including type, file size, modification time, and a
total for immediate files. Directories appear first, output is capped at 200
entries, and symbolic links are displayed without following them recursively.
File previews use Vim's syntax highlighting while Tree-sitter is suspended to
avoid asynchronous parser races during rapid replacement; normal Tree-sitter
highlighting resumes automatically when a previewed file is opened for editing.
Diagnostics are hidden in previews and restored to their prior state on edit.
File previews suppress syntax highlighting, Tree-sitter, diagnostics, and indent
guides so rapidly replaced content remains plain and quiet. Normal highlighting
and the buffer's prior diagnostic/indent-guide state return automatically when a
previewed file is opened for editing.
Preview-only file buffers remain loaded but unlisted until Neovim exits, avoiding
the parser detachment that triggers this Neovim 0.12 race.

View file

@ -55,6 +55,25 @@ local function close_timer(state, key)
state[key] = nil
end
local function indent_guides_enabled(buf)
local ok, config = pcall(require, 'ibl.config')
if not ok or not config.config then
return nil
end
return config.get_config(buf).enabled
end
local function set_indent_guides(buf, enabled)
if enabled == nil then
return
end
local ok, ibl = pcall(require, 'ibl')
if ok and ibl.initialized then
ibl.setup_buffer(buf, { enabled = enabled })
end
end
local function restore_preview_buffer(buf, for_editing)
local metadata = preview_buffers[buf]
if not metadata or not is_valid_buffer(buf) then
@ -66,6 +85,7 @@ local function restore_preview_buffer(buf, for_editing)
vim.bo[buf].buflisted = for_editing or metadata.buflisted
vim.bo[buf].syntax = metadata.syntax
vim.diagnostic.enable(metadata.diagnostics_enabled, { bufnr = buf })
set_indent_guides(buf, metadata.indent_guides_enabled)
if metadata.treesitter_active then
pcall(vim.treesitter.start, buf)
end
@ -449,6 +469,7 @@ local function show_native_preview(state, entry)
syntax = vim.bo[existing_buf].syntax,
treesitter_active = vim.treesitter.highlighter.active[existing_buf] ~= nil,
diagnostics_enabled = vim.diagnostic.is_enabled({ bufnr = existing_buf }),
indent_guides_enabled = indent_guides_enabled(existing_buf),
} or nil
local ok, shown = pcall(native_preview, entry)
@ -472,6 +493,10 @@ local function show_native_preview(state, entry)
and existing.buf == preview_buf
and existing.diagnostics_enabled
or vim.diagnostic.is_enabled({ bufnr = preview_buf }),
indent_guides_enabled = existing ~= nil
and existing.buf == preview_buf
and existing.indent_guides_enabled
or indent_guides_enabled(preview_buf),
}
vim.bo[preview_buf].bufhidden = 'hide'
@ -479,11 +504,8 @@ local function show_native_preview(state, entry)
vim.b[preview_buf].netrw_live_preview_buffer = true
pcall(vim.treesitter.stop, preview_buf)
vim.diagnostic.enable(false, { bufnr = preview_buf })
local filetype = vim.bo[preview_buf].filetype
if filetype ~= '' then
vim.bo[preview_buf].syntax = filetype
end
vim.bo[preview_buf].syntax = ''
set_indent_guides(preview_buf, false)
end
end