mirror of
https://github.com/neovim/neovim.git
synced 2025-09-18 09:18:19 +00:00
fix(completion): include lua syntaxes in :ownsyntax completion (#21941)
This just removes DIP_LUA and always executes its branches. Also add tests for cmdline completion for other lua runtime files.
This commit is contained in:
@@ -2710,11 +2710,11 @@ static int ExpandFromContext(expand_T *xp, char *pat, char ***matches, int *numM
|
||||
}
|
||||
if (xp->xp_context == EXPAND_COLORS) {
|
||||
char *directories[] = { "colors", NULL };
|
||||
return ExpandRTDir(pat, DIP_START + DIP_OPT + DIP_LUA, numMatches, matches, directories);
|
||||
return ExpandRTDir(pat, DIP_START + DIP_OPT, numMatches, matches, directories);
|
||||
}
|
||||
if (xp->xp_context == EXPAND_COMPILER) {
|
||||
char *directories[] = { "compiler", NULL };
|
||||
return ExpandRTDir(pat, DIP_LUA, numMatches, matches, directories);
|
||||
return ExpandRTDir(pat, 0, numMatches, matches, directories);
|
||||
}
|
||||
if (xp->xp_context == EXPAND_OWNSYNTAX) {
|
||||
char *directories[] = { "syntax", NULL };
|
||||
@@ -2722,7 +2722,7 @@ static int ExpandFromContext(expand_T *xp, char *pat, char ***matches, int *numM
|
||||
}
|
||||
if (xp->xp_context == EXPAND_FILETYPE) {
|
||||
char *directories[] = { "syntax", "indent", "ftplugin", NULL };
|
||||
return ExpandRTDir(pat, DIP_LUA, numMatches, matches, directories);
|
||||
return ExpandRTDir(pat, 0, numMatches, matches, directories);
|
||||
}
|
||||
if (xp->xp_context == EXPAND_USER_LIST) {
|
||||
return ExpandUserList(xp, matches, numMatches);
|
||||
|
@@ -1175,12 +1175,11 @@ void ex_packadd(exarg_T *eap)
|
||||
|
||||
/// Expand color scheme, compiler or filetype names.
|
||||
/// Search from 'runtimepath':
|
||||
/// 'runtimepath'/{dirnames}/{pat}.vim
|
||||
/// When "flags" has DIP_START: search also from 'start' of 'packpath':
|
||||
/// 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim
|
||||
/// When "flags" has DIP_OPT: search also from 'opt' of 'packpath':
|
||||
/// 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim
|
||||
/// When "flags" has DIP_LUA: search also performed for .lua files
|
||||
/// 'runtimepath'/{dirnames}/{pat}.(vim|lua)
|
||||
/// When "flags" has DIP_START: search also from "start" of 'packpath':
|
||||
/// 'packpath'/pack/*/start/*/{dirnames}/{pat}.(vim|lua)
|
||||
/// When "flags" has DIP_OPT: search also from "opt" of 'packpath':
|
||||
/// 'packpath'/pack/*/opt/*/{dirnames}/{pat}.(vim|lua)
|
||||
/// "dirnames" is an array with one or more directory names.
|
||||
int ExpandRTDir(char *pat, int flags, int *num_file, char ***file, char *dirnames[])
|
||||
{
|
||||
@@ -1197,10 +1196,8 @@ int ExpandRTDir(char *pat, int flags, int *num_file, char ***file, char *dirname
|
||||
char *s = xmalloc(size);
|
||||
snprintf(s, size, "%s/%s*.vim", dirnames[i], pat);
|
||||
globpath(p_rtp, s, &ga, 0);
|
||||
if (flags & DIP_LUA) {
|
||||
snprintf(s, size, "%s/%s*.lua", dirnames[i], pat);
|
||||
globpath(p_rtp, s, &ga, 0);
|
||||
}
|
||||
xfree(s);
|
||||
}
|
||||
|
||||
@@ -1210,10 +1207,8 @@ int ExpandRTDir(char *pat, int flags, int *num_file, char ***file, char *dirname
|
||||
char *s = xmalloc(size);
|
||||
snprintf(s, size, "pack/*/start/*/%s/%s*.vim", dirnames[i], pat); // NOLINT
|
||||
globpath(p_pp, s, &ga, 0);
|
||||
if (flags & DIP_LUA) {
|
||||
snprintf(s, size, "pack/*/start/*/%s/%s*.lua", dirnames[i], pat); // NOLINT
|
||||
globpath(p_pp, s, &ga, 0);
|
||||
}
|
||||
xfree(s);
|
||||
}
|
||||
|
||||
@@ -1222,10 +1217,8 @@ int ExpandRTDir(char *pat, int flags, int *num_file, char ***file, char *dirname
|
||||
char *s = xmalloc(size);
|
||||
snprintf(s, size, "start/*/%s/%s*.vim", dirnames[i], pat); // NOLINT
|
||||
globpath(p_pp, s, &ga, 0);
|
||||
if (flags & DIP_LUA) {
|
||||
snprintf(s, size, "start/*/%s/%s*.lua", dirnames[i], pat); // NOLINT
|
||||
globpath(p_pp, s, &ga, 0);
|
||||
}
|
||||
xfree(s);
|
||||
}
|
||||
}
|
||||
@@ -1236,10 +1229,8 @@ int ExpandRTDir(char *pat, int flags, int *num_file, char ***file, char *dirname
|
||||
char *s = xmalloc(size);
|
||||
snprintf(s, size, "pack/*/opt/*/%s/%s*.vim", dirnames[i], pat); // NOLINT
|
||||
globpath(p_pp, s, &ga, 0);
|
||||
if (flags & DIP_LUA) {
|
||||
snprintf(s, size, "pack/*/opt/*/%s/%s*.lua", dirnames[i], pat); // NOLINT
|
||||
globpath(p_pp, s, &ga, 0);
|
||||
}
|
||||
xfree(s);
|
||||
}
|
||||
|
||||
@@ -1248,10 +1239,8 @@ int ExpandRTDir(char *pat, int flags, int *num_file, char ***file, char *dirname
|
||||
char *s = xmalloc(size);
|
||||
snprintf(s, size, "opt/*/%s/%s*.vim", dirnames[i], pat); // NOLINT
|
||||
globpath(p_pp, s, &ga, 0);
|
||||
if (flags & DIP_LUA) {
|
||||
snprintf(s, size, "opt/*/%s/%s*.lua", dirnames[i], pat); // NOLINT
|
||||
globpath(p_pp, s, &ga, 0);
|
||||
}
|
||||
xfree(s);
|
||||
}
|
||||
}
|
||||
@@ -1261,8 +1250,7 @@ int ExpandRTDir(char *pat, int flags, int *num_file, char ***file, char *dirname
|
||||
char *s = match;
|
||||
char *e = s + strlen(s);
|
||||
if (e - s > 4 && (STRNICMP(e - 4, ".vim", 4) == 0
|
||||
|| ((flags & DIP_LUA)
|
||||
&& STRNICMP(e - 4, ".lua", 4) == 0))) {
|
||||
|| STRNICMP(e - 4, ".lua", 4) == 0)) {
|
||||
e -= 4;
|
||||
for (s = e; s > match; MB_PTR_BACK(match, s)) {
|
||||
if (vim_ispathsep(*s)) {
|
||||
|
@@ -105,7 +105,6 @@ typedef kvec_t(char *) CharVec;
|
||||
#define DIP_NORTP 0x20 // do not use 'runtimepath'
|
||||
#define DIP_NOAFTER 0x40 // skip "after" directories
|
||||
#define DIP_AFTER 0x80 // only use "after" directories
|
||||
#define DIP_LUA 0x100 // also use ".lua" files
|
||||
#define DIP_DIRFILE 0x200 // find both files and directories
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
|
@@ -4,6 +4,7 @@ local clear = helpers.clear
|
||||
local eq = helpers.eq
|
||||
local eval = helpers.eval
|
||||
local exec = helpers.exec
|
||||
local funcs = helpers.funcs
|
||||
local mkdir_p = helpers.mkdir_p
|
||||
local rmdir = helpers.rmdir
|
||||
local write_file = helpers.write_file
|
||||
@@ -29,6 +30,7 @@ describe('runtime:', function()
|
||||
|
||||
after_each(function()
|
||||
rmdir(plug_dir)
|
||||
exec('bwipe!')
|
||||
end)
|
||||
|
||||
describe('colors', function()
|
||||
@@ -39,6 +41,8 @@ describe('runtime:', function()
|
||||
mkdir_p(colorscheme_folder)
|
||||
write_file(colorscheme_file, [[vim.g.lua_colorscheme = 1]])
|
||||
|
||||
eq({'new_colorscheme'}, funcs.getcompletion('new_c', 'color'))
|
||||
|
||||
exec('colorscheme new_colorscheme')
|
||||
|
||||
eq(1, eval('g:lua_colorscheme'))
|
||||
@@ -64,23 +68,25 @@ describe('runtime:', function()
|
||||
it('loads lua compilers', function()
|
||||
local compiler_file = compiler_folder .. sep .. 'new_compiler.lua'
|
||||
mkdir_p(compiler_folder)
|
||||
write_file(compiler_file, [[vim.g.lua_compiler = 1]])
|
||||
write_file(compiler_file, [[vim.b.lua_compiler = 1]])
|
||||
|
||||
eq({'new_compiler'}, funcs.getcompletion('new_c', 'compiler'))
|
||||
|
||||
exec('compiler new_compiler')
|
||||
|
||||
eq(1, eval('g:lua_compiler'))
|
||||
eq(1, eval('b:lua_compiler'))
|
||||
rmdir(compiler_folder)
|
||||
end)
|
||||
|
||||
it('loads vim compilers when both lua and vim version exist', function()
|
||||
local compiler_file = compiler_folder .. sep .. 'new_compiler'
|
||||
mkdir_p(compiler_folder)
|
||||
write_file(compiler_file..'.vim', [[let g:compiler = 'vim']])
|
||||
write_file(compiler_file..'.lua', [[vim.g.compiler = 'lua']])
|
||||
write_file(compiler_file..'.vim', [[let b:compiler = 'vim']])
|
||||
write_file(compiler_file..'.lua', [[vim.b.compiler = 'lua']])
|
||||
|
||||
exec('compiler new_compiler')
|
||||
|
||||
eq('vim', eval('g:compiler'))
|
||||
eq('vim', eval('b:compiler'))
|
||||
rmdir(compiler_folder)
|
||||
end)
|
||||
end)
|
||||
@@ -91,10 +97,12 @@ describe('runtime:', function()
|
||||
it('loads lua ftplugins', function()
|
||||
local ftplugin_file = table.concat({ftplugin_folder , 'new-ft.lua'}, sep)
|
||||
mkdir_p(ftplugin_folder)
|
||||
write_file(ftplugin_file , [[vim.g.lua_ftplugin = 1]])
|
||||
write_file(ftplugin_file , [[vim.b.lua_ftplugin = 1]])
|
||||
|
||||
eq({'new-ft'}, funcs.getcompletion('new-f', 'filetype'))
|
||||
|
||||
exec [[set filetype=new-ft]]
|
||||
eq(1, eval('g:lua_ftplugin'))
|
||||
eq(1, eval('b:lua_ftplugin'))
|
||||
rmdir(ftplugin_folder)
|
||||
end)
|
||||
end)
|
||||
@@ -105,10 +113,12 @@ describe('runtime:', function()
|
||||
it('loads lua indents', function()
|
||||
local indent_file = table.concat({indent_folder , 'new-ft.lua'}, sep)
|
||||
mkdir_p(indent_folder)
|
||||
write_file(indent_file , [[vim.g.lua_indent = 1]])
|
||||
write_file(indent_file , [[vim.b.lua_indent = 1]])
|
||||
|
||||
eq({'new-ft'}, funcs.getcompletion('new-f', 'filetype'))
|
||||
|
||||
exec [[set filetype=new-ft]]
|
||||
eq(1, eval('g:lua_indent'))
|
||||
eq(1, eval('b:lua_indent'))
|
||||
rmdir(indent_folder)
|
||||
end)
|
||||
end)
|
||||
@@ -116,24 +126,32 @@ describe('runtime:', function()
|
||||
describe('syntax', function()
|
||||
local syntax_folder = table.concat({plug_dir, 'syntax'}, sep)
|
||||
|
||||
it('loads lua syntaxes on filetype change', function()
|
||||
before_each(function()
|
||||
local syntax_file = table.concat({syntax_folder , 'my-lang.lua'}, sep)
|
||||
mkdir_p(syntax_folder)
|
||||
write_file(syntax_file , [[vim.g.lua_syntax = 1]])
|
||||
write_file(syntax_file , [[vim.b.current_syntax = 'my-lang']])
|
||||
exec([[let b:current_syntax = '']])
|
||||
end)
|
||||
|
||||
it('loads lua syntaxes on filetype change', function()
|
||||
exec('set filetype=my-lang')
|
||||
eq(1, eval('g:lua_syntax'))
|
||||
rmdir(syntax_folder)
|
||||
eq('my-lang', eval('b:current_syntax'))
|
||||
end)
|
||||
|
||||
it('loads lua syntaxes on syntax change', function()
|
||||
local syntax_file = table.concat({syntax_folder , 'my-lang.lua'}, sep)
|
||||
mkdir_p(syntax_folder)
|
||||
write_file(syntax_file , [[vim.g.lua_syntax = 5]])
|
||||
|
||||
exec('set syntax=my-lang')
|
||||
eq(5, eval('g:lua_syntax'))
|
||||
rmdir(syntax_folder)
|
||||
eq('my-lang', eval('b:current_syntax'))
|
||||
end)
|
||||
|
||||
it('loads lua syntaxes for :ownsyntax', function()
|
||||
exec('ownsyntax my-lang')
|
||||
eq('my-lang', eval('w:current_syntax'))
|
||||
eq('', eval('b:current_syntax'))
|
||||
end)
|
||||
|
||||
it('lua syntaxes are included in cmdline completion', function()
|
||||
eq({'my-lang'}, funcs.getcompletion('my-l', 'filetype'))
|
||||
eq({'my-lang'}, funcs.getcompletion('my-l', 'syntax'))
|
||||
end)
|
||||
end)
|
||||
|
||||
|
Reference in New Issue
Block a user