diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt index a1cd23ec2a..46407a6396 100644 --- a/runtime/doc/lua.txt +++ b/runtime/doc/lua.txt @@ -2409,6 +2409,20 @@ vim.filetype.get_option({filetype}, {option}) Return: ~ (`string|boolean|integer`) Option value +vim.filetype.inspect() *vim.filetype.inspect()* + Inspect the current state of the filetype registry. + + Returns a copy of the internal tables used for filetype detection by + extension, filename, or pattern. Note: Due to the dynamic nature of + filetype detection, this is only useful for checking whether a certain + extension, filename, or pattern has been registered so far. In addition, + the `pattern` table is in an internal format optimized for fast lookup. + Prefer |vim.filetype.match()| for checking the detected filetype for a + given pattern. + + Return: ~ + (`table>>`) + vim.filetype.match({args}) *vim.filetype.match()* Perform filetype detection. diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index 4af8dd6716..3ef77fbb47 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -299,6 +299,8 @@ LUA • |vim.json.encode()| `sort_keys` option sorts by key. • |vim.json.decode()| `skip_comments` option allows comments in JSON data. • EXPERIMENTAL: |vim.pos|, |vim.range| provide Position/Range abstraction. +• |vim.filetype.inspect()| returns a copy of the internal tables used for + filetype detection. OPTIONS diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua index 37cdb7aed8..d77b27ada5 100644 --- a/runtime/lua/vim/filetype.lua +++ b/runtime/lua/vim/filetype.lua @@ -3295,4 +3295,20 @@ function M.get_option(filetype, option) return require('vim.filetype.options').get_option(filetype, option) end +--- Inspect the current state of the filetype registry. +--- +--- Returns a copy of the internal tables used for filetype detection by extension, filename, or +--- pattern. Note: Due to the dynamic nature of filetype detection, this is only useful for checking +--- whether a certain extension, filename, or pattern has been registered so far. In addition, the +--- `pattern` table is in an internal format optimized for fast lookup. Prefer |vim.filetype.match()| +--- for checking the detected filetype for a given pattern. +---@return table>> +function M.inspect() + return { + extension = vim.deepcopy(extension), + filename = vim.deepcopy(filename), + pattern = vim.deepcopy(pattern), + } +end + return M