feat: add telescope.nvim integration (#170)

Closes #169.

## Problem

Telescope never sets `filetype=diff` on preview buffers — it calls
`vim.treesitter.start(bufnr, "diff")` directly, so diffs.nvim's
`FileType` autocmd never fires.

## Solution

Add a `telescope` config toggle (same pattern as
neogit/gitsigns/committia) and a `User TelescopePreviewerLoaded` autocmd
that calls `attach()` on the preview buffer. Disabled by default; enable
with `telescope = true`.

Also adds a `diffs-telescope` vimdoc section documenting the integration
and the upstream first-line preview bug
(nvim-telescope/telescope.nvim#3626).

Includes committia.vim integration from `feat/committia`.
This commit is contained in:
Barrett Ruth 2026-03-06 13:46:15 -05:00 committed by GitHub
parent dc6fd7a387
commit d584d816bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 61 additions and 0 deletions

View file

@ -41,6 +41,7 @@ CONTENTS *diffs-contents*
Fugitive .......................................... |diffs-fugitive|
Neogit .............................................. |diffs-neogit|
Gitsigns .......................................... |diffs-gitsigns|
Telescope ........................................ |diffs-telescope|
8. Conflict Resolution .................................... |diffs-conflict|
9. Merge Diff Resolution ..................................... |diffs-merge|
10. API ......................................................... |diffs-api|
@ -84,6 +85,7 @@ Configuration is done via `vim.g.diffs`. Set this before the plugin loads:
neogit = false,
gitsigns = false,
committia = false,
telescope = false,
extra_filetypes = {},
highlights = {
background = true,
@ -187,6 +189,16 @@ Configuration is done via `vim.g.diffs`. Set this before the plugin loads:
vim.g.diffs = { committia = true }
<
{telescope} (boolean|table, default: false)
Enable telescope.nvim preview highlighting.
Pass `true` or `{}` to enable, `false` to
disable. When active, telescope preview
buffers showing diffs receive treesitter
syntax, line backgrounds, and intra-line
diffs. See |diffs-telescope|. >lua
vim.g.diffs = { telescope = true }
<
{extra_filetypes} (table, default: {})
Additional filetypes to attach to, beyond the
built-in `git`, `gitcommit`, and any enabled
@ -577,6 +589,28 @@ backgrounds, and intra-line diffs.
Highlights are applied in a separate `diffs-gitsigns` namespace and do not
interfere with the main decoration provider used for diff buffers.
------------------------------------------------------------------------------
TELESCOPE *diffs-telescope*
Enable telescope.nvim (https://github.com/nvim-telescope/telescope.nvim)
preview highlighting: >lua
vim.g.diffs = { telescope = true }
<
Telescope does not set `filetype=diff` on preview buffers — it calls
`vim.treesitter.start(bufnr, "diff")` directly, so diffs.nvim's `FileType`
autocmd never fires. This integration listens for the
`User TelescopePreviewerLoaded` event and attaches to the preview buffer.
Pickers that show diff content (e.g. `git_bcommits`, `git_status`) will
receive treesitter syntax, line backgrounds, and intra-line diffs in the
preview pane.
Known issue: Telescope's previewer may render the first line of the preview
buffer with a black background regardless of colorscheme. This is a
Telescope artifact unrelated to diffs.nvim. Tracked upstream:
https://github.com/nvim-telescope/telescope.nvim/issues/3626
==============================================================================
CONFLICT RESOLUTION *diffs-conflict*

View file

@ -42,6 +42,8 @@
---@class diffs.CommittiaConfig
---@class diffs.TelescopeConfig
---@class diffs.ConflictKeymaps
---@field ours string|false
---@field theirs string|false
@ -68,6 +70,7 @@
---@field neogit diffs.NeogitConfig|false
---@field gitsigns diffs.GitsignsConfig|false
---@field committia diffs.CommittiaConfig|false
---@field telescope diffs.TelescopeConfig|false
---@field conflict diffs.ConflictConfig
---@class diffs
@ -149,6 +152,7 @@ local default_config = {
neogit = false,
gitsigns = false,
committia = false,
telescope = false,
conflict = {
enabled = true,
disable_diagnostics = true,
@ -607,6 +611,10 @@ local function init()
opts.committia = {}
end
if opts.telescope == true then
opts.telescope = {}
end
vim.validate('debug', opts.debug, function(v)
return v == nil or type(v) == 'boolean' or type(v) == 'string'
end, 'boolean or string (file path)')
@ -623,6 +631,9 @@ local function init()
vim.validate('committia', opts.committia, function(v)
return v == nil or v == false or type(v) == 'table'
end, 'table or false')
vim.validate('telescope', opts.telescope, function(v)
return v == nil or v == false or type(v) == 'table'
end, 'table or false')
vim.validate('extra_filetypes', opts.extra_filetypes, 'table', true)
vim.validate('highlights', opts.highlights, 'table', true)
@ -1012,6 +1023,12 @@ function M.get_committia_config()
return config.committia
end
---@return diffs.TelescopeConfig|false
function M.get_telescope_config()
init()
return config.telescope
end
---@return diffs.ConflictConfig
function M.get_conflict_config()
init()

View file

@ -18,6 +18,16 @@ if gs_cfg == true or type(gs_cfg) == 'table' then
end
end
local tel_cfg = (vim.g.diffs or {}).telescope
if tel_cfg == true or type(tel_cfg) == 'table' then
vim.api.nvim_create_autocmd('User', {
pattern = 'TelescopePreviewerLoaded',
callback = function()
require('diffs').attach(vim.api.nvim_get_current_buf())
end,
})
end
vim.api.nvim_create_autocmd('FileType', {
pattern = require('diffs').compute_filetypes(vim.g.diffs or {}),
callback = function(args)