Skip to main content

Module repl

Module repl 

Source
Expand description

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ EXTENSION — NO vendor/ COUNTERPART. Interactive REPL for vimlrs — a utop-style line editor backed by reedline. Adapted from strykelang’s repl.rs (same reedline 0.47 API), trimmed for vimlrs’s thread-local interpreter model.

Layout per turn:

─( HH:MM:SS )──< command N >─────────────────────────────{ vimlrs 0.1.2 }─
vimlrs❯ <buffer>
        abs           add           and           append        …
  • The top “modeline” is rendered as part of Prompt::render_prompt_left, so it repaints with the buffer (no scroll-off, no flicker).
  • Tab pops a ColumnarMenu of suggestions sourced from crate::lsp::completion_words — the same wordlist the LSP serves.
  • History is ~/.vimlrs/history via FileBackedHistory.
  • Edit mode (emacs/vi) comes from ~/.vimlrs/config.toml [repl] mode, with a VIMLRS_REPL_MODE env override and a VIMLRS_NO_CONFIG guard.

§Single-line evaluation (no multi-line block validator)

Each Enter submits one line to crate::eval_source, exactly like the plain non-TTY cli::repl fallback. A reedline Validator that continued the buffer on an open function/if/while/for/try block was considered and deliberately not shipped: doing it correctly requires replicating the parser’s |-separator + string/comment awareness (an inline if x | echo 1 | endif is a complete line; echo "endif" must not decrement block depth). A naive counter hangs the REPL on those valid single-line inputs, which is worse than not having continuation. Interactive block definitions are therefore entered one line at a time, matching the existing stdin REPL. Reedline does not include a file-path completer either; bare-path completion is intentionally dropped — the LSP word list is the high-value surface (commands, not paths), the same choice utop makes.

Functions§

ensure_default_config_seeded
First-run seed: write ~/.vimlrs/config.toml if it does not exist. Safe to call on every REPL launch — no-op when the file is already there (and silent if the home directory is read-only). Honors VIMLRS_NO_CONFIG=1 for CI / sandbox environments that should not touch the user’s home dir.
run
Run the interactive reedline REPL. Must be called on the CLI worker thread (interpreter globals — g:/v: vars, the last-result slot — are thread-local, so evaluating inline here preserves state across turns).