Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reset s:is_wsl after calling (un)install #1628

Merged
merged 1 commit into from
Aug 4, 2024

Conversation

xudyang1
Copy link
Contributor

@xudyang1 xudyang1 commented Jul 27, 2024

The behaviors of firenvim#install and firenvim#uninstall on WSL are controlled by the script variable s:is_wsl: we initialize it to false to (un)install firenvim on wsl side, and then set it to 1 to (un)install on windows host side.

Currently, only firenvim#install and firenvim#uninstall changes the value of s:is_wsl. The two function do not reset s:is_wsl, and thus s:is_wsl is always 1 after calling them.

As a result, doing the followings sequentially in neovim have unexpected results:

-- 1. `s:is_wsl` is set to 1
vim.fn["firenvim#install"](0)

-- 2. uninstall firenvim only on windows host because `s:is_wsl` is 1
vim.fn["firenvim#uninstall"]()
-- 1. `s:is_wsl` is set to 1
vim.fn["firenvim#uninstall"]()
-- 2. reinstall, installs scripts on host only, no scripts on WSL
vim.fn["firenvim#install"](0)

To fix this, a try ... finally block resets s:is_wsl even if the two functions throw errors or run unsuccessfully.

@xudyang1 xudyang1 force-pushed the fix/reset_wsl_state branch 2 times, most recently from 33e9d73 to 2703425 Compare July 28, 2024 20:11
autoload/firenvim.vim Outdated Show resolved Hide resolved
The behaviors of `firenvim#install` and `firenvim#uninstall` on WSL is
controlled by the script variable `s:is_wsl`: we initialize it to false
to (un)install firenvim on wsl side, and then set it to 1 to (un)install
on windows host side.

Currently, only `firenvim#install` and `firenvim#uninstall` changes the
value of `s:is_wsl`. The two function do not reset `s:is_wsl`, and thus
`s:is_wsl` is always 1 after calling them.

As a result, doing the followings sequentially in neovim have unexpected
results:

```lua
-- 1. `s:is_wsl` is set to 1
vim.fn["firenvim#install"](0)

-- 2. uninstall firenvim only on windows host because `s:is_wsl` is 1
vim.fn["firenvim#uninstall"]()
```

```lua
-- 1. `s:is_wsl` is set to 1
vim.fn["firenvim#uninstall"]()
-- 2. reinstall, installs scripts on host only, no scripts on WSL
vim.fn["firenvim#install"](0)
```

To fix this, a `try ... finally` block resets `s:is_wsl` even
if the two functions throw errors or run unsuccessfully.
@glacambre
Copy link
Owner

Thanks! Sorry for the late merge - I'm a bit distracted.

@glacambre glacambre merged commit bb70728 into glacambre:master Aug 4, 2024
17 of 18 checks passed
@xudyang1
Copy link
Contributor Author

xudyang1 commented Aug 6, 2024

Thanks! Sorry for the late merge - I'm a bit distracted.

No worries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants