diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2020-01-25 13:29:52 +0100 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2020-02-07 09:22:55 +0100 |
commit | 7ce9a5c7da0fb5d6117cf9526c39e01faf7e908d (patch) | |
tree | 79dbef5225a1e09dcef257d0992ec8b9e4724190 | |
parent | 405f49a9b16c5668a033b8be959564abc5f852ba (diff) | |
download | rneovim-7ce9a5c7da0fb5d6117cf9526c39e01faf7e908d.tar.gz rneovim-7ce9a5c7da0fb5d6117cf9526c39e01faf7e908d.tar.bz2 rneovim-7ce9a5c7da0fb5d6117cf9526c39e01faf7e908d.zip |
api: add nvim_get_runtime_file for finding runtime files
-rwxr-xr-x | src/clint.py | 6 | ||||
-rw-r--r-- | src/nvim/api/vim.c | 29 | ||||
-rw-r--r-- | test/functional/api/vim_spec.lua | 24 |
3 files changed, 58 insertions, 1 deletions
diff --git a/src/clint.py b/src/clint.py index 675b67ccef..12bada6aac 100755 --- a/src/clint.py +++ b/src/clint.py @@ -270,6 +270,8 @@ _line_length = 80 # This is set by --extensions flag. _valid_extensions = set(['c', 'h']) +_RE_COMMENTLINE = re.compile(r'^\s*//') + def ParseNolintSuppressions(filename, raw_line, linenum, error): """Updates the global list of error-suppressions. @@ -1358,7 +1360,9 @@ def CheckForOldStyleComments(filename, line, linenum, error): linenum: The number of the line to check. error: The function to call with any errors found. """ - if line.find('/*') >= 0 and line[-1] != '\\': + # hack: allow /* inside comment line. Could be extended to allow them inside + # any // comment. + if line.find('/*') >= 0 and line[-1] != '\\' and not _RE_COMMENTLINE.match(line): error(filename, linenum, 'readability/old_style_comment', 5, '/*-style comment found, it should be replaced with //-style. ' '/*-style comments are only allowed inside macros. ' diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 9c58ce853b..29ec0207ba 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -703,6 +703,35 @@ ArrayOf(String) nvim_list_runtime_paths(void) return rv; } +/// Find files in runtime directories +/// +/// 'name' can contain wildcards. For example +/// nvim_get_runtime_file("colors/*.vim", true) will return all color +/// scheme files. +/// +/// It is not an error to not find any files. An empty array is returned then. +/// +/// @param name pattern of files to search for +/// @param all whether to return all matches or only the first +/// @return list of absolute paths to the found files +ArrayOf(String) nvim_get_runtime_file(String name, Boolean all) + FUNC_API_SINCE(7) +{ + Array rv = ARRAY_DICT_INIT; + if (!name.data) { + return rv; + } + int flags = DIP_START | (all ? DIP_ALL : 0); + do_in_runtimepath((char_u *)name.data, flags, find_runtime_cb, &rv); + return rv; +} + +static void find_runtime_cb(char_u *fname, void *cookie) +{ + Array *rv = (Array *)cookie; + ADD(*rv, STRING_OBJ(cstr_to_string((char *)fname))); +} + /// Changes the global working directory. /// /// @param dir Directory path diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index d901a5e2eb..fb3755cb8e 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -23,6 +23,7 @@ local pcall_err = helpers.pcall_err local format_string = helpers.format_string local intchar2lua = helpers.intchar2lua local mergedicts_copy = helpers.mergedicts_copy +local endswith = helpers.endswith describe('API', function() before_each(clear) @@ -1853,4 +1854,27 @@ describe('API', function() command('silent! call nvim_create_buf(0, 1)') end) end) + + describe('nvim_get_runtime_file', function() + it('works', function() + eq({}, meths.get_runtime_file("bork.borkbork", false)) + eq({}, meths.get_runtime_file("bork.borkbork", true)) + eq(1, #meths.get_runtime_file("autoload/msgpack.vim", false)) + eq(1, #meths.get_runtime_file("autoload/msgpack.vim", true)) + local val = meths.get_runtime_file("autoload/remote/*.vim", true) + eq(2, #val) + local p = helpers.alter_slashes + if endswith(val[1], "define.vim") then + ok(endswith(val[1], p("autoload/remote/define.vim"))) + ok(endswith(val[2], p("autoload/remote/host.vim"))) + else + ok(endswith(val[1], p("autoload/remote/host.vim"))) + ok(endswith(val[2], p("autoload/remote/define.vim"))) + end + val = meths.get_runtime_file("autoload/remote/*.vim", false) + eq(1, #val) + ok(endswith(val[1], p("autoload/remote/define.vim")) + or endswith(val[1], p("autoload/remote/host.vim"))) + end) + end) end) |