looks_complete heuristic

Decides whether Enter submits the buffer or inserts a newline. Slash/colon commands are always complete; SQL is complete only when the trimmed buffer ends with `;`. Ctrl+Enter and F5 bypass the check entirely.

Category: repl-features

Description

## Overview `looks_complete` is the interactive shell's one-liner for deciding how Enter should behave. It runs on every unmodified Enter press: if the function returns true, `submit` is invoked; otherwise `editor.insert_newline()` is called. The function is deliberately small so the rule is easy to explain: slash commands always submit, SQL requires a terminating semicolon, everything else falls through to a newline. ## Behavior - Trims trailing whitespace and inspects the result. - Returns true if the first character is `/` or `:` (slash commands are always single-logical-line verbs). - Otherwise, returns true only when the text ends with `;`. - No other heuristics: the interactive version does not peek at parenthesis depth, unmatched quotes, or unclosed `--` / `/* */` comments. Those states are caught by `delta_forge_lang::diagnostics` on render, which surfaces them on the diagnostic hint row, but the submission decision itself is purely the terminating-semicolon check. ## Interaction - Shift+Enter always inserts a newline (the submission check is skipped). - Ctrl+Enter and F5 always submit with `force=true`, regardless of whether `looks_complete` would have returned true. Ctrl+Enter is the SSMS-style "run this now even if it looks wrong" verb. - Alt+Enter submits **only** the statement under the cursor, identified via `delta_forge_lang::symbols::document_symbols`. It also runs with `force=true` so the per-statement submission proceeds even if that statement is missing its semicolon. - While a submission is in flight, Enter and Ctrl+Enter are ignored (no new submission can start until the runner emits a terminal status). ## Compatibility - `--classic` uses a richer heuristic (`repl::SqlValidator`): it counts parenthesis depth, tracks single-quoted strings (including `''` escapes), and respects `--` line comments before checking for the trailing semicolon. That validator reports `Incomplete` when any of those checks fail, which is why multi-line SQL composes naturally in the classic REPL without a force-submit.

Examples

-- Submits (trailing semicolon):
SELECT 1;
-- Inserts newline (no semicolon):
SELECT 1
-- Always submits (slash command):
/help
-- Always submits (force):
SELECT 1   -- then Ctrl+Enter
-- Always submits (force, SSMS-style):
SELECT 1   -- then F5

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →