mirror of
https://github.com/neovim/neovim
synced 2025-07-18 10:11:50 +00:00
Merge #9666 'Fix completion of multibyte env var names'
This commit is contained in:
@ -150,28 +150,47 @@ int os_unsetenv(const char *name)
|
|||||||
|
|
||||||
char *os_getenvname_at_index(size_t index)
|
char *os_getenvname_at_index(size_t index)
|
||||||
{
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
// Check if index is inside the environ array and is not the last element.
|
||||||
|
for (size_t i = 0; i <= index; i++) {
|
||||||
|
if (_wenviron[i] == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wchar_t *utf16_str = _wenviron[index];
|
||||||
|
char *utf8_str;
|
||||||
|
int conversion_result = utf16_to_utf8(utf16_str, &utf8_str);
|
||||||
|
if (conversion_result != 0) {
|
||||||
|
EMSG2("utf16_to_utf8 failed: %d", conversion_result);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
size_t namesize = 0;
|
||||||
|
while (utf8_str[namesize] != '=' && utf8_str[namesize] != NUL) {
|
||||||
|
namesize++;
|
||||||
|
}
|
||||||
|
char *name = (char *)vim_strnsave((char_u *)utf8_str, namesize);
|
||||||
|
xfree(utf8_str);
|
||||||
|
return name;
|
||||||
|
#else
|
||||||
# if defined(HAVE__NSGETENVIRON)
|
# if defined(HAVE__NSGETENVIRON)
|
||||||
char **environ = *_NSGetEnviron();
|
char **environ = *_NSGetEnviron();
|
||||||
# elif !defined(__WIN32__)
|
# else
|
||||||
// Borland C++ 5.2 has this in a header file.
|
|
||||||
extern char **environ;
|
extern char **environ;
|
||||||
# endif
|
# endif
|
||||||
// check if index is inside the environ array
|
// Check if index is inside the environ array and is not the last element.
|
||||||
for (size_t i = 0; i < index; i++) {
|
for (size_t i = 0; i <= index; i++) {
|
||||||
if (environ[i] == NULL) {
|
if (environ[i] == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
char *str = environ[index];
|
char *str = environ[index];
|
||||||
if (str == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
size_t namesize = 0;
|
size_t namesize = 0;
|
||||||
while (str[namesize] != '=' && str[namesize] != NUL) {
|
while (str[namesize] != '=' && str[namesize] != NUL) {
|
||||||
namesize++;
|
namesize++;
|
||||||
}
|
}
|
||||||
char *name = (char *)vim_strnsave((char_u *)str, namesize);
|
char *name = (char *)vim_strnsave((char_u *)str, namesize);
|
||||||
return name;
|
return name;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the process ID of the Neovim process.
|
/// Get the process ID of the Neovim process.
|
||||||
@ -404,7 +423,7 @@ void expand_env_esc(char_u *restrict srcp,
|
|||||||
var = NULL;
|
var = NULL;
|
||||||
} else {
|
} else {
|
||||||
if (src[1] == '{') {
|
if (src[1] == '{') {
|
||||||
++tail;
|
tail++;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
*var = NUL;
|
*var = NUL;
|
||||||
|
@ -1104,7 +1104,7 @@ char *os_resolve_shortcut(const char *fname)
|
|||||||
if (hr == S_OK && wsz[0] != NUL) {
|
if (hr == S_OK && wsz[0] != NUL) {
|
||||||
const int conversion_result = utf16_to_utf8(wsz, &rfname);
|
const int conversion_result = utf16_to_utf8(wsz, &rfname);
|
||||||
if (conversion_result != 0) {
|
if (conversion_result != 0) {
|
||||||
EMSG2("utf16_to_utf8 failed: %s", uv_strerror(conversion_result));
|
EMSG2("utf16_to_utf8 failed: %d", conversion_result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3913,7 +3913,7 @@ abort_search:
|
|||||||
VIsual = t;
|
VIsual = t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -171,19 +171,21 @@ end)
|
|||||||
|
|
||||||
describe('command line completion', function()
|
describe('command line completion', function()
|
||||||
local screen
|
local screen
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
clear()
|
|
||||||
screen = Screen.new(40, 5)
|
screen = Screen.new(40, 5)
|
||||||
screen:attach()
|
screen:set_default_attr_ids({
|
||||||
screen:set_default_attr_ids({[1]={bold=true, foreground=Screen.colors.Blue}})
|
[1] = {bold = true, foreground = Screen.colors.Blue1},
|
||||||
|
[2] = {foreground = Screen.colors.Grey0, background = Screen.colors.Yellow},
|
||||||
|
[3] = {bold = true, reverse = true},
|
||||||
|
})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
after_each(function()
|
after_each(function()
|
||||||
os.remove('Xtest-functional-viml-compl-dir')
|
os.remove('Xtest-functional-viml-compl-dir')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('lists directories with empty PATH', function()
|
it('lists directories with empty PATH', function()
|
||||||
|
clear()
|
||||||
|
screen:attach()
|
||||||
local tmp = funcs.tempname()
|
local tmp = funcs.tempname()
|
||||||
command('e '.. tmp)
|
command('e '.. tmp)
|
||||||
command('cd %:h')
|
command('cd %:h')
|
||||||
@ -198,6 +200,24 @@ describe('command line completion', function()
|
|||||||
:!Xtest-functional-viml-compl-dir^ |
|
:!Xtest-functional-viml-compl-dir^ |
|
||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('completes (multibyte) env var names #9655', function()
|
||||||
|
clear({env={
|
||||||
|
['XTEST_1AaあB']='foo',
|
||||||
|
['XTEST_2']='bar',
|
||||||
|
}})
|
||||||
|
screen:attach()
|
||||||
|
command('set wildmode=full')
|
||||||
|
command('set wildmenu')
|
||||||
|
feed(':!echo $XTEST_<tab>')
|
||||||
|
screen:expect([[
|
||||||
|
|
|
||||||
|
{1:~ }|
|
||||||
|
{1:~ }|
|
||||||
|
{2:XTEST_1AaあB}{3: XTEST_2 }|
|
||||||
|
:!echo $XTEST_1AaあB^ |
|
||||||
|
]])
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('ui/ext_wildmenu', function()
|
describe('ui/ext_wildmenu', function()
|
||||||
|
Reference in New Issue
Block a user