Skip to content

✨ feat(mq-repl): improve REPL tab completion with word-boundary awareness#1455

Merged
harehare merged 6 commits intomainfrom
feat/improve-repl-completion
Mar 16, 2026
Merged

✨ feat(mq-repl): improve REPL tab completion with word-boundary awareness#1455
harehare merged 6 commits intomainfrom
feat/improve-repl-completion

Conversation

@harehare
Copy link
Copy Markdown
Owner

  • 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

…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
Copilot AI review requested due to automatic review settings March 16, 2026 12:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 /command prefix 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

Comment on lines +159 to 162
let mut completions = matches
.iter()
.map(|cmd| Pair {
display: cmd.clone(),
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Copilot AI review requested due to automatic review settings March 16, 2026 12:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
Copilot AI review requested due to automatic review settings March 16, 2026 12:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 /command vs keyword/symbol completion paths, and _-prefix filtering
  • repl.rs updated to destructure the new return type and pass start to 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('_')));
harehare and others added 2 commits March 16, 2026 21:50
Copilot AI review requested due to automatic review settings March 16, 2026 13:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) from completions() so rustyline replaces only the current word, with separate handling for /command prefixes vs identifiers/keywords
  • Add a KEYWORDS constant 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

Comment on lines 167 to +172
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))
Comment on lines +153 to +154
if name.starts_with(word) && !matches.contains(&name.to_string()) {
matches.push(name.to_string());
@harehare harehare merged commit 21cb04f into main Mar 16, 2026
4 checks passed
@harehare harehare deleted the feat/improve-repl-completion branch March 16, 2026 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants