mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
api/vim: Fix nvim_list_runtimepaths
It used to 1. Always omit last component in runtimepath. 2. Always omit trailing empty item and leave uninitialized memory in place of it.
This commit is contained in:
parent
9cc10c69f2
commit
a5a5c83608
@ -299,7 +299,7 @@ ArrayOf(String) nvim_list_runtime_paths(void)
|
|||||||
FUNC_API_SINCE(1)
|
FUNC_API_SINCE(1)
|
||||||
{
|
{
|
||||||
Array rv = ARRAY_DICT_INIT;
|
Array rv = ARRAY_DICT_INIT;
|
||||||
uint8_t *rtp = p_rtp;
|
char_u *rtp = p_rtp;
|
||||||
|
|
||||||
if (*rtp == NUL) {
|
if (*rtp == NUL) {
|
||||||
// No paths
|
// No paths
|
||||||
@ -313,13 +313,14 @@ ArrayOf(String) nvim_list_runtime_paths(void)
|
|||||||
}
|
}
|
||||||
rtp++;
|
rtp++;
|
||||||
}
|
}
|
||||||
|
rv.size++;
|
||||||
|
|
||||||
// Allocate memory for the copies
|
// Allocate memory for the copies
|
||||||
rv.items = xmalloc(sizeof(Object) * rv.size);
|
rv.items = xmalloc(sizeof(*rv.items) * rv.size);
|
||||||
// Reset the position
|
// Reset the position
|
||||||
rtp = p_rtp;
|
rtp = p_rtp;
|
||||||
// Start copying
|
// Start copying
|
||||||
for (size_t i = 0; i < rv.size && *rtp != NUL; i++) {
|
for (size_t i = 0; i < rv.size; i++) {
|
||||||
rv.items[i].type = kObjectTypeString;
|
rv.items[i].type = kObjectTypeString;
|
||||||
rv.items[i].data.string.data = xmalloc(MAXPATHL);
|
rv.items[i].data.string.data = xmalloc(MAXPATHL);
|
||||||
// Copy the path from 'runtimepath' to rv.items[i]
|
// Copy the path from 'runtimepath' to rv.items[i]
|
||||||
@ -708,7 +709,7 @@ void nvim_unsubscribe(uint64_t channel_id, String event)
|
|||||||
Integer nvim_get_color_by_name(String name)
|
Integer nvim_get_color_by_name(String name)
|
||||||
FUNC_API_SINCE(1)
|
FUNC_API_SINCE(1)
|
||||||
{
|
{
|
||||||
return name_to_color((uint8_t *)name.data);
|
return name_to_color((char_u *)name.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary nvim_get_color_map(void)
|
Dictionary nvim_get_color_map(void)
|
||||||
@ -859,7 +860,7 @@ static void write_msg(String message, bool to_err)
|
|||||||
#define PUSH_CHAR(i, pos, line_buf, msg) \
|
#define PUSH_CHAR(i, pos, line_buf, msg) \
|
||||||
if (message.data[i] == NL || pos == LINE_BUFFER_SIZE - 1) { \
|
if (message.data[i] == NL || pos == LINE_BUFFER_SIZE - 1) { \
|
||||||
line_buf[pos] = NUL; \
|
line_buf[pos] = NUL; \
|
||||||
msg((uint8_t *)line_buf); \
|
msg((char_u *)line_buf); \
|
||||||
pos = 0; \
|
pos = 0; \
|
||||||
continue; \
|
continue; \
|
||||||
} \
|
} \
|
||||||
|
@ -327,11 +327,11 @@ describe('api', function()
|
|||||||
{'nvim_get_mode', {}},
|
{'nvim_get_mode', {}},
|
||||||
{'nvim_eval', {'1'}},
|
{'nvim_eval', {'1'}},
|
||||||
}
|
}
|
||||||
eq({{{mode='n', blocking=false},
|
eq({ { {mode='n', blocking=false},
|
||||||
13,
|
13,
|
||||||
{mode='n', blocking=false}, -- TODO: should be blocked=true
|
{mode='n', blocking=false}, -- TODO: should be blocked=true
|
||||||
1},
|
1 },
|
||||||
NIL}, meths.call_atomic(req))
|
NIL}, meths.call_atomic(req))
|
||||||
eq({mode='r', blocking=true}, nvim("get_mode"))
|
eq({mode='r', blocking=true}, nvim("get_mode"))
|
||||||
end)
|
end)
|
||||||
-- TODO: bug #6166
|
-- TODO: bug #6166
|
||||||
@ -588,6 +588,36 @@ describe('api', function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('list_runtime_paths', function()
|
||||||
|
it('returns nothing with empty &runtimepath', function()
|
||||||
|
meths.set_option('runtimepath', '')
|
||||||
|
eq({}, meths.list_runtime_paths())
|
||||||
|
end)
|
||||||
|
it('returns single runtimepath', function()
|
||||||
|
meths.set_option('runtimepath', 'a')
|
||||||
|
eq({'a'}, meths.list_runtime_paths())
|
||||||
|
end)
|
||||||
|
it('returns two runtimepaths', function()
|
||||||
|
meths.set_option('runtimepath', 'a,b')
|
||||||
|
eq({'a', 'b'}, meths.list_runtime_paths())
|
||||||
|
end)
|
||||||
|
it('returns empty strings when appropriate', function()
|
||||||
|
meths.set_option('runtimepath', 'a,,b')
|
||||||
|
eq({'a', '', 'b'}, meths.list_runtime_paths())
|
||||||
|
meths.set_option('runtimepath', ',a,b')
|
||||||
|
eq({'', 'a', 'b'}, meths.list_runtime_paths())
|
||||||
|
meths.set_option('runtimepath', 'a,b,')
|
||||||
|
eq({'a', 'b', ''}, meths.list_runtime_paths())
|
||||||
|
end)
|
||||||
|
it('truncates too long paths', function()
|
||||||
|
local long_path = ('/a'):rep(8192)
|
||||||
|
meths.set_option('runtimepath', long_path)
|
||||||
|
local paths_list = meths.list_runtime_paths()
|
||||||
|
neq({long_path}, paths_list)
|
||||||
|
eq({long_path:sub(1, #(paths_list[1]))}, paths_list)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
it('can throw exceptions', function()
|
it('can throw exceptions', function()
|
||||||
local status, err = pcall(nvim, 'get_option', 'invalid-option')
|
local status, err = pcall(nvim, 'get_option', 'invalid-option')
|
||||||
eq(false, status)
|
eq(false, status)
|
||||||
|
Loading…
Reference in New Issue
Block a user