aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshadmansaleh <shadmansaleh3@gmail.com>2021-06-02 17:04:42 +0600
committershadmansaleh <shadmansaleh3@gmail.com>2021-06-11 01:01:02 +0600
commitf256a18fefeebe76edcca42f530b238e95bc25b6 (patch)
tree77010b37031d3f5ec6ad14a13b500e12082dfb98
parent4dffe1ff2f284fbd4d2bdb6a0f3997e21f9c0c6c (diff)
downloadrneovim-f256a18fefeebe76edcca42f530b238e95bc25b6.tar.gz
rneovim-f256a18fefeebe76edcca42f530b238e95bc25b6.tar.bz2
rneovim-f256a18fefeebe76edcca42f530b238e95bc25b6.zip
feat(runtime): Allow lua to be used in ftdetect
-rw-r--r--runtime/filetype.vim1
-rw-r--r--src/nvim/runtime.c6
-rw-r--r--test/functional/lua/runtime_spec.lua21
3 files changed, 24 insertions, 4 deletions
diff --git a/runtime/filetype.vim b/runtime/filetype.vim
index ed70ac5ce8..89cc1a8fc5 100644
--- a/runtime/filetype.vim
+++ b/runtime/filetype.vim
@@ -2303,6 +2303,7 @@ au BufNewFile,BufRead *.txt
" Use the filetype detect plugins. They may overrule any of the previously
" detected filetypes.
runtime! ftdetect/*.vim
+runtime! ftdetect/*.lua
" NOTE: The above command could have ended the filetypedetect autocmd group
" and started another one. Let's make sure it has ended to get to a consistent
diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c
index dadff42456..22df4d985b 100644
--- a/src/nvim/runtime.c
+++ b/src/nvim/runtime.c
@@ -421,9 +421,9 @@ static int load_pack_plugin(char_u *fname)
size_t len = strlen(ffname) + STRLEN(ftpat);
char_u *pat = xmallocz(len);
- vim_snprintf((char *)pat, len, "%s/plugin/**/*.vim", ffname);
+ vim_snprintf((char *)pat, len, "%s/plugin/**/*.vim", ffname); // NOLINT
source_all_matches(pat);
- vim_snprintf((char *)pat, len, "%s/plugin/**/*.lua", ffname);
+ vim_snprintf((char *)pat, len, "%s/plugin/**/*.lua", ffname); // NOLINT
source_all_matches(pat);
char_u *cmd = vim_strsave((char_u *)"g:did_load_filetypes");
@@ -434,6 +434,8 @@ static int load_pack_plugin(char_u *fname)
do_cmdline_cmd("augroup filetypedetect");
vim_snprintf((char *)pat, len, ftpat, ffname);
source_all_matches(pat);
+ vim_snprintf((char *)pat, len, "%s/ftdetect/*.lua", ffname); // NOLINT
+ source_all_matches(pat);
do_cmdline_cmd("augroup END");
}
xfree(cmd);
diff --git a/test/functional/lua/runtime_spec.lua b/test/functional/lua/runtime_spec.lua
index cd554d6bea..7286e89c76 100644
--- a/test/functional/lua/runtime_spec.lua
+++ b/test/functional/lua/runtime_spec.lua
@@ -127,7 +127,7 @@ describe('runtime:', function()
it('loads lua ftplugins', function()
local ftplugin_file = table.concat({ftplugin_folder , 'new-ft.lua'}, pathsep)
mkdir_p(ftplugin_folder)
- write_file(ftplugin_file , [[ vim.g.lua_ftplugin = 1 ]])
+ write_file(ftplugin_file , [[vim.g.lua_ftplugin = 1]])
clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig, VIMRUNTIME='runtime/' }}
@@ -145,7 +145,7 @@ describe('runtime:', function()
it('loads lua indents', function()
local indent_file = table.concat({indent_folder , 'new-ft.lua'}, pathsep)
mkdir_p(indent_folder)
- write_file(indent_file , [[ vim.g.lua_indent = 1 ]])
+ write_file(indent_file , [[vim.g.lua_indent = 1]])
clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig, VIMRUNTIME='runtime/' }}
@@ -155,5 +155,22 @@ describe('runtime:', function()
end)
end)
+ describe('ftdetect', function()
+ local ftdetect_folder = table.concat({xconfig, 'nvim', 'ftdetect'}, pathsep)
+
+ before_each(clear)
+
+ it('loads lua ftdetects', function()
+ local ftdetect_file = table.concat({ftdetect_folder , 'new-ft.lua'}, pathsep)
+ mkdir_p(ftdetect_folder)
+ write_file(ftdetect_file , [[vim.g.lua_ftdetect = 1]])
+
+ clear{ args_rm={'-u' }, env={ XDG_CONFIG_HOME=xconfig, VIMRUNTIME='runtime/' }}
+
+ eq(1, eval('g:lua_ftdetect'))
+ rmdir(ftdetect_folder)
+ end)
+ end)
+
end)