mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 22:18:33 +00:00
Don't show entire context when completing
This commit is contained in:
@@ -1292,7 +1292,7 @@ static void nlua_add_treesitter(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
|
||||
lua_setfield(lstate, -2, "_ts_parse_query");
|
||||
}
|
||||
|
||||
int nlua_expand_pat(char_u *pat, int *num_results, char_u ***results)
|
||||
int nlua_expand_pat(expand_T *xp, char_u *pat, int *num_results, char_u ***results)
|
||||
{
|
||||
lua_State *const lstate = nlua_enter();
|
||||
int ret = OK;
|
||||
@@ -1307,10 +1307,11 @@ int nlua_expand_pat(char_u *pat, int *num_results, char_u ***results)
|
||||
// [ vim, vim._log_keystroke, buf ]
|
||||
lua_pushlstring(lstate, (const char *)pat, STRLEN(pat));
|
||||
|
||||
if (lua_pcall(lstate, 1, 1, 0)) {
|
||||
if (lua_pcall(lstate, 1, 2, 0) != 0) {
|
||||
nlua_error(
|
||||
lstate,
|
||||
_("Error executing vim._expand_pat: %.*s"));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
Error err = ERROR_INIT;
|
||||
@@ -1318,12 +1319,18 @@ int nlua_expand_pat(char_u *pat, int *num_results, char_u ***results)
|
||||
*num_results = 0;
|
||||
*results = NULL;
|
||||
|
||||
Array completions = nlua_pop_Array(lstate, &err);
|
||||
int prefix_len = (int)nlua_pop_Integer(lstate, &err);
|
||||
if (ERROR_SET(&err)) {
|
||||
ret = FAIL;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
Array completions = nlua_pop_Array(lstate, &err);
|
||||
if (ERROR_SET(&err)) {
|
||||
ret = FAIL;
|
||||
goto cleanup_array;
|
||||
}
|
||||
|
||||
garray_T result_array;
|
||||
ga_init(&result_array, (int)sizeof(char *), 80);
|
||||
for (size_t i = 0; i < completions.size; i++) {
|
||||
@@ -1331,7 +1338,7 @@ int nlua_expand_pat(char_u *pat, int *num_results, char_u ***results)
|
||||
|
||||
if (v.type != kObjectTypeString) {
|
||||
ret = FAIL;
|
||||
goto cleanup;
|
||||
goto cleanup_array;
|
||||
}
|
||||
|
||||
GA_APPEND(
|
||||
@@ -1340,12 +1347,15 @@ int nlua_expand_pat(char_u *pat, int *num_results, char_u ***results)
|
||||
vim_strsave((char_u *)v.data.string.data));
|
||||
}
|
||||
|
||||
xp->xp_pattern += prefix_len;
|
||||
*results = result_array.ga_data;
|
||||
*num_results = result_array.ga_len;
|
||||
|
||||
cleanup:
|
||||
cleanup_array:
|
||||
api_free_array(completions);
|
||||
|
||||
cleanup:
|
||||
|
||||
if (ret == FAIL) {
|
||||
ga_clear(&result_array);
|
||||
}
|
||||
|
@@ -547,7 +547,7 @@ function vim._expand_pat(pat, env)
|
||||
if pat == '' then
|
||||
local result = vim.tbl_keys(env)
|
||||
table.sort(result)
|
||||
return result
|
||||
return result, 0
|
||||
end
|
||||
|
||||
-- TODO: We can handle spaces in [] ONLY.
|
||||
@@ -558,7 +558,7 @@ function vim._expand_pat(pat, env)
|
||||
|
||||
-- Get the last part of the pattern
|
||||
local last_part = pat:match("[%w.:_%[%]'\"]+$")
|
||||
if not last_part then return {} end
|
||||
if not last_part then return {}, 0 end
|
||||
|
||||
local parts, search_index = vim._expand_pat_get_parts(last_part)
|
||||
|
||||
@@ -568,11 +568,11 @@ function vim._expand_pat(pat, env)
|
||||
local final_env = env
|
||||
for _, part in ipairs(parts) do
|
||||
if type(final_env) ~= 'table' then
|
||||
return {}
|
||||
return {}, 0
|
||||
end
|
||||
|
||||
-- Normally, we just have a string
|
||||
-- Just attempt to get the string directly from the environment
|
||||
-- Just attempt to get the string directly from the environment
|
||||
if type(part) == "string" then
|
||||
final_env = rawget(final_env, part)
|
||||
else
|
||||
@@ -584,32 +584,32 @@ function vim._expand_pat(pat, env)
|
||||
-- -> _G[MY_VAR] -> "api"
|
||||
local result_key = part[1]
|
||||
if not result_key then
|
||||
return {}
|
||||
return {}, 0
|
||||
end
|
||||
|
||||
local result = rawget(env, result_key)
|
||||
|
||||
if result == nil then
|
||||
return {}
|
||||
return {}, 0
|
||||
end
|
||||
|
||||
final_env = rawget(final_env, result)
|
||||
end
|
||||
|
||||
if not final_env then
|
||||
return {}
|
||||
return {}, 0
|
||||
end
|
||||
end
|
||||
|
||||
local result = vim.tbl_map(function(v)
|
||||
return prefix_match_pat .. v
|
||||
return v
|
||||
end, vim.tbl_filter(function(name)
|
||||
return string.find(name, match_pat) ~= nil
|
||||
end, vim.tbl_keys(final_env)))
|
||||
|
||||
table.sort(result)
|
||||
|
||||
return result
|
||||
return result, #prefix_match_pat
|
||||
end
|
||||
|
||||
vim._expand_pat_get_parts = function(lua_string)
|
||||
|
Reference in New Issue
Block a user