fix(filetype): ensure directory bufname ends w/ slash sep #40552

Problem:
`vim.filetype.match()` needs a cheap way to recognize directory buffers
without doing filesystem stat work.

Solution:
Ensure full buffer names for directories end in a trailing slash. Now
directory buffers can proceed through the normal 'filetype' path.

Note side-effects: session and ShaDa buffer-list restore behavior must
be compatible, so those + corresponding tests must be updated.
This commit is contained in:
Barrett Ruth
2026-07-10 11:40:13 -05:00
committed by GitHub
parent 20a4b1bc5e
commit 3b88a8a65d
14 changed files with 122 additions and 9 deletions

View File

@@ -2392,6 +2392,32 @@ describe('api/buf', function()
os.remove(new_name)
end)
it('directory buffer-name always ends with slash', function()
local cwd = t.fix_slashes(fn.getcwd())
local dir = 'Xtest_dir_name'
t.mkdir(dir)
finally(function()
n.rmdir(dir)
end)
api.nvim_buf_set_name(0, dir)
eq(cwd .. '/' .. dir .. '/', t.fix_slashes(api.nvim_buf_get_name(0)))
end)
it('directory buffer-name preserves symbolic link path', function()
t.skip(t.is_os('win'), 'N/A for Windows')
local cwd = t.fix_slashes(fn.getcwd())
local target = 'Xtest_dir_target'
local link = 'Xtest_dir_link'
t.mkdir(target)
assert(vim.uv.fs_symlink(assert(vim.uv.fs_realpath(target)), link, { dir = true }))
finally(function()
os.remove(link)
n.rmdir(target)
end)
api.nvim_buf_set_name(0, link .. '/')
eq(cwd .. '/' .. link .. '/', t.fix_slashes(api.nvim_buf_get_name(0)))
end)
describe("with 'autochdir'", function()
local topdir
local oldbuf