mirror of
https://github.com/neovim/neovim.git
synced 2026-07-14 21:30:34 +00:00
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:
@@ -158,8 +158,7 @@ end
|
||||
|
||||
---@param buf integer
|
||||
local function open_parent(buf)
|
||||
local path = api.nvim_buf_get_name(buf)
|
||||
-- TODO(barrettruth): simplify after #40552
|
||||
local path = fs.normalize(api.nvim_buf_get_name(buf))
|
||||
local name = encode_name(fs.basename(path)) .. (vim.fn.isdirectory(path) == 1 and '/' or '')
|
||||
navigate(fs.dirname(path))
|
||||
vim.fn.search([[\C\m^\V]] .. vim.fn.escape(name, [[\]]) .. [[\m$]], 'cw')
|
||||
|
||||
3
runtime/lua/vim/_meta/api.gen.lua
generated
3
runtime/lua/vim/_meta/api.gen.lua
generated
@@ -511,6 +511,9 @@ function vim.api.nvim_buf_get_mark(buf, name) end
|
||||
|
||||
--- Gets the full/absolute filepath of the buffer, or the buffer name for non-file buffers.
|
||||
---
|
||||
--- If the buffer represents a directory, the name ends with a path separator,
|
||||
--- unless it was changed by `:file` or `nvim_buf_set_name()`.
|
||||
---
|
||||
--- @param buf integer Buffer id, or 0 for current buffer
|
||||
--- @return string # Buffer name
|
||||
function vim.api.nvim_buf_get_name(buf) end
|
||||
|
||||
4
runtime/lua/vim/_meta/vimfn.gen.lua
generated
4
runtime/lua/vim/_meta/vimfn.gen.lua
generated
@@ -605,7 +605,9 @@ function vim.fn.bufloaded(buf) end
|
||||
---
|
||||
--- The result is the name of a buffer. Mostly as it is displayed
|
||||
--- by the `:ls` command, but not using special names such as
|
||||
--- "[No Name]".
|
||||
--- "[No Name]". If the buffer represents a directory, the name
|
||||
--- ends with a path separator, unless it was changed by |:file| or
|
||||
--- |nvim_buf_set_name()|.
|
||||
--- If {buf} is omitted the current buffer is used.
|
||||
--- If {buf} is a Number, that buffer number's name is given.
|
||||
--- Number zero is the alternate buffer for the current window.
|
||||
|
||||
@@ -3254,6 +3254,9 @@ function M.match(args)
|
||||
end
|
||||
|
||||
if name then
|
||||
if name:sub(-1) == '/' then
|
||||
return 'directory'
|
||||
end
|
||||
name = normalize_path(name)
|
||||
|
||||
local ok_abspath, path = pcall(vim.fs.abspath, name)
|
||||
|
||||
Reference in New Issue
Block a user