From f40ce3456313138f2e0f822da9676ed3bc51f608 Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Wed, 5 Jan 2022 09:50:54 -0700 Subject: fix(filetype): match on rather than (#16943) Filetype detection runs on BufRead and BufNewFile autocommands, both of which can fire without an underlying buffer, so it's incorrect to use to determine the file path. Instead, match on and assume that the buffer we're operating on is the current buffer. This is the same assumption that filetype.vim makes, so it should be safe. --- test/functional/lua/filetype_spec.lua | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'test/functional/lua') diff --git a/test/functional/lua/filetype_spec.lua b/test/functional/lua/filetype_spec.lua index d96e7b8a85..20f91ce0f6 100644 --- a/test/functional/lua/filetype_spec.lua +++ b/test/functional/lua/filetype_spec.lua @@ -24,8 +24,7 @@ describe('vim.filetype', function() rs = 'radicalscript', }, }) - vim.api.nvim_buf_set_name(0, 'main.rs') - vim.filetype.match(0) + vim.filetype.match('main.rs') return vim.bo.filetype ]]) end) @@ -40,8 +39,7 @@ describe('vim.filetype', function() ['main.rs'] = 'somethingelse', }, }) - vim.api.nvim_buf_set_name(0, 'main.rs') - vim.filetype.match(0) + vim.filetype.match('main.rs') return vim.bo.filetype ]]) end) @@ -53,8 +51,7 @@ describe('vim.filetype', function() ['s_O_m_e_F_i_l_e'] = 'nim', }, }) - vim.api.nvim_buf_set_name(0, 's_O_m_e_F_i_l_e') - vim.filetype.match(0) + vim.filetype.match('s_O_m_e_F_i_l_e') return vim.bo.filetype ]]) @@ -66,8 +63,7 @@ describe('vim.filetype', function() [root .. '/.config/fun/config'] = 'dosini', }, }) - vim.api.nvim_buf_set_name(0, root .. '/.config/fun/config') - vim.filetype.match(0) + vim.filetype.match(root .. '/.config/fun/config') return vim.bo.filetype ]], root)) end) @@ -80,8 +76,7 @@ describe('vim.filetype', function() [root .. '/blog/.*%.txt'] = 'markdown', } }) - vim.api.nvim_buf_set_name(0, root .. '/blog/why_neovim_is_awesome.txt') - vim.filetype.match(0) + vim.filetype.match(root .. '/blog/why_neovim_is_awesome.txt') return vim.bo.filetype ]], root)) end) @@ -97,8 +92,7 @@ describe('vim.filetype', function() end, } }) - vim.api.nvim_buf_set_name(0, 'relevant_to_me') - vim.filetype.match(0) + vim.filetype.match('relevant_to_me') return vim.bo.filetype ]]) end) -- cgit