Skip to content

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

Open
gustav-fff wants to merge 1 commit into
mainfrom
triage-bot/issue-367
Open

fix: restore user control over treesitter in preview (#367)#508
gustav-fff wants to merge 1 commit into
mainfrom
triage-bot/issue-367

Conversation

@gustav-fff
Copy link
Copy Markdown
Collaborator

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.

Refs #367

PR #335 forced treesitter start in preview buffers, removing user control.
Users rely on ftplugin scripts to conditionally start treesitter based on
file size / parser performance. With forced vim.treesitter.start, large files
or slow parsers lag UI.

Fix: restore filetype setting without forced treesitter. Buffer already
protected via buftype=nofile. Plugins should check buftype in ftplugin
(standard neovim practice, see fugitive, telescope). Misbehaving plugins
need upstream fix, not fff forcing highlighting off.

Changed:
- Removed attach_preview_highlighter() function (22 lines)
- Restored direct filetype setting at 4 call sites
- Clear buffer now explicit treesitter stop + filetype/syntax reset

Automated triage via gustav-fff bot.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Regression] fff.nvim forces preview highlighting

2 participants