mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 19:25:11 -07:00
Fix environment variable on Windows
Since uv_os_setenv uses SetEnvironmentVariableW, _wenviron is no updated. As a result, inconsistency occurs in completion of environment variable names. Change to use GetEnvironmentStaringsW instead of _wenviron to solve it.
This commit is contained in:
parent
299f32dc01
commit
24a56cca30
@ -151,25 +151,39 @@ int os_unsetenv(const char *name)
|
||||
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);
|
||||
wchar_t *env = GetEnvironmentStringsW();
|
||||
if (!env) {
|
||||
return NULL;
|
||||
}
|
||||
size_t namesize = 0;
|
||||
while (utf8_str[namesize] != '=' && utf8_str[namesize] != NUL) {
|
||||
namesize++;
|
||||
|
||||
// GetEnvironmentStrings return environment block of the following format:
|
||||
//
|
||||
// var1=value1\0var2=value2\0...varN=valueN\0\0
|
||||
//
|
||||
char *name = NULL;
|
||||
size_t current_index = 0;
|
||||
for (wchar_t *it = env; *it != L'\0' || *(it + 1) != L'\0'; it++) {
|
||||
if (index == current_index) {
|
||||
char *utf8_str;
|
||||
int conversion_result = utf16_to_utf8(it, &utf8_str);
|
||||
if (conversion_result != 0) {
|
||||
EMSG2("utf16_to_utf8 failed: %d", conversion_result);
|
||||
break;
|
||||
}
|
||||
size_t namesize = 0;
|
||||
while (utf8_str[namesize] != '=' && utf8_str[namesize] != NUL) {
|
||||
namesize++;
|
||||
}
|
||||
name = (char *)vim_strnsave((char_u *)utf8_str, namesize);
|
||||
xfree(utf8_str);
|
||||
break;
|
||||
}
|
||||
if (*it == L'\0') {
|
||||
current_index++;
|
||||
}
|
||||
}
|
||||
char *name = (char *)vim_strnsave((char_u *)utf8_str, namesize);
|
||||
xfree(utf8_str);
|
||||
|
||||
FreeEnvironmentStringsW(env);
|
||||
return name;
|
||||
#else
|
||||
# if defined(HAVE__NSGETENVIRON)
|
||||
|
@ -201,6 +201,22 @@ describe('command line completion', function()
|
||||
]])
|
||||
end)
|
||||
|
||||
it('completes env var names', function()
|
||||
clear()
|
||||
screen:attach()
|
||||
command('let $XTEST_1 = "foo" | let $XTEST_2 = "bar"')
|
||||
command('set wildmode=full')
|
||||
command('set wildmenu')
|
||||
feed(':!echo $XTEST_<tab>')
|
||||
screen:expect([[
|
||||
|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{2:XTEST_1}{3: XTEST_2 }|
|
||||
:!echo $XTEST_1^ |
|
||||
]])
|
||||
end)
|
||||
|
||||
it('completes (multibyte) env var names #9655', function()
|
||||
clear({env={
|
||||
['XTEST_1AaあB']='foo',
|
||||
|
Loading…
Reference in New Issue
Block a user