aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-08-20 09:35:09 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-11-07 08:24:48 +0800
commit1508618d4c35dafee2b82726d2d27fae4e314386 (patch)
tree25f8ab47d771110f80356776f9a076ff6d09043b
parentb3e9010f4783a51407ec5a5ad9fda1216d4db3fe (diff)
downloadrneovim-1508618d4c35dafee2b82726d2d27fae4e314386.tar.gz
rneovim-1508618d4c35dafee2b82726d2d27fae4e314386.tar.bz2
rneovim-1508618d4c35dafee2b82726d2d27fae4e314386.zip
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) https://github.com/vim/vim/commit/05e59e3a9ffddbf93c7af02cd2ba1d0f822d4625 Omit Vim9 script in code and comment out in tests. Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
-rw-r--r--runtime/doc/options.txt10
-rw-r--r--src/nvim/insexpand.c6
-rw-r--r--src/nvim/testdir/test_tagfunc.vim107
3 files changed, 108 insertions, 15 deletions
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index 883585116d..a14dc1b99e 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -320,7 +320,15 @@ or a function reference or a lambda function. Examples:
set opfunc=MyOpFunc
set opfunc=function('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
diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c
index 9f4c02da19..7ff4735480 100644
--- a/src/nvim/insexpand.c
+++ b/src/nvim/insexpand.c
@@ -2239,10 +2239,10 @@ static char_u *get_complete_funcname(int type)
}
}
-/// Execute user defined complete function 'completefunc' or 'omnifunc', and
-/// get matches in "matches".
+/// Execute user defined complete function 'completefunc', 'omnifunc' or
+/// '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)
{
list_T *matchlist = NULL;
diff --git a/src/nvim/testdir/test_tagfunc.vim b/src/nvim/testdir/test_tagfunc.vim
index 92c2f2d6a1..29ca69278d 100644
--- a/src/nvim/testdir/test_tagfunc.vim
+++ b/src/nvim/testdir/test_tagfunc.vim
@@ -124,32 +124,73 @@ func Test_tagfunc_callback()
let g:MytagFunc1_args = [a:pat, a:flags, a:info]
return v:null
endfunc
- let g:MytagFunc1_args = []
set tagfunc=function('MytagFunc1')
- call assert_fails('tag abc', 'E433:')
- call assert_equal(['abc', '', {}], g:MytagFunc1_args)
+ new | only
+ 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()
- new
func MytagFunc2(pat, flags, info)
let g:MytagFunc2_args = [a:pat, a:flags, a:info]
return v:null
endfunc
- let g:MytagFunc2_args = []
set tagfunc=funcref('MytagFunc2')
- call assert_fails('tag def', 'E433:')
- call assert_equal(['def', '', {}], g:MytagFunc2_args)
+ new | only
+ 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
- new
func MytagFunc3(pat, flags, info)
let g:MytagFunc3_args = [a:pat, a:flags, a:info]
return v:null
endfunc
+ set tagfunc={a,\ b,\ c\ ->\ MytagFunc3(a,\ b,\ c)}
+ new | only
let g:MytagFunc3_args = []
- let &tagfunc= '{a, b, c -> MytagFunc3(a, b, c)}'
- call assert_fails('tag ghi', 'E433:')
- call assert_equal(['ghi', '', {}], g:MytagFunc3_args)
+ call assert_fails('tag a15', 'E433:')
+ call assert_equal(['a15', '', {}], 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
set tagfunc=''
@@ -160,10 +201,54 @@ func Test_tagfunc_callback()
let &tagfunc = "{a -> 'abc'}"
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
delfunc MytagFunc1
delfunc MytagFunc2
delfunc MytagFunc3
+ set tagfunc&
%bw!
endfunc