fix(cli): keep typing responsive by not blocking the keystroke loop
The interactive CLI input box runs its completer with
`complete_while_typing=True`, so `SlashCommandCompleter.get_completions`
is invoked on *every* keystroke. That completer does blocking I/O:
fuzzy `@`-file indexing shells out to `rg`/`fd` (up to a 2s timeout) and
file-path completion calls `os.listdir` + `stat`. Because the completer
was passed inline (never wrapped in `ThreadedCompleter`), all of this ran
synchronously on the prompt_toolkit event loop, stalling the render after
each key — very noticeable on WSL2 and other slow-filesystem setups
("typing in the prompt box being very latent").
Two fixes:
- Wrap the input completer in `ThreadedCompleter` so completion work runs
off the UI event loop and never blocks rendering between keystrokes.
- Stop treating URLs as file paths in `_extract_path_word`: a token like
`https://example.com/x` contains `/`, so it triggered `os.listdir` on
every keystroke while typing/pasting a link (listing a bogus `https:`
dir) for a completion that can never be useful. Skip any token with a
`://` scheme separator.
This commit is contained in:
@@ -1291,6 +1291,12 @@ class SlashCommandCompleter(Completer):
|
||||
word = text[i + 1:]
|
||||
if not word:
|
||||
return None
|
||||
# URLs contain "/" but are not local paths. Treating them as paths fires
|
||||
# os.listdir on every keystroke while typing/pasting a link (e.g. an
|
||||
# https:// URL becomes a listdir of "https:") — pure latency, never a
|
||||
# useful completion. Skip any token with a scheme separator.
|
||||
if "://" in word:
|
||||
return None
|
||||
# Only trigger path completion for path-like tokens
|
||||
if word.startswith(("./", "../", "~/", "/")) or "/" in word:
|
||||
return word
|
||||
|
||||
Reference in New Issue
Block a user