From 58323b1fe2e494cf6a75f108780e21c08996c08e Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Thu, 9 Jun 2022 13:12:36 -0600 Subject: feat(filetype): remove side effects from vim.filetype.match (#18894) Many filetypes from filetype.vim set buffer-local variables, meaning vim.filetype.match cannot be used without side effects. Instead of setting these buffer-local variables in the filetype detection functions themselves, have vim.filetype.match return an optional function value that, when called, sets these variables. This allows vim.filetype.match to work without side effects. --- test/functional/lua/filetype_spec.lua | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'test') diff --git a/test/functional/lua/filetype_spec.lua b/test/functional/lua/filetype_spec.lua index e83dd2eb24..d0cef53c4b 100644 --- a/test/functional/lua/filetype_spec.lua +++ b/test/functional/lua/filetype_spec.lua @@ -23,8 +23,7 @@ describe('vim.filetype', function() rs = 'radicalscript', }, }) - vim.filetype.match('main.rs') - return vim.bo.filetype + return vim.filetype.match('main.rs') ]]) end) @@ -38,8 +37,7 @@ describe('vim.filetype', function() ['main.rs'] = 'somethingelse', }, }) - vim.filetype.match('main.rs') - return vim.bo.filetype + return vim.filetype.match('main.rs') ]]) end) @@ -50,8 +48,7 @@ describe('vim.filetype', function() ['s_O_m_e_F_i_l_e'] = 'nim', }, }) - vim.filetype.match('s_O_m_e_F_i_l_e') - return vim.bo.filetype + return vim.filetype.match('s_O_m_e_F_i_l_e') ]]) eq('dosini', exec_lua([[ @@ -62,8 +59,7 @@ describe('vim.filetype', function() [root .. '/.config/fun/config'] = 'dosini', }, }) - vim.filetype.match(root .. '/.config/fun/config') - return vim.bo.filetype + return vim.filetype.match(root .. '/.config/fun/config') ]], root)) end) @@ -76,8 +72,7 @@ describe('vim.filetype', function() ['~/blog/.*%.txt'] = 'markdown', } }) - vim.filetype.match('~/blog/why_neovim_is_awesome.txt') - return vim.bo.filetype + return vim.filetype.match('~/blog/why_neovim_is_awesome.txt') ]], root)) end) @@ -92,8 +87,7 @@ describe('vim.filetype', function() end, } }) - vim.filetype.match('relevant_to_me') - return vim.bo.filetype + return vim.filetype.match('relevant_to_me') ]]) end) end) -- cgit