feat: add telescope.nvim integration
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.
This commit is contained in:
parent
36504a3882
commit
7773c8a876
2 changed files with 27 additions and 0 deletions
|
|
@ -42,6 +42,8 @@
|
||||||
|
|
||||||
---@class diffs.CommittiaConfig
|
---@class diffs.CommittiaConfig
|
||||||
|
|
||||||
|
---@class diffs.TelescopeConfig
|
||||||
|
|
||||||
---@class diffs.ConflictKeymaps
|
---@class diffs.ConflictKeymaps
|
||||||
---@field ours string|false
|
---@field ours string|false
|
||||||
---@field theirs string|false
|
---@field theirs string|false
|
||||||
|
|
@ -68,6 +70,7 @@
|
||||||
---@field neogit diffs.NeogitConfig|false
|
---@field neogit diffs.NeogitConfig|false
|
||||||
---@field gitsigns diffs.GitsignsConfig|false
|
---@field gitsigns diffs.GitsignsConfig|false
|
||||||
---@field committia diffs.CommittiaConfig|false
|
---@field committia diffs.CommittiaConfig|false
|
||||||
|
---@field telescope diffs.TelescopeConfig|false
|
||||||
---@field conflict diffs.ConflictConfig
|
---@field conflict diffs.ConflictConfig
|
||||||
|
|
||||||
---@class diffs
|
---@class diffs
|
||||||
|
|
@ -149,6 +152,7 @@ local default_config = {
|
||||||
neogit = false,
|
neogit = false,
|
||||||
gitsigns = false,
|
gitsigns = false,
|
||||||
committia = false,
|
committia = false,
|
||||||
|
telescope = false,
|
||||||
conflict = {
|
conflict = {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
disable_diagnostics = true,
|
disable_diagnostics = true,
|
||||||
|
|
@ -607,6 +611,10 @@ local function init()
|
||||||
opts.committia = {}
|
opts.committia = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if opts.telescope == true then
|
||||||
|
opts.telescope = {}
|
||||||
|
end
|
||||||
|
|
||||||
vim.validate('debug', opts.debug, function(v)
|
vim.validate('debug', opts.debug, function(v)
|
||||||
return v == nil or type(v) == 'boolean' or type(v) == 'string'
|
return v == nil or type(v) == 'boolean' or type(v) == 'string'
|
||||||
end, 'boolean or string (file path)')
|
end, 'boolean or string (file path)')
|
||||||
|
|
@ -623,6 +631,9 @@ local function init()
|
||||||
vim.validate('committia', opts.committia, function(v)
|
vim.validate('committia', opts.committia, function(v)
|
||||||
return v == nil or v == false or type(v) == 'table'
|
return v == nil or v == false or type(v) == 'table'
|
||||||
end, 'table or false')
|
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('extra_filetypes', opts.extra_filetypes, 'table', true)
|
||||||
vim.validate('highlights', opts.highlights, 'table', true)
|
vim.validate('highlights', opts.highlights, 'table', true)
|
||||||
|
|
||||||
|
|
@ -1012,6 +1023,12 @@ function M.get_committia_config()
|
||||||
return config.committia
|
return config.committia
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return diffs.TelescopeConfig|false
|
||||||
|
function M.get_telescope_config()
|
||||||
|
init()
|
||||||
|
return config.telescope
|
||||||
|
end
|
||||||
|
|
||||||
---@return diffs.ConflictConfig
|
---@return diffs.ConflictConfig
|
||||||
function M.get_conflict_config()
|
function M.get_conflict_config()
|
||||||
init()
|
init()
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,16 @@ if gs_cfg == true or type(gs_cfg) == 'table' then
|
||||||
end
|
end
|
||||||
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', {
|
vim.api.nvim_create_autocmd('FileType', {
|
||||||
pattern = require('diffs').compute_filetypes(vim.g.diffs or {}),
|
pattern = require('diffs').compute_filetypes(vim.g.diffs or {}),
|
||||||
callback = function(args)
|
callback = function(args)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue