Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): vim.filetype.get_option() #22753

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions runtime/lua/vim/filetype/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@ 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),
string.format('ftplugin/%s.lua', 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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/nvim/api/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ static buf_T *do_ft_buf(char *filetype, aco_save_T *aco, Error *err)

// Set curwin/curbuf to buf and save a few things.
aucmd_prepbuf(aco, ftbuf);
set_option_value("bufhidden", 0L, "hide", OPT_LOCAL);
set_option_value("buftype", 0L, "nofile", OPT_LOCAL);
set_option_value("swapfile", 0L, NULL, OPT_LOCAL);
set_option_value("modeline", 0L, NULL, OPT_LOCAL); // 'nomodeline'

ftbuf->b_p_ft = xstrdup(filetype);

Expand Down