mirror of
https://github.com/vim/vim.git
synced 2025-10-10 06:24:10 -04:00
patch 8.2.3838: cannot use script-local function for setting *func options
Problem: Cannot use script-local function for setting *func options. Solution: Use the script context. (Yegappan Lakshmanan, closes #9362)
This commit is contained in:
committed by
Bram Moolenaar
parent
d2ff705af3
commit
db1a410b61
30
src/option.c
30
src/option.c
@@ -7199,17 +7199,39 @@ option_set_callback_func(char_u *optval UNUSED, callback_T *optcb UNUSED)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STRNCMP(optval, "s:", 2) == 0 && !SCRIPT_ID_VALID(current_sctx.sc_sid))
|
|
||||||
return FAIL;
|
|
||||||
|
|
||||||
if (*optval == '{' || (in_vim9script() && *optval == '(')
|
if (*optval == '{' || (in_vim9script() && *optval == '(')
|
||||||
|| (STRNCMP(optval, "function(", 9) == 0)
|
|| (STRNCMP(optval, "function(", 9) == 0)
|
||||||
|| (STRNCMP(optval, "funcref(", 8) == 0))
|
|| (STRNCMP(optval, "funcref(", 8) == 0))
|
||||||
// Lambda expression or a funcref
|
// Lambda expression or a funcref
|
||||||
tv = eval_expr(optval, NULL);
|
tv = eval_expr(optval, NULL);
|
||||||
else
|
else
|
||||||
|
{
|
||||||
// treat everything else as a function name string
|
// treat everything else as a function name string
|
||||||
tv = alloc_string_tv(vim_strsave(optval));
|
|
||||||
|
// Function name starting with "s:" are supported only in a vimscript
|
||||||
|
// context.
|
||||||
|
if (STRNCMP(optval, "s:", 2) == 0)
|
||||||
|
{
|
||||||
|
char sid_buf[25];
|
||||||
|
char_u *funcname;
|
||||||
|
|
||||||
|
if (!SCRIPT_ID_VALID(current_sctx.sc_sid))
|
||||||
|
{
|
||||||
|
emsg(_(e_using_sid_not_in_script_context));
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
// Expand s: prefix into <SNR>nr_<name>
|
||||||
|
sprintf(sid_buf, "<SNR>%ld_", (long)current_sctx.sc_sid);
|
||||||
|
funcname = alloc(STRLEN(sid_buf) + STRLEN(optval + 2) + 1);
|
||||||
|
if (funcname == NULL)
|
||||||
|
return FAIL;
|
||||||
|
STRCPY(funcname, sid_buf);
|
||||||
|
STRCAT(funcname, optval + 2);
|
||||||
|
tv = alloc_string_tv(funcname);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
tv = alloc_string_tv(vim_strsave(optval));
|
||||||
|
}
|
||||||
if (tv == NULL)
|
if (tv == NULL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
|
|
||||||
|
@@ -1,6 +0,0 @@
|
|||||||
| +0&#ffffff0@74
|
|
||||||
@75
|
|
||||||
@75
|
|
||||||
|E+0#ffffff16#e000002|r@1|o|r| |d|e|t|e|c|t|e|d| |w|h|i|l|e| |p|r|o|c|e|s@1|i|n|g| |c|o|m@1|a|n|d| |l|i|n|e|:| +0#0000000#ffffff0@29
|
|
||||||
|E+0#ffffff16#e000002|4|7|4|:| |I|n|v|a|l|i|d| |a|r|g|u|m|e|n|t|:| |t|a|g|f|u|n|c|=|s|:|F|u|n|c| +0#0000000#ffffff0@36
|
|
||||||
|P+0#00e0003&|r|e|s@1| |E|N|T|E|R| |o|r| |t|y|p|e| |c|o|m@1|a|n|d| |t|o| |c|o|n|t|i|n|u|e> +0#0000000&@35
|
|
@@ -880,13 +880,13 @@ func Test_completefunc_callback()
|
|||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
let lines =<< trim END
|
let lines =<< trim END
|
||||||
#" Test for using a function name
|
#" Test for using a global function name
|
||||||
LET &completefunc = 'g:CompleteFunc2'
|
LET &completefunc = 'g:CompleteFunc2'
|
||||||
new
|
new
|
||||||
call setline(1, 'zero')
|
call setline(1, 'global')
|
||||||
LET g:CompleteFunc2Args = []
|
LET g:CompleteFunc2Args = []
|
||||||
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
||||||
call assert_equal([[1, ''], [0, 'zero']], g:CompleteFunc2Args)
|
call assert_equal([[1, ''], [0, 'global']], g:CompleteFunc2Args)
|
||||||
bw!
|
bw!
|
||||||
|
|
||||||
#" Test for using a function()
|
#" Test for using a function()
|
||||||
@@ -1022,6 +1022,29 @@ func Test_completefunc_callback()
|
|||||||
END
|
END
|
||||||
call CheckLegacyAndVim9Success(lines)
|
call CheckLegacyAndVim9Success(lines)
|
||||||
|
|
||||||
|
" Test for using a script-local function name
|
||||||
|
func s:CompleteFunc3(findstart, base)
|
||||||
|
call add(g:CompleteFunc3Args, [a:findstart, a:base])
|
||||||
|
return a:findstart ? 0 : []
|
||||||
|
endfunc
|
||||||
|
set completefunc=s:CompleteFunc3
|
||||||
|
new
|
||||||
|
call setline(1, 'script1')
|
||||||
|
let g:CompleteFunc3Args = []
|
||||||
|
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
||||||
|
call assert_equal([[1, ''], [0, 'script1']], g:CompleteFunc3Args)
|
||||||
|
bw!
|
||||||
|
|
||||||
|
let &completefunc = 's:CompleteFunc3'
|
||||||
|
new
|
||||||
|
call setline(1, 'script2')
|
||||||
|
let g:CompleteFunc3Args = []
|
||||||
|
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
||||||
|
call assert_equal([[1, ''], [0, 'script2']], g:CompleteFunc3Args)
|
||||||
|
bw!
|
||||||
|
delfunc s:CompleteFunc3
|
||||||
|
|
||||||
|
" invalid return value
|
||||||
let &completefunc = {a -> 'abc'}
|
let &completefunc = {a -> 'abc'}
|
||||||
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
||||||
|
|
||||||
@@ -1056,11 +1079,12 @@ func Test_completefunc_callback()
|
|||||||
let lines =<< trim END
|
let lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
|
|
||||||
# Test for using a def function with completefunc
|
def Vim9CompleteFunc(callnr: number, findstart: number, base: string): any
|
||||||
def Vim9CompleteFunc(val: number, findstart: number, base: string): any
|
add(g:Vim9completeFuncArgs, [callnr, findstart, base])
|
||||||
add(g:Vim9completeFuncArgs, [val, findstart, base])
|
|
||||||
return findstart ? 0 : []
|
return findstart ? 0 : []
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
# Test for using a def function with completefunc
|
||||||
set completefunc=function('Vim9CompleteFunc',\ [60])
|
set completefunc=function('Vim9CompleteFunc',\ [60])
|
||||||
new | only
|
new | only
|
||||||
setline(1, 'one')
|
setline(1, 'one')
|
||||||
@@ -1068,6 +1092,28 @@ func Test_completefunc_callback()
|
|||||||
feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
||||||
assert_equal([[60, 1, ''], [60, 0, 'one']], g:Vim9completeFuncArgs)
|
assert_equal([[60, 1, ''], [60, 0, 'one']], g:Vim9completeFuncArgs)
|
||||||
bw!
|
bw!
|
||||||
|
|
||||||
|
# Test for using a global function name
|
||||||
|
&completefunc = g:CompleteFunc2
|
||||||
|
new | only
|
||||||
|
setline(1, 'two')
|
||||||
|
g:CompleteFunc2Args = []
|
||||||
|
feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
||||||
|
assert_equal([[1, ''], [0, 'two']], g:CompleteFunc2Args)
|
||||||
|
bw!
|
||||||
|
|
||||||
|
# Test for using a script-local function name
|
||||||
|
def s:LocalCompleteFunc(findstart: number, base: string): any
|
||||||
|
add(g:LocalCompleteFuncArgs, [findstart, base])
|
||||||
|
return findstart ? 0 : []
|
||||||
|
enddef
|
||||||
|
&completefunc = s:LocalCompleteFunc
|
||||||
|
new | only
|
||||||
|
setline(1, 'three')
|
||||||
|
g:LocalCompleteFuncArgs = []
|
||||||
|
feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
|
||||||
|
assert_equal([[1, ''], [0, 'three']], g:LocalCompleteFuncArgs)
|
||||||
|
bw!
|
||||||
END
|
END
|
||||||
call CheckScriptSuccess(lines)
|
call CheckScriptSuccess(lines)
|
||||||
|
|
||||||
@@ -1233,6 +1279,29 @@ func Test_omnifunc_callback()
|
|||||||
END
|
END
|
||||||
call CheckLegacyAndVim9Success(lines)
|
call CheckLegacyAndVim9Success(lines)
|
||||||
|
|
||||||
|
" Test for using a script-local function name
|
||||||
|
func s:OmniFunc3(findstart, base)
|
||||||
|
call add(g:OmniFunc3Args, [a:findstart, a:base])
|
||||||
|
return a:findstart ? 0 : []
|
||||||
|
endfunc
|
||||||
|
set omnifunc=s:OmniFunc3
|
||||||
|
new
|
||||||
|
call setline(1, 'script1')
|
||||||
|
let g:OmniFunc3Args = []
|
||||||
|
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
||||||
|
call assert_equal([[1, ''], [0, 'script1']], g:OmniFunc3Args)
|
||||||
|
bw!
|
||||||
|
|
||||||
|
let &omnifunc = 's:OmniFunc3'
|
||||||
|
new
|
||||||
|
call setline(1, 'script2')
|
||||||
|
let g:OmniFunc3Args = []
|
||||||
|
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
||||||
|
call assert_equal([[1, ''], [0, 'script2']], g:OmniFunc3Args)
|
||||||
|
bw!
|
||||||
|
delfunc s:OmniFunc3
|
||||||
|
|
||||||
|
" invalid return value
|
||||||
let &omnifunc = {a -> 'abc'}
|
let &omnifunc = {a -> 'abc'}
|
||||||
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
||||||
|
|
||||||
@@ -1267,11 +1336,12 @@ func Test_omnifunc_callback()
|
|||||||
let lines =<< trim END
|
let lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
|
|
||||||
# Test for using a def function with omnifunc
|
def Vim9omniFunc(callnr: number, findstart: number, base: string): any
|
||||||
def Vim9omniFunc(val: number, findstart: number, base: string): any
|
add(g:Vim9omniFunc_Args, [callnr, findstart, base])
|
||||||
add(g:Vim9omniFunc_Args, [val, findstart, base])
|
|
||||||
return findstart ? 0 : []
|
return findstart ? 0 : []
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
# Test for using a def function with omnifunc
|
||||||
set omnifunc=function('Vim9omniFunc',\ [60])
|
set omnifunc=function('Vim9omniFunc',\ [60])
|
||||||
new | only
|
new | only
|
||||||
setline(1, 'one')
|
setline(1, 'one')
|
||||||
@@ -1279,6 +1349,28 @@ func Test_omnifunc_callback()
|
|||||||
feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
||||||
assert_equal([[60, 1, ''], [60, 0, 'one']], g:Vim9omniFunc_Args)
|
assert_equal([[60, 1, ''], [60, 0, 'one']], g:Vim9omniFunc_Args)
|
||||||
bw!
|
bw!
|
||||||
|
|
||||||
|
# Test for using a global function name
|
||||||
|
&omnifunc = g:OmniFunc2
|
||||||
|
new | only
|
||||||
|
setline(1, 'two')
|
||||||
|
g:OmniFunc2Args = []
|
||||||
|
feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
||||||
|
assert_equal([[1, ''], [0, 'two']], g:OmniFunc2Args)
|
||||||
|
bw!
|
||||||
|
|
||||||
|
# Test for using a script-local function name
|
||||||
|
def s:LocalOmniFunc(findstart: number, base: string): any
|
||||||
|
add(g:LocalOmniFuncArgs, [findstart, base])
|
||||||
|
return findstart ? 0 : []
|
||||||
|
enddef
|
||||||
|
&omnifunc = s:LocalOmniFunc
|
||||||
|
new | only
|
||||||
|
setline(1, 'three')
|
||||||
|
g:LocalOmniFuncArgs = []
|
||||||
|
feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
|
||||||
|
assert_equal([[1, ''], [0, 'three']], g:LocalOmniFuncArgs)
|
||||||
|
bw!
|
||||||
END
|
END
|
||||||
call CheckScriptSuccess(lines)
|
call CheckScriptSuccess(lines)
|
||||||
|
|
||||||
@@ -1467,6 +1559,29 @@ func Test_thesaurusfunc_callback()
|
|||||||
END
|
END
|
||||||
call CheckLegacyAndVim9Success(lines)
|
call CheckLegacyAndVim9Success(lines)
|
||||||
|
|
||||||
|
" Test for using a script-local function name
|
||||||
|
func s:TsrFunc3(findstart, base)
|
||||||
|
call add(g:TsrFunc3Args, [a:findstart, a:base])
|
||||||
|
return a:findstart ? 0 : []
|
||||||
|
endfunc
|
||||||
|
set tsrfu=s:TsrFunc3
|
||||||
|
new
|
||||||
|
call setline(1, 'script1')
|
||||||
|
let g:TsrFunc3Args = []
|
||||||
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
||||||
|
call assert_equal([[1, ''], [0, 'script1']], g:TsrFunc3Args)
|
||||||
|
bw!
|
||||||
|
|
||||||
|
let &tsrfu = 's:TsrFunc3'
|
||||||
|
new
|
||||||
|
call setline(1, 'script2')
|
||||||
|
let g:TsrFunc3Args = []
|
||||||
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
||||||
|
call assert_equal([[1, ''], [0, 'script2']], g:TsrFunc3Args)
|
||||||
|
bw!
|
||||||
|
delfunc s:TsrFunc3
|
||||||
|
|
||||||
|
" invalid return value
|
||||||
let &thesaurusfunc = {a -> 'abc'}
|
let &thesaurusfunc = {a -> 'abc'}
|
||||||
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
||||||
|
|
||||||
@@ -1514,11 +1629,12 @@ func Test_thesaurusfunc_callback()
|
|||||||
let lines =<< trim END
|
let lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
|
|
||||||
# Test for using a def function with thesaurusfunc
|
def Vim9tsrFunc(callnr: number, findstart: number, base: string): any
|
||||||
def Vim9tsrFunc(val: number, findstart: number, base: string): any
|
add(g:Vim9tsrFunc_Args, [callnr, findstart, base])
|
||||||
add(g:Vim9tsrFunc_Args, [val, findstart, base])
|
|
||||||
return findstart ? 0 : []
|
return findstart ? 0 : []
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
# Test for using a def function with thesaurusfunc
|
||||||
set thesaurusfunc=function('Vim9tsrFunc',\ [60])
|
set thesaurusfunc=function('Vim9tsrFunc',\ [60])
|
||||||
new | only
|
new | only
|
||||||
setline(1, 'one')
|
setline(1, 'one')
|
||||||
@@ -1526,6 +1642,28 @@ func Test_thesaurusfunc_callback()
|
|||||||
feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
||||||
assert_equal([[60, 1, ''], [60, 0, 'one']], g:Vim9tsrFunc_Args)
|
assert_equal([[60, 1, ''], [60, 0, 'one']], g:Vim9tsrFunc_Args)
|
||||||
bw!
|
bw!
|
||||||
|
|
||||||
|
# Test for using a global function name
|
||||||
|
&thesaurusfunc = g:TsrFunc2
|
||||||
|
new | only
|
||||||
|
setline(1, 'two')
|
||||||
|
g:TsrFunc2Args = []
|
||||||
|
feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
||||||
|
assert_equal([[1, ''], [0, 'two']], g:TsrFunc2Args)
|
||||||
|
bw!
|
||||||
|
|
||||||
|
# Test for using a script-local function name
|
||||||
|
def s:LocalTsrFunc(findstart: number, base: string): any
|
||||||
|
add(g:LocalTsrFuncArgs, [findstart, base])
|
||||||
|
return findstart ? 0 : []
|
||||||
|
enddef
|
||||||
|
&thesaurusfunc = s:LocalTsrFunc
|
||||||
|
new | only
|
||||||
|
setline(1, 'three')
|
||||||
|
g:LocalTsrFuncArgs = []
|
||||||
|
feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
|
||||||
|
assert_equal([[1, ''], [0, 'three']], g:LocalTsrFuncArgs)
|
||||||
|
bw!
|
||||||
END
|
END
|
||||||
call CheckScriptSuccess(lines)
|
call CheckScriptSuccess(lines)
|
||||||
|
|
||||||
|
@@ -575,6 +575,21 @@ func Test_opfunc_callback()
|
|||||||
END
|
END
|
||||||
call CheckTransLegacySuccess(lines)
|
call CheckTransLegacySuccess(lines)
|
||||||
|
|
||||||
|
" Test for using a script-local function name
|
||||||
|
func s:OpFunc3(type)
|
||||||
|
let g:OpFunc3Args = [a:type]
|
||||||
|
endfunc
|
||||||
|
set opfunc=s:OpFunc3
|
||||||
|
let g:OpFunc3Args = []
|
||||||
|
normal! g@l
|
||||||
|
call assert_equal(['char'], g:OpFunc3Args)
|
||||||
|
|
||||||
|
let &opfunc = 's:OpFunc3'
|
||||||
|
let g:OpFunc3Args = []
|
||||||
|
normal! g@l
|
||||||
|
call assert_equal(['char'], g:OpFunc3Args)
|
||||||
|
delfunc s:OpFunc3
|
||||||
|
|
||||||
" Using Vim9 lambda expression in legacy context should fail
|
" Using Vim9 lambda expression in legacy context should fail
|
||||||
set opfunc=(a)\ =>\ OpFunc1(24,\ a)
|
set opfunc=(a)\ =>\ OpFunc1(24,\ a)
|
||||||
let g:OpFunc1Args = []
|
let g:OpFunc1Args = []
|
||||||
@@ -598,14 +613,32 @@ func Test_opfunc_callback()
|
|||||||
let lines =<< trim END
|
let lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
|
|
||||||
# Test for using a def function with opfunc
|
|
||||||
def g:Vim9opFunc(val: number, type: string): void
|
def g:Vim9opFunc(val: number, type: string): void
|
||||||
g:OpFunc1Args = [val, type]
|
g:OpFunc1Args = [val, type]
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
# Test for using a def function with opfunc
|
||||||
set opfunc=function('g:Vim9opFunc',\ [60])
|
set opfunc=function('g:Vim9opFunc',\ [60])
|
||||||
g:OpFunc1Args = []
|
g:OpFunc1Args = []
|
||||||
normal! g@l
|
normal! g@l
|
||||||
assert_equal([60, 'char'], g:OpFunc1Args)
|
assert_equal([60, 'char'], g:OpFunc1Args)
|
||||||
|
|
||||||
|
# Test for using a global function name
|
||||||
|
&opfunc = g:OpFunc2
|
||||||
|
g:OpFunc2Args = []
|
||||||
|
normal! g@l
|
||||||
|
assert_equal(['char'], g:OpFunc2Args)
|
||||||
|
bw!
|
||||||
|
|
||||||
|
# Test for using a script-local function name
|
||||||
|
def s:LocalOpFunc(type: string): void
|
||||||
|
g:LocalOpFuncArgs = [type]
|
||||||
|
enddef
|
||||||
|
&opfunc = s:LocalOpFunc
|
||||||
|
g:LocalOpFuncArgs = []
|
||||||
|
normal! g@l
|
||||||
|
assert_equal(['char'], g:LocalOpFuncArgs)
|
||||||
|
bw!
|
||||||
END
|
END
|
||||||
call CheckScriptSuccess(lines)
|
call CheckScriptSuccess(lines)
|
||||||
|
|
||||||
|
@@ -5387,6 +5387,23 @@ func Test_qftextfunc_callback()
|
|||||||
END
|
END
|
||||||
call CheckLegacyAndVim9Success(lines)
|
call CheckLegacyAndVim9Success(lines)
|
||||||
|
|
||||||
|
" Test for using a script-local function name
|
||||||
|
func s:TqfFunc2(info)
|
||||||
|
let g:TqfFunc2Args = [a:info.start_idx, a:info.end_idx]
|
||||||
|
return ''
|
||||||
|
endfunc
|
||||||
|
let g:TqfFunc2Args = []
|
||||||
|
set quickfixtextfunc=s:TqfFunc2
|
||||||
|
cexpr "F10:10:10:L10"
|
||||||
|
cclose
|
||||||
|
call assert_equal([1, 1], g:TqfFunc2Args)
|
||||||
|
|
||||||
|
let &quickfixtextfunc = 's:TqfFunc2'
|
||||||
|
cexpr "F11:11:11:L11"
|
||||||
|
cclose
|
||||||
|
call assert_equal([1, 1], g:TqfFunc2Args)
|
||||||
|
delfunc s:TqfFunc2
|
||||||
|
|
||||||
" set 'quickfixtextfunc' to a partial with dict. This used to cause a crash.
|
" set 'quickfixtextfunc' to a partial with dict. This used to cause a crash.
|
||||||
func SetQftfFunc()
|
func SetQftfFunc()
|
||||||
let params = {'qftf': function('g:DictQftfFunc')}
|
let params = {'qftf': function('g:DictQftfFunc')}
|
||||||
|
@@ -267,38 +267,62 @@ func Test_tagfunc_callback()
|
|||||||
END
|
END
|
||||||
call CheckLegacyAndVim9Success(lines)
|
call CheckLegacyAndVim9Success(lines)
|
||||||
|
|
||||||
|
" Test for using a script-local function name
|
||||||
|
func s:TagFunc3(pat, flags, info)
|
||||||
|
let g:TagFunc3Args = [a:pat, a:flags, a:info]
|
||||||
|
return v:null
|
||||||
|
endfunc
|
||||||
|
set tagfunc=s:TagFunc3
|
||||||
|
new
|
||||||
|
let g:TagFunc3Args = []
|
||||||
|
call assert_fails('tag a21', 'E433:')
|
||||||
|
call assert_equal(['a21', '', {}], g:TagFunc3Args)
|
||||||
|
bw!
|
||||||
|
let &tagfunc = 's:TagFunc3'
|
||||||
|
new
|
||||||
|
let g:TagFunc3Args = []
|
||||||
|
call assert_fails('tag a22', 'E433:')
|
||||||
|
call assert_equal(['a22', '', {}], g:TagFunc3Args)
|
||||||
|
bw!
|
||||||
|
delfunc s:TagFunc3
|
||||||
|
|
||||||
|
" invalid return value
|
||||||
let &tagfunc = "{a -> 'abc'}"
|
let &tagfunc = "{a -> 'abc'}"
|
||||||
call assert_fails("echo taglist('a')", "E987:")
|
call assert_fails("echo taglist('a')", "E987:")
|
||||||
|
|
||||||
" Using Vim9 lambda expression in legacy context should fail
|
" Using Vim9 lambda expression in legacy context should fail
|
||||||
set tagfunc=(a,\ b,\ c)\ =>\ g:TagFunc1(21,\ a,\ b,\ c)
|
set tagfunc=(a,\ b,\ c)\ =>\ g:TagFunc1(21,\ a,\ b,\ c)
|
||||||
new | only
|
new
|
||||||
let g:TagFunc1Args = []
|
let g:TagFunc1Args = []
|
||||||
call assert_fails("tag a17", "E117:")
|
call assert_fails("tag a17", "E117:")
|
||||||
call assert_equal([], g:TagFunc1Args)
|
call assert_equal([], g:TagFunc1Args)
|
||||||
|
bw!
|
||||||
|
|
||||||
" Test for using a script local function
|
" Test for using a script local function
|
||||||
set tagfunc=<SID>ScriptLocalTagFunc
|
set tagfunc=<SID>ScriptLocalTagFunc
|
||||||
new | only
|
new
|
||||||
let g:ScriptLocalFuncArgs = []
|
let g:ScriptLocalFuncArgs = []
|
||||||
call assert_fails('tag a15', 'E433:')
|
call assert_fails('tag a15', 'E433:')
|
||||||
call assert_equal(['a15', '', {}], g:ScriptLocalFuncArgs)
|
call assert_equal(['a15', '', {}], g:ScriptLocalFuncArgs)
|
||||||
|
bw!
|
||||||
|
|
||||||
" Test for using a script local funcref variable
|
" Test for using a script local funcref variable
|
||||||
let Fn = function("s:ScriptLocalTagFunc")
|
let Fn = function("s:ScriptLocalTagFunc")
|
||||||
let &tagfunc= Fn
|
let &tagfunc= Fn
|
||||||
new | only
|
new
|
||||||
let g:ScriptLocalFuncArgs = []
|
let g:ScriptLocalFuncArgs = []
|
||||||
call assert_fails('tag a16', 'E433:')
|
call assert_fails('tag a16', 'E433:')
|
||||||
call assert_equal(['a16', '', {}], g:ScriptLocalFuncArgs)
|
call assert_equal(['a16', '', {}], g:ScriptLocalFuncArgs)
|
||||||
|
bw!
|
||||||
|
|
||||||
" Test for using a string(script local funcref variable)
|
" Test for using a string(script local funcref variable)
|
||||||
let Fn = function("s:ScriptLocalTagFunc")
|
let Fn = function("s:ScriptLocalTagFunc")
|
||||||
let &tagfunc= string(Fn)
|
let &tagfunc= string(Fn)
|
||||||
new | only
|
new
|
||||||
let g:ScriptLocalFuncArgs = []
|
let g:ScriptLocalFuncArgs = []
|
||||||
call assert_fails('tag a16', 'E433:')
|
call assert_fails('tag a16', 'E433:')
|
||||||
call assert_equal(['a16', '', {}], g:ScriptLocalFuncArgs)
|
call assert_equal(['a16', '', {}], g:ScriptLocalFuncArgs)
|
||||||
|
bw!
|
||||||
|
|
||||||
" set 'tagfunc' to a partial with dict. This used to cause a crash.
|
" set 'tagfunc' to a partial with dict. This used to cause a crash.
|
||||||
func SetTagFunc()
|
func SetTagFunc()
|
||||||
@@ -324,16 +348,37 @@ func Test_tagfunc_callback()
|
|||||||
let lines =<< trim END
|
let lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
|
|
||||||
# Test for using function()
|
def Vim9tagFunc(callnr: number, pat: string, flags: string, info: dict<any>): any
|
||||||
def Vim9tagFunc(val: number, pat: string, flags: string, info: dict<any>): any
|
g:Vim9tagFuncArgs = [callnr, pat, flags, info]
|
||||||
g:Vim9tagFuncArgs = [val, pat, flags, info]
|
|
||||||
return null
|
return null
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
# Test for using a def function with completefunc
|
||||||
set tagfunc=function('Vim9tagFunc',\ [60])
|
set tagfunc=function('Vim9tagFunc',\ [60])
|
||||||
new | only
|
new
|
||||||
g:Vim9tagFuncArgs = []
|
g:Vim9tagFuncArgs = []
|
||||||
assert_fails('tag a10', 'E433:')
|
assert_fails('tag a10', 'E433:')
|
||||||
assert_equal([60, 'a10', '', {}], g:Vim9tagFuncArgs)
|
assert_equal([60, 'a10', '', {}], g:Vim9tagFuncArgs)
|
||||||
|
|
||||||
|
# Test for using a global function name
|
||||||
|
&tagfunc = g:TagFunc2
|
||||||
|
new
|
||||||
|
g:TagFunc2Args = []
|
||||||
|
assert_fails('tag a11', 'E433:')
|
||||||
|
assert_equal(['a11', '', {}], g:TagFunc2Args)
|
||||||
|
bw!
|
||||||
|
|
||||||
|
# Test for using a script-local function name
|
||||||
|
def s:LocalTagFunc(pat: string, flags: string, info: dict<any> ): any
|
||||||
|
g:LocalTagFuncArgs = [pat, flags, info]
|
||||||
|
return null
|
||||||
|
enddef
|
||||||
|
&tagfunc = s:LocalTagFunc
|
||||||
|
new
|
||||||
|
g:LocalTagFuncArgs = []
|
||||||
|
assert_fails('tag a12', 'E433:')
|
||||||
|
assert_equal(['a12', '', {}], g:LocalTagFuncArgs)
|
||||||
|
bw!
|
||||||
END
|
END
|
||||||
call CheckScriptSuccess(lines)
|
call CheckScriptSuccess(lines)
|
||||||
|
|
||||||
@@ -344,13 +389,4 @@ func Test_tagfunc_callback()
|
|||||||
%bw!
|
%bw!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_set_tagfunc_on_cmdline()
|
|
||||||
CheckScreendump
|
|
||||||
|
|
||||||
let buf = RunVimInTerminal(' +"set tagfunc=s:Func"', #{rows: 6, wait_for_ruler: 0})
|
|
||||||
call VerifyScreenDump(buf, 'Test_set_tagfunc_on_cmdline', {})
|
|
||||||
call StopVimInTerminal(buf)
|
|
||||||
endfunc
|
|
||||||
|
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
@@ -749,6 +749,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
3838,
|
||||||
/**/
|
/**/
|
||||||
3837,
|
3837,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user