From 28cfcf51269b7390b447c8a5b61d5083c830e834 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 22 Mar 2023 16:49:04 +0000 Subject: fix(api): vim.filetype.get_option() (#22753) - Fix a bug in the cache - Set some buffer options on the dummy buffer --- runtime/lua/vim/filetype/options.lua | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'runtime/lua') diff --git a/runtime/lua/vim/filetype/options.lua b/runtime/lua/vim/filetype/options.lua index 77a66991d5..a093c249f7 100644 --- a/runtime/lua/vim/filetype/options.lua +++ b/runtime/lua/vim/filetype/options.lua @@ -3,7 +3,7 @@ local api = vim.api local M = {} local function get_ftplugin_runtime(filetype) - return api.nvim__get_runtime({ + local files = api.nvim__get_runtime({ string.format('ftplugin/%s.vim', filetype), string.format('ftplugin/%s_*.vim', filetype), string.format('ftplugin/%s/*.vim', filetype), @@ -11,6 +11,15 @@ local function get_ftplugin_runtime(filetype) string.format('ftplugin/%s_*.lua', filetype), string.format('ftplugin/%s/*.lua', filetype), }, true, {}) --[[@as string[] ]] + + local r = {} ---@type string[] + for _, f in ipairs(files) do + -- VIMRUNTIME should be static so shouldn't need to worry about it changing + if not vim.startswith(f, vim.env.VIMRUNTIME) then + r[#r + 1] = f + end + end + return r end -- Keep track of ftplugin files @@ -52,14 +61,11 @@ local function update_ft_option_cache(filetype) end for _, f in ipairs(files) do - -- VIMRUNTIME should be static so shouldn't need to worry about it changing - if not vim.startswith(f, vim.env.VIMRUNTIME) then - local mtime = hash(f) - if ftplugin_cache[filetype][f] ~= mtime then - -- invalidate - ft_option_cache[filetype] = nil - ftplugin_cache[filetype][f] = mtime - end + local mtime = hash(f) + if ftplugin_cache[filetype][f] ~= mtime then + -- invalidate + ft_option_cache[filetype] = nil + ftplugin_cache[filetype][f] = mtime end end end -- cgit