runtime(vimcomplete): do not complete 'shellcmd' on WSL and Windows

- shellcmd completion is VERY slow on both WSL and Windows, e.g. `term
  something` or `!something` might take ~10 seconds to show first
  results. Do not complete it there.

- revert previous change to not complete on whitespace, do not complete
  on *empty* lines instead.

closes: #18568

Signed-off-by: Maxim Kim <habamax@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Maxim Kim
2025-10-16 19:17:02 +00:00
committed by Christian Brabandt
parent f22cedd75f
commit 30ff1e3b02
3 changed files with 46 additions and 8 deletions

View File

@ -3,7 +3,7 @@ vim9script
# Vim completion script
# Language: Vim script
# Maintainer: Maxim Kim <habamax@gmail.com>
# Last Change: 2025-10-13
# Last Change: 2025-10-15
#
# Usage:
# setlocal omnifunc=vimcomplete#Complete
@ -22,12 +22,15 @@ def GetTrigger(line: string): list<any>
result = 'function'
elseif line =~ '\v%(^|\s+)\&\k*$'
result = 'option'
elseif line =~ '\vse%[t]\s+(\k+\s+)*no\k*$'
result = 'nooption'
result_len = -2
elseif line =~ '[\[(]\s*$'
result = 'expression'
elseif line =~ '[lvgsb]:\k*$'
result = 'var'
result_len = 2
else
elseif line !~ '^\s*$'
result = getcompletiontype(line) ?? 'cmdline'
endif
return [result, result_len]
@ -35,10 +38,8 @@ enddef
export def Complete(findstart: number, base: string): any
if findstart > 0
prefix = ""
var line = getline('.')->strpart(0, col('.') - 1)
if line =~ '\s\+$'
return -2
endif
var keyword = line->matchstr('\k\+$')
var stx = synstack(line('.'), col('.') - 1)->map('synIDattr(v:val, "name")')->join()
if stx =~? 'Comment' || (stx =~ 'String' && stx !~ 'vimStringInterpolationExpr')
@ -60,6 +61,9 @@ export def Complete(findstart: number, base: string): any
elseif trigger == 'option'
items = getcompletion(base, 'option')
->mapnew((_, v) => ({word: v, kind: 'v', menu: 'Option', dup: 0}))
elseif trigger == 'nooption'
items = getcompletion(base[2 : ], 'option')
->mapnew((_, v) => ({word: v, kind: 'v', menu: 'Option', dup: 0}))
elseif trigger == 'var'
items = getcompletion(base, 'var')
->mapnew((_, v) => ({word: v, kind: 'v', menu: 'Variable', dup: 0}))
@ -74,8 +78,11 @@ export def Complete(findstart: number, base: string): any
items = commands + functions
else
try
items = getcompletion(prefix, 'cmdline')
->mapnew((_, v) => ({word: v->matchstr('\k\+'), kind: 'v', dup: 0}))
# :! and :term completion is very slow on Windows and WSL, disable it there.
if !((has("win32") || has("win32unix") || exists("$WSLENV")) && getcompletiontype(prefix) == 'shellcmd')
items = getcompletion(prefix, 'cmdline')
->mapnew((_, v) => ({word: v->matchstr('\k\+'), kind: 'v', dup: 0}))
endif
catch /E220/
endtry