✨ feat(mq-repl): improve REPL tab completion with word-boundary awareness#1455
✨ feat(mq-repl): improve REPL tab completion with word-boundary awareness#1455
Conversation
…ness - Return `(start, matches)` from `completions()` so rustyline replaces only the current word instead of the whole line - Complete `/command` prefixes separately from identifiers and keywords - Add keyword list completions (def, let, if, foreach, etc.) - Filter internal symbols starting with `_` from completions - Sort completion results alphabetically - Expand tests to cover commands, mid-line completion, and internal filtering
There was a problem hiding this comment.
Pull request overview
This PR improves the REPL tab completion in mq-repl by making it word-boundary aware. Instead of replacing the entire line from position 0, the completion now identifies the current word being typed and replaces only that portion. It also adds keyword completions, command (/-prefixed) completions, and filters out internal symbols starting with _.
Changes:
completions()now returns(start, Vec<String>)to indicate where the word being completed starts, enabling rustyline to replace only the current word- Adds keyword list and
/commandprefix completion with internal symbol filtering and alphabetical sorting - Expands tests to cover commands, mid-line completion, and internal symbol filtering
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
crates/mq-repl/src/command_context.rs |
Rewrites completions() to return word start position, adds keyword list, command completions, internal symbol filtering, and deduplication |
crates/mq-repl/src/repl.rs |
Updates Completer::complete() to destructure the new (start, matches) return and pass start to rustyline |
| let mut completions = matches | ||
| .iter() | ||
| .map(|cmd| Pair { | ||
| display: cmd.clone(), |
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR improves REPL tab completion by making it word-boundary aware. Previously, completions always replaced from position 0 (the start of the line); now completions() returns a (start, matches) tuple so that only the current word is replaced. It also adds command prefix completion (for /-prefixed commands), keyword completions, filtering of internal _-prefixed symbols, and alphabetical sorting.
Changes:
completions()now returns(usize, Vec<String>)with word-boundary detection, enabling mid-line completion- Completion logic branches on
/-prefixed commands vs. keywords + HIR symbols, with_-prefixed internal symbols filtered out - Tests expanded to cover commands, mid-line completion, and internal symbol filtering
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
crates/mq-repl/src/command_context.rs |
Rewrote completions() to return (start, matches), added word-boundary detection, command/keyword completion, _-prefix filtering, sorting, and new tests |
crates/mq-repl/src/repl.rs |
Updated Completer::complete to destructure and forward the new (start, matches) return value |
| let completions = ctx.completions("", 0); | ||
| assert!(!completions.is_empty(), "Completions should not be empty"); | ||
| let (_, matches) = ctx.completions("_", 1); | ||
| assert!(matches.iter().all(|m| !m.starts_with('_'))); |
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR improves REPL tab completion in mq-repl by making it word-boundary aware. Previously, completions always replaced from position 0 and matched substrings anywhere in symbol names. Now, completions identify the current word at the cursor and return the correct start position, enabling mid-line completion. It also adds keyword and /command prefix completions, filters internal _-prefixed symbols, and sorts results.
Changes:
completions()now returns(start, Vec<String>)with word-boundary detection, separate/commandvs keyword/symbol completion paths, and_-prefix filteringrepl.rsupdated to destructure the new return type and passstartto rustyline- Tests expanded with cases for basic completion, command completion, mid-line completion, and internal symbol filtering
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
crates/mq-repl/src/command_context.rs |
Reworked completions() to return (start, matches), added word-boundary detection, command/keyword/symbol completion branches, _-prefix filtering, and sorting |
crates/mq-repl/src/repl.rs |
Updated Completer::complete to use the new (start, matches) return value |
| } | ||
|
|
||
| Ok((0, completions)) | ||
| Ok((start, completions)) |
| let completions = ctx.completions("", 0); | ||
| assert!(!completions.is_empty(), "Completions should not be empty"); | ||
| let (_, matches) = ctx.completions("_", 1); | ||
| assert!(matches.iter().all(|m| !m.starts_with('_'))); |
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR improves REPL tab completion in the mq-repl crate by making it word-boundary-aware. Previously, completions replaced the entire line from position 0; now they replace only the current word being typed, which provides a much better user experience for mid-line completions.
Changes:
- Return
(start, matches)fromcompletions()so rustyline replaces only the current word, with separate handling for/commandprefixes vs identifiers/keywords - Add a
KEYWORDSconstant with all language keywords for REPL completion, and filter out internal (_-prefixed) symbols - Expand tests to cover command completions, mid-line completion, and internal symbol filtering
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
crates/mq-repl/src/command_context.rs |
Refactored completions() to return (usize, Vec<String>) with word-boundary detection, keyword completions, _ filtering, and alphabetical sorting; added KEYWORDS constant and new tests |
crates/mq-repl/src/repl.rs |
Updated Completer::complete() to destructure the new return type and pass start instead of hardcoded 0 to rustyline |
| if line.starts_with(Command::LoadFile("".to_string()).to_string().as_str()) { | ||
| let (_, file_completions) = self.file_completer.complete_path(line, pos)?; | ||
| completions.extend(file_completions); | ||
| } | ||
|
|
||
| Ok((0, completions)) | ||
| Ok((start, completions)) |
| if name.starts_with(word) && !matches.contains(&name.to_string()) { | ||
| matches.push(name.to_string()); |
(start, matches)fromcompletions()so rustyline replaces only the current word instead of the whole line/commandprefixes separately from identifiers and keywords_from completions