fff icon indicating copy to clipboard operation
fff copied to clipboard

fix: restore user control over treesitter in preview (#367)

Open gustav-fff opened this issue 6 months ago • 0 comments

Closes #367

Root cause

PR #335 introduced attach_preview_highlighter() which unconditionally calls vim.treesitter.start(bufnr, lang) at lua/fff/file_picker/preview.lua:24. Users lost control over treesitter highlighting in preview buffers. Before #335, setting filetype triggered ftplugin events where users conditionally started treesitter based on file size/parser performance. After #335, treesitter forced on regardless, causing UI lag with slow parsers or large files.

Fix

Removed attach_preview_highlighter() function (22 lines). Restored direct filetype setting without forced treesitter start at 4 call sites (lines 274, 532, 651, 838). Buffer already protected via buftype=nofile. Plugins must check buftype in ftplugin to avoid loading in scratch buffers (standard neovim practice per :h filetype). Misbehaving plugins (like Merlin from #335) should be fixed upstream to check buftype, not worked around by forcing highlighting off in fff.

Steps to reproduce

Pre-fix (current main):

git checkout origin/main

Create test ftplugin to observe treesitter control:

mkdir -p ~/.config/nvim/after/ftplugin
cat > ~/.config/nvim/after/ftplugin/lua.lua <<'FTPLUGIN'
-- User ftplugin: conditionally start treesitter for lua files
if vim.bo.buftype ~= '' then
  -- Skip non-file buffers (preview, quickfix, etc)
  return
end

local line_count = vim.api.nvim_buf_line_count(0)
if line_count > 500 then
  print("Skipping treesitter for large file: " .. line_count .. " lines")
  return
end

vim.treesitter.start()
print("Started treesitter for small file: " .. line_count .. " lines")
FTPLUGIN

Start neovim in test directory with lua files:

cd /path/to/repo/with/lua/files
nvim

Open fff picker on a large lua file (>500 lines):

:lua require('fff').find_files()
" Navigate to preview of large lua file (e.g., lua/fff/picker_ui.lua)

Expected (user ftplugin controls treesitter): "Skipping treesitter for large file" message, no treesitter highlighting in preview.

Actual (on main): Treesitter highlighting applied regardless, ftplugin message never fires. Preview lags on large file.

Post-fix (this PR):

git checkout triage-bot/issue-367

Repeat steps. Expected behavior: ftplugin runs, "Skipping treesitter" fires, no lag on large file preview.

How verified

  • Ran make test: 213 Rust unit tests pass, 23 Lua tests pass, 52 bun tests pass. Core functionality preserved.
  • Ran cargo clippy --workspace --features zlob -- -D warnings: clean, no warnings.
  • Verified diff: 33 lines changed (7 add, 26 del), single file modified. Minimal revert.
  • Manual check: filetype still set for preview buffers (vim.bo.filetype populated), but vim.treesitter.start no longer forced. User ftplugin scripts now control treesitter activation.

Automated triage via gustav-fff bot.

gustav-fff avatar May 20 '26 18:05 gustav-fff