Skip to content

fix(cmdline): prevent hangs from shellcmd completion on win32/wsl#1933

Merged
saghen merged 1 commit intomainfrom
fix/cmdline-wsl
Jun 23, 2025
Merged

fix(cmdline): prevent hangs from shellcmd completion on win32/wsl#1933
saghen merged 1 commit intomainfrom
fix/cmdline-wsl

Conversation

@soifou
Copy link
Collaborator

@soifou soifou commented Jun 20, 2025

This change makes the previous attempt to disable shell completion in Windows environments more robust:

  • Handles both Windows and WSL, instead of only targeting Windows.
  • Handles all shellcmd completions, e.g. :term, not just the :! command.
  • Instead of disabling shellcmd completions entirely, temporarily remove system32 from PATH. This avoids hangs while still allowing completion items from other locations to be displayed.

Closes #1926
Related #1029

@soifou
Copy link
Collaborator Author

soifou commented Jun 22, 2025

Need some feedback from WSL users before this PR can get merged.

@vinnymeller
Copy link
Contributor

not super knowledgeable about either wsl or lua but I tested this out and did run into a couple problems

system stuff:

~ uname -r
5.15.167.4-microsoft-standard-WSL2

~ wsl.exe --version
WSL version: 2.4.12.0
Kernel version: 5.15.167.4-1
WSLg version: 1.0.65
MSRDC version: 1.2.5716
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26100.1-240331-1435.ge-release
Windows version: 10.0.26100.4349

~ nvim --version
NVIM v0.12.0-nightly+0d65866
Build type: Release
LuaJIT 2.1.1741730670
Run "nvim -V1 -v" for more info

separator issue

For some reason the separator logic here wasn't working as intended(i think?):

:lua vim.print(vim.fn.has('win32'))
0

:lua vim.print(vim.fn.has('wsl'))
1

:lua vim.print(vim.fn.has('win32') and ';' or ':')
;

extra windows paths

The other issue I ran into is that I had more than just /mnt/c/windows/system32 in my path:

~ print -rl $path | grep /mnt/c
/mnt/c/WINDOWS/system32
/mnt/c/WINDOWS
/mnt/c/WINDOWS/System32/Wbem
/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/
/mnt/c/WINDOWS/System32/OpenSSH/
/mnt/c/Program Files/NVIDIA Corporation/NVIDIA app/NvDLISR
/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common
/mnt/c/Users/vinny/AppData/Local/Microsoft/WindowsApps

I opened a branch & pr in my fork that "fixes" these issues here: https://github.com/vinnymeller/blink.cmp/pull/3/files

I don't know that my solution is close to something you'd want to do but my version works as expected for me - basically having any /mnt/c/* path in my PATH causes cmdline completions to completely freeze. not sure if that is a universal experience but something specific to my installation, but I had to remove all of them to fix the issue

@soifou soifou force-pushed the fix/cmdline-wsl branch from c56d3a5 to 6daf7f3 Compare June 22, 2025 23:10
@soifou
Copy link
Collaborator Author

soifou commented Jun 22, 2025

Hey, thanks for digging into this! Honestly, I'm not super knowledgeable either. I just threw that patch together and tested quickly on a basic Windows VM (no WSL).

Good catch on vim.fn.has, returning 0 or 1 instead of a boolean is a classic Lua gotcha!

basically having any /mnt/c/* path in my PATH causes cmdline completions to completely freeze.

Yeah, that makes sense. It’s because of the slow cross-filesystem performance between WSL and Windows. Pretty much anything under /mnt is going to be sluggish. So it's better to skip all /mnt.

On regular Windows, though, I think just blacklisting System32 should be enough (I tested it 😄).

Anyway, thanks again for your help, I just pushed an update with all these points and added you as a co-author in the commit. If you could confirm that it’s still working fine on your side, that would be great.

@vinnymeller
Copy link
Contributor

@soifou works perfectly for me 😃

This change makes the previous attempt to disable shell completion in
Windows environments more robust:
- Handles both Windows and WSL, instead of only targeting Windows.
- Handles all shellcmd completions, e.g. `:term`, not just the `:!` command.
- Instead of disabling shellcmd completions entirely, temporarily remove
  the problematic folders from `PATH`. This avoids hangs while still
  allowing completion items from other locations to be displayed.

Closes #1926
Related #1029

Co-Authored-By: vinnymeller <vinnymeller@proton.me>
Co-Authored-By: Liam Dyer <liamcdyer@gmail.com>
@soifou soifou force-pushed the fix/cmdline-wsl branch from 3413ce7 to 1e93315 Compare June 23, 2025 23:35
@saghen saghen merged commit 1cc44a3 into main Jun 23, 2025
6 checks passed
@saghen
Copy link
Owner

saghen commented Jun 23, 2025

Tysm!

@soifou soifou deleted the fix/cmdline-wsl branch June 23, 2025 23:42
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.

':!' stops neovim in WSL

3 participants