aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-04-15 19:50:23 +0800
committerzeertzjq <zeertzjq@outlook.com>2023-04-15 21:06:16 +0800
commitbcc971de15ed540356405f937d640eaffa4a03bb (patch)
treeebd853d8e81134cd7dad02ed4c7bd51849f8683b
parenteb151a9730f0000ff46e0b3467e29bb9f02ae362 (diff)
downloadrneovim-bcc971de15ed540356405f937d640eaffa4a03bb.tar.gz
rneovim-bcc971de15ed540356405f937d640eaffa4a03bb.tar.bz2
rneovim-bcc971de15ed540356405f937d640eaffa4a03bb.zip
vim-patch:9.0.0269: getscriptinfo() does not include the version
Problem: getscriptinfo() does not include the version. Cannot select entries by script name. Solution: Add the "version" item and the "name" argument. (Yegappan Lakshmanan, closes vim/vim#10962) https://github.com/vim/vim/commit/520f6ef60a59f7b5f3da9199999d13dbe817d3ce Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
-rw-r--r--runtime/doc/builtin.txt11
-rw-r--r--src/nvim/eval.lua2
-rw-r--r--src/nvim/runtime.c27
-rw-r--r--test/old/testdir/test_scriptnames.vim30
4 files changed, 63 insertions, 7 deletions
diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt
index 3c940ccfa2..e32cac7839 100644
--- a/runtime/doc/builtin.txt
+++ b/runtime/doc/builtin.txt
@@ -223,7 +223,7 @@ getreg([{regname} [, 1 [, {list}]]])
String or List contents of a register
getreginfo([{regname}]) Dict information about a register
getregtype([{regname}]) String type of a register
-getscriptinfo() List list of sourced scripts
+getscriptinfo([{opts}]) List list of sourced scripts
gettabinfo([{expr}]) List list of tab pages
gettabvar({nr}, {varname} [, {def}])
any variable {varname} in tab {nr} or {def}
@@ -3576,7 +3576,7 @@ getregtype([{regname}]) *getregtype()*
Can also be used as a |method|: >
GetRegname()->getregtype()
-getscriptinfo() *getscriptinfo()*
+getscriptinfo([{opts}]) *getscriptinfo()*
Returns a |List| with information about all the sourced Vim
scripts in the order they were sourced.
@@ -3585,6 +3585,13 @@ getscriptinfo() *getscriptinfo()*
autoload always set to FALSE.
name vim script file name.
sid script ID |<SID>|.
+ version vimscript version, always 1
+
+ The optional Dict argument {opts} supports the following
+ items:
+ name script name match pattern. If specified,
+ information about scripts with name
+ that match the pattern "name" are returned.
gettabinfo([{tabnr}]) *gettabinfo()*
If {tabnr} is not specified, then information about all the
diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua
index 66032adbaf..7dbfac80f3 100644
--- a/src/nvim/eval.lua
+++ b/src/nvim/eval.lua
@@ -189,7 +189,7 @@ return {
gettabinfo={args={0, 1}, base=1},
gettabvar={args={2, 3}, base=1},
gettabwinvar={args={3, 4}, base=1},
- getscriptinfo={},
+ getscriptinfo={args={0, 1}},
gettagstack={args={0, 1}, base=1},
gettext={args=1, base=1},
getwininfo={args={0, 1}, base=1},
diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c
index 1e39b58543..5bc63453c9 100644
--- a/src/nvim/runtime.c
+++ b/src/nvim/runtime.c
@@ -43,6 +43,7 @@
#include "nvim/os/stdpaths_defs.h"
#include "nvim/path.h"
#include "nvim/profile.h"
+#include "nvim/regexp.h"
#include "nvim/runtime.h"
#include "nvim/strings.h"
#include "nvim/usercmd.h"
@@ -2361,8 +2362,25 @@ void f_getscriptinfo(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
{
tv_list_alloc_ret(rettv, script_items.ga_len);
+ if (tv_check_for_opt_dict_arg(argvars, 0) == FAIL) {
+ return;
+ }
+
list_T *l = rettv->vval.v_list;
+ regmatch_T regmatch = {
+ .regprog = NULL,
+ .rm_ic = p_ic,
+ };
+
+ char *pat = NULL;
+ if (argvars[0].v_type == VAR_DICT) {
+ pat = tv_dict_get_string(argvars[0].vval.v_dict, "name", true);
+ if (pat != NULL) {
+ regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
+ }
+ }
+
for (int i = 1; i <= script_items.ga_len; i++) {
scriptitem_T *si = SCRIPT_ITEM(i);
@@ -2370,13 +2388,22 @@ void f_getscriptinfo(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
continue;
}
+ if (pat != NULL && regmatch.regprog != NULL
+ && !vim_regexec(&regmatch, si->sn_name, (colnr_T)0)) {
+ continue;
+ }
+
dict_T *d = tv_dict_alloc();
tv_list_append_dict(l, d);
tv_dict_add_str(d, S_LEN("name"), si->sn_name);
tv_dict_add_nr(d, S_LEN("sid"), i);
+ tv_dict_add_nr(d, S_LEN("version"), 1);
// Vim9 autoload script (:h vim9-autoload), not applicable to Nvim.
tv_dict_add_bool(d, S_LEN("autoload"), false);
}
+
+ vim_regfree(regmatch.regprog);
+ xfree(pat);
}
/// Get one full line from a sourced file.
diff --git a/test/old/testdir/test_scriptnames.vim b/test/old/testdir/test_scriptnames.vim
index 06ae305ab7..a04cce3b44 100644
--- a/test/old/testdir/test_scriptnames.vim
+++ b/test/old/testdir/test_scriptnames.vim
@@ -31,12 +31,34 @@ endfunc
" Test for the getscriptinfo() function
func Test_getscriptinfo()
- call writefile(['let loaded_script_id = expand("<SID>")'], 'Xscript')
- source Xscript
+ let lines =<< trim END
+ let g:loaded_script_id = expand("<SID>")
+ let s:XscriptVar = [1, #{v: 2}]
+ func s:XscriptFunc()
+ endfunc
+ END
+ call writefile(lines, 'X22script91')
+ source X22script91
let l = getscriptinfo()
- call assert_match('Xscript$', l[-1].name)
+ call assert_match('X22script91$', l[-1].name)
call assert_equal(g:loaded_script_id, $"<SNR>{l[-1].sid}_")
- call delete('Xscript')
+
+ let l = getscriptinfo({'name': '22script91'})
+ call assert_equal(1, len(l))
+ call assert_match('22script91$', l[0].name)
+
+ let l = getscriptinfo({'name': 'foobar'})
+ call assert_equal(0, len(l))
+ let l = getscriptinfo({'name': ''})
+ call assert_true(len(l) > 1)
+
+ call assert_fails("echo getscriptinfo({'name': []})", 'E730:')
+ call assert_fails("echo getscriptinfo({'name': '\\@'})", 'E866:')
+ let l = getscriptinfo({'name': v:_null_string})
+ call assert_true(len(l) > 1)
+ call assert_fails("echo getscriptinfo('foobar')", 'E1206:')
+
+ call delete('X22script91')
endfunc
" vim: shiftwidth=2 sts=2 expandtab