mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:8.2.3712: cannot use Vim9 lambda for 'tagfunc'
Problem: Cannot use Vim9 lambda for 'tagfunc'.
Solution: Make it work, add more tests. (Yegappan Lakshmanan, closes vim/vim#9250)
05e59e3a9f
Omit Vim9 script in code and comment out in tests.
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
parent
b3e9010f47
commit
1508618d4c
@ -320,7 +320,15 @@ or a function reference or a lambda function. Examples:
|
|||||||
set opfunc=MyOpFunc
|
set opfunc=MyOpFunc
|
||||||
set opfunc=function('MyOpFunc')
|
set opfunc=function('MyOpFunc')
|
||||||
set opfunc=funcref('MyOpFunc')
|
set opfunc=funcref('MyOpFunc')
|
||||||
let &opfunc = "{t -> MyOpFunc(t)}"
|
set opfunc={a\ ->\ MyOpFunc(a)}
|
||||||
|
" set using a funcref variable
|
||||||
|
let Fn = function('MyTagFunc')
|
||||||
|
let &tagfunc = string(Fn)
|
||||||
|
" set using a lambda expression
|
||||||
|
let &tagfunc = "{t -> MyTagFunc(t)}"
|
||||||
|
" set using a variable with lambda expression
|
||||||
|
let L = {a, b, c -> MyTagFunc(a, b , c)}
|
||||||
|
let &tagfunc = string(L)
|
||||||
<
|
<
|
||||||
|
|
||||||
Setting the filetype
|
Setting the filetype
|
||||||
|
@ -2239,10 +2239,10 @@ static char_u *get_complete_funcname(int type)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Execute user defined complete function 'completefunc' or 'omnifunc', and
|
/// Execute user defined complete function 'completefunc', 'omnifunc' or
|
||||||
/// get matches in "matches".
|
/// 'thesaurusfunc', and get matches in "matches".
|
||||||
///
|
///
|
||||||
/// @param type CTRL_X_OMNI or CTRL_X_FUNCTION
|
/// @param type either CTRL_X_OMNI or CTRL_X_FUNCTION or CTRL_X_THESAURUS
|
||||||
static void expand_by_function(int type, char_u *base)
|
static void expand_by_function(int type, char_u *base)
|
||||||
{
|
{
|
||||||
list_T *matchlist = NULL;
|
list_T *matchlist = NULL;
|
||||||
|
@ -124,32 +124,73 @@ func Test_tagfunc_callback()
|
|||||||
let g:MytagFunc1_args = [a:pat, a:flags, a:info]
|
let g:MytagFunc1_args = [a:pat, a:flags, a:info]
|
||||||
return v:null
|
return v:null
|
||||||
endfunc
|
endfunc
|
||||||
let g:MytagFunc1_args = []
|
|
||||||
set tagfunc=function('MytagFunc1')
|
set tagfunc=function('MytagFunc1')
|
||||||
call assert_fails('tag abc', 'E433:')
|
new | only
|
||||||
call assert_equal(['abc', '', {}], g:MytagFunc1_args)
|
let g:MytagFunc1_args = []
|
||||||
|
call assert_fails('tag a11', 'E433:')
|
||||||
|
call assert_equal(['a11', '', {}], g:MytagFunc1_args)
|
||||||
|
|
||||||
|
" Using a funcref variable to set 'tagfunc'
|
||||||
|
let Fn = function('MytagFunc1')
|
||||||
|
let &tagfunc = string(Fn)
|
||||||
|
new | only
|
||||||
|
let g:MytagFunc1_args = []
|
||||||
|
call assert_fails('tag a12', 'E433:')
|
||||||
|
call assert_equal(['a12', '', {}], g:MytagFunc1_args)
|
||||||
|
call assert_fails('let &tagfunc = Fn', 'E729:')
|
||||||
|
|
||||||
" Test for using a funcref()
|
" Test for using a funcref()
|
||||||
new
|
|
||||||
func MytagFunc2(pat, flags, info)
|
func MytagFunc2(pat, flags, info)
|
||||||
let g:MytagFunc2_args = [a:pat, a:flags, a:info]
|
let g:MytagFunc2_args = [a:pat, a:flags, a:info]
|
||||||
return v:null
|
return v:null
|
||||||
endfunc
|
endfunc
|
||||||
let g:MytagFunc2_args = []
|
|
||||||
set tagfunc=funcref('MytagFunc2')
|
set tagfunc=funcref('MytagFunc2')
|
||||||
call assert_fails('tag def', 'E433:')
|
new | only
|
||||||
call assert_equal(['def', '', {}], g:MytagFunc2_args)
|
let g:MytagFunc2_args = []
|
||||||
|
call assert_fails('tag a13', 'E433:')
|
||||||
|
call assert_equal(['a13', '', {}], g:MytagFunc2_args)
|
||||||
|
|
||||||
|
" Using a funcref variable to set 'tagfunc'
|
||||||
|
let Fn = funcref('MytagFunc2')
|
||||||
|
let &tagfunc = string(Fn)
|
||||||
|
new | only
|
||||||
|
let g:MytagFunc2_args = []
|
||||||
|
call assert_fails('tag a14', 'E433:')
|
||||||
|
call assert_equal(['a14', '', {}], g:MytagFunc2_args)
|
||||||
|
call assert_fails('let &tagfunc = Fn', 'E729:')
|
||||||
|
|
||||||
" Test for using a lambda function
|
" Test for using a lambda function
|
||||||
new
|
|
||||||
func MytagFunc3(pat, flags, info)
|
func MytagFunc3(pat, flags, info)
|
||||||
let g:MytagFunc3_args = [a:pat, a:flags, a:info]
|
let g:MytagFunc3_args = [a:pat, a:flags, a:info]
|
||||||
return v:null
|
return v:null
|
||||||
endfunc
|
endfunc
|
||||||
|
set tagfunc={a,\ b,\ c\ ->\ MytagFunc3(a,\ b,\ c)}
|
||||||
|
new | only
|
||||||
let g:MytagFunc3_args = []
|
let g:MytagFunc3_args = []
|
||||||
let &tagfunc= '{a, b, c -> MytagFunc3(a, b, c)}'
|
call assert_fails('tag a15', 'E433:')
|
||||||
call assert_fails('tag ghi', 'E433:')
|
call assert_equal(['a15', '', {}], g:MytagFunc3_args)
|
||||||
call assert_equal(['ghi', '', {}], g:MytagFunc3_args)
|
|
||||||
|
" Set 'tagfunc' to a lambda expression
|
||||||
|
let &tagfunc = '{a, b, c -> MytagFunc3(a, b, c)}'
|
||||||
|
new | only
|
||||||
|
let g:MytagFunc3_args = []
|
||||||
|
call assert_fails('tag a16', 'E433:')
|
||||||
|
call assert_equal(['a16', '', {}], g:MytagFunc3_args)
|
||||||
|
|
||||||
|
" Set 'tagfunc' to a variable with a lambda expression
|
||||||
|
let Lambda = {a, b, c -> MytagFunc3(a, b, c)}
|
||||||
|
let &tagfunc = string(Lambda)
|
||||||
|
new | only
|
||||||
|
let g:MytagFunc3_args = []
|
||||||
|
call assert_fails("tag a17", "E433:")
|
||||||
|
call assert_equal(['a17', '', {}], g:MytagFunc3_args)
|
||||||
|
call assert_fails('let &tagfunc = Lambda', 'E729:')
|
||||||
|
|
||||||
|
" Test for using a lambda function with incorrect return value
|
||||||
|
let Lambda = {s -> strlen(s)}
|
||||||
|
let &tagfunc = string(Lambda)
|
||||||
|
new | only
|
||||||
|
call assert_fails("tag a17", "E987:")
|
||||||
|
|
||||||
" Test for clearing the 'tagfunc' option
|
" Test for clearing the 'tagfunc' option
|
||||||
set tagfunc=''
|
set tagfunc=''
|
||||||
@ -160,10 +201,54 @@ func Test_tagfunc_callback()
|
|||||||
let &tagfunc = "{a -> 'abc'}"
|
let &tagfunc = "{a -> 'abc'}"
|
||||||
call assert_fails("echo taglist('a')", "E987:")
|
call assert_fails("echo taglist('a')", "E987:")
|
||||||
|
|
||||||
|
" Vim9 tests
|
||||||
|
let lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
|
||||||
|
# Test for using function()
|
||||||
|
def MytagFunc1(pat: string, flags: string, info: dict<any>): any
|
||||||
|
g:MytagFunc1_args = [pat, flags, info]
|
||||||
|
return null
|
||||||
|
enddef
|
||||||
|
set tagfunc=function('MytagFunc1')
|
||||||
|
new | only
|
||||||
|
g:MytagFunc1_args = []
|
||||||
|
assert_fails('tag a10', 'E433:')
|
||||||
|
assert_equal(['a10', '', {}], g:MytagFunc1_args)
|
||||||
|
|
||||||
|
# Test for using a lambda
|
||||||
|
def MytagFunc2(pat: string, flags: string, info: dict<any>): any
|
||||||
|
g:MytagFunc2_args = [pat, flags, info]
|
||||||
|
return null
|
||||||
|
enddef
|
||||||
|
&tagfunc = '(a, b, c) => MytagFunc2(a, b, c)'
|
||||||
|
new | only
|
||||||
|
g:MytagFunc2_args = []
|
||||||
|
assert_fails('tag a20', 'E433:')
|
||||||
|
assert_equal(['a20', '', {}], g:MytagFunc2_args)
|
||||||
|
|
||||||
|
# Test for using a variable with a lambda expression
|
||||||
|
var Fn: func = (a, b, c) => MytagFunc2(a, b, c)
|
||||||
|
&tagfunc = string(Fn)
|
||||||
|
new | only
|
||||||
|
g:MytagFunc2_args = []
|
||||||
|
assert_fails('tag a30', 'E433:')
|
||||||
|
assert_equal(['a30', '', {}], g:MytagFunc2_args)
|
||||||
|
END
|
||||||
|
" call CheckScriptSuccess(lines)
|
||||||
|
|
||||||
|
" Using Vim9 lambda expression in legacy context should fail
|
||||||
|
" set tagfunc=(a,\ b,\ c)\ =>\ g:MytagFunc2(a,\ b,\ c)
|
||||||
|
" new | only
|
||||||
|
" let g:MytagFunc3_args = []
|
||||||
|
" call assert_fails("tag a17", "E117:")
|
||||||
|
" call assert_equal([], g:MytagFunc3_args)
|
||||||
|
|
||||||
" cleanup
|
" cleanup
|
||||||
delfunc MytagFunc1
|
delfunc MytagFunc1
|
||||||
delfunc MytagFunc2
|
delfunc MytagFunc2
|
||||||
delfunc MytagFunc3
|
delfunc MytagFunc3
|
||||||
|
set tagfunc&
|
||||||
%bw!
|
%bw!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user