mirror of
https://github.com/folke/snacks.nvim
synced 2025-12-23 08:47:57 +00:00
feat(picker.diff): native diff now also highlights the language of the diffed code in the diff
This commit is contained in:
parent
e39478daac
commit
726095723d
1 changed files with 20 additions and 0 deletions
|
|
@ -24,6 +24,7 @@ M.__index = M
|
|||
|
||||
local ns = vim.api.nvim_create_namespace("snacks.picker.preview")
|
||||
local ns_loc = vim.api.nvim_create_namespace("snacks.picker.preview.loc")
|
||||
local did_diff_setup = false
|
||||
|
||||
-- HACK: work-around for buffer-local window options mess. From the docs:
|
||||
-- > When editing a buffer that has been edited before, the options from the window
|
||||
|
|
@ -281,6 +282,9 @@ function M:highlight(opts)
|
|||
end
|
||||
self:check_big()
|
||||
local lang = Snacks.util.get_lang(opts.lang or ft)
|
||||
if lang == "diff" then
|
||||
self:diff()
|
||||
end
|
||||
if not (lang and pcall(vim.treesitter.start, self.win.buf, lang)) and ft then
|
||||
vim.bo[self.win.buf].syntax = ft
|
||||
end
|
||||
|
|
@ -411,4 +415,20 @@ function M:notify(msg, level, opts)
|
|||
self:highlight({ lang = "lua" })
|
||||
end
|
||||
|
||||
function M:diff()
|
||||
if did_diff_setup then
|
||||
return
|
||||
end
|
||||
did_diff_setup = true
|
||||
vim.treesitter.query.set(
|
||||
"diff",
|
||||
"injections",
|
||||
[[; extends
|
||||
(block
|
||||
(new_file (filename) @injection.filename)
|
||||
(hunks
|
||||
(hunk changes: (changes) @injection.content
|
||||
(#set! injection.include-children))))]]
|
||||
)
|
||||
end
|
||||
return M
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue