fix(git): set filetype on URI buffers from the inner path
This commit is contained in:
+19
-5
@@ -198,14 +198,13 @@ function M.read_uri(buf)
|
||||
end
|
||||
|
||||
local parsed = util.parse_revspec(revspec)
|
||||
local index_path = parsed.stage == 0 and parsed.path or nil
|
||||
if index_path then
|
||||
if parsed.stage == 0 and parsed.path then
|
||||
vim.bo[buf].buftype = "acwrite"
|
||||
-- Re-running BufReadCmd (e.g. on `:edit`) would otherwise stack
|
||||
-- another BufWriteCmd on the same buffer, so each `:w` runs
|
||||
-- hash-object + update-index N times.
|
||||
if not vim.b[buf].git_index_writer then
|
||||
attach_index_writer(buf, worktree, index_path)
|
||||
attach_index_writer(buf, worktree, parsed.path)
|
||||
vim.b[buf].git_index_writer = true
|
||||
end
|
||||
else
|
||||
@@ -214,8 +213,23 @@ function M.read_uri(buf)
|
||||
end
|
||||
vim.bo[buf].modified = false
|
||||
|
||||
-- BufReadCmd suppresses the normal BufReadPost dispatch, so filetype
|
||||
-- detection and modeline parsing don't run unless we fire it ourselves.
|
||||
-- Filetype from the inner path. We can't lean on `vim.filetype.add`
|
||||
-- because Vim normalises `git://` filenames (cwd-prefix + collapses
|
||||
-- `://` to `:/`) before matching, breaking any pattern keyed on the
|
||||
-- raw scheme as well as any built-in pattern that doesn't catch a
|
||||
-- recognisable extension on the mangled form (.Xresources is the
|
||||
-- canonical example).
|
||||
if parsed.path then
|
||||
local ft = vim.filetype.match({ filename = parsed.path, buf = buf })
|
||||
if ft then
|
||||
vim.bo[buf].filetype = ft
|
||||
end
|
||||
end
|
||||
|
||||
-- BufReadCmd suppresses the normal BufReadPost dispatch, so
|
||||
-- modeline parsing doesn't run unless we fire it ourselves. The
|
||||
-- modeline can still override the filetype set above; standard Vim
|
||||
-- precedence.
|
||||
vim.api.nvim_exec_autocmds("BufReadPost", { buffer = buf })
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user