Skip to content

Commit 22edd31

Browse files
refactor(editor): replace reedline with rustyline completer (#3399)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent b3454cb commit 22edd31

9 files changed

Lines changed: 319 additions & 279 deletions

File tree

Cargo.lock

Lines changed: 21 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ posthog-rs = "0.7.0"
6363
pretty_assertions = "1.4.1"
6464
proc-macro2 = "1.0"
6565
quote = "1.0"
66-
reedline = "=0.47.0"
6766
rustyline = "18.0.0"
6867
regex = "1.12.3"
6968
reqwest = { version = "0.12.23", features = [

crates/forge_main/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ colored.workspace = true
3939
anyhow.workspace = true
4040
derive_setters.workspace = true
4141
lazy_static.workspace = true
42-
reedline.workspace = true
43-
crossterm = "0.29.0"
42+
rustyline.workspace = true
4443
nu-ansi-term.workspace = true
4544
tracing.workspace = true
4645
chrono.workspace = true

crates/forge_main/src/completer/command.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use std::sync::Arc;
22

33
use forge_select::ForgeWidget;
4-
use reedline::{Completer, Span, Suggestion};
54

5+
use crate::completer::input_completer::InputSuggestion;
6+
use crate::completer::search_term::Span;
67
use crate::model::{ForgeCommand, ForgeCommandManager};
78

89
/// A display wrapper for `ForgeCommand` that renders the name and description
@@ -25,8 +26,8 @@ impl CommandCompleter {
2526
}
2627
}
2728

28-
impl Completer for CommandCompleter {
29-
fn complete(&mut self, line: &str, _: usize) -> Vec<reedline::Suggestion> {
29+
impl CommandCompleter {
30+
pub fn complete(&mut self, line: &str, _: usize) -> Vec<InputSuggestion> {
3031
// Determine which sentinel the user typed (`:` or `/`), defaulting to `/`.
3132
let sentinel = if line.starts_with(':') { ':' } else { '/' };
3233

@@ -74,15 +75,10 @@ impl Completer for CommandCompleter {
7475

7576
match builder.prompt() {
7677
Ok(Some(row)) => {
77-
vec![Suggestion {
78+
vec![InputSuggestion {
7879
value: row.0.name,
79-
description: None,
80-
style: None,
81-
extra: None,
8280
span: Span::new(0, line.len()),
8381
append_whitespace: true,
84-
match_indices: None,
85-
display_override: None,
8682
}]
8783
}
8884
_ => vec![],

crates/forge_main/src/completer/input_completer.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ use std::sync::Arc;
33

44
use forge_select::{ForgeWidget, PreviewLayout, PreviewPlacement, SelectRow};
55
use forge_walker::Walker;
6-
use reedline::{Completer, Span, Suggestion};
76

87
use crate::completer::CommandCompleter;
9-
use crate::completer::search_term::SearchTerm;
8+
use crate::completer::search_term::{SearchTerm, Span};
109
use crate::model::ForgeCommandManager;
1110

1211
pub fn select_workspace_file(cwd: &Path, query: Option<String>) -> anyhow::Result<Option<String>> {
@@ -60,14 +59,18 @@ pub struct InputCompleter {
6059
command: CommandCompleter,
6160
}
6261

62+
pub struct InputSuggestion {
63+
pub value: String,
64+
pub span: Span,
65+
pub append_whitespace: bool,
66+
}
67+
6368
impl InputCompleter {
6469
pub fn new(cwd: PathBuf, command_manager: Arc<ForgeCommandManager>) -> Self {
6570
Self { cwd, command: CommandCompleter::new(command_manager) }
6671
}
67-
}
6872

69-
impl Completer for InputCompleter {
70-
fn complete(&mut self, line: &str, pos: usize) -> Vec<Suggestion> {
73+
pub fn complete(&mut self, line: &str, pos: usize) -> Vec<InputSuggestion> {
7174
if line.starts_with('/') || line.starts_with(':') {
7275
// if the line starts with '/' or ':' it's probably a command, so we delegate to
7376
// the command completer.
@@ -86,15 +89,10 @@ impl Completer for InputCompleter {
8689

8790
if let Ok(Some(selected)) = select_workspace_file(&self.cwd, initial_text) {
8891
let value = format!("[{}]", selected);
89-
return vec![Suggestion {
90-
description: None,
92+
return vec![InputSuggestion {
9193
value,
92-
style: None,
93-
extra: None,
9494
span: Span::new(query.span.start, query.span.end),
9595
append_whitespace: true,
96-
match_indices: None,
97-
display_override: None,
9896
}];
9997
}
10098
}

crates/forge_main/src/completer/search_term.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
use reedline::Span;
1+
#[derive(Clone, Debug, PartialEq, Eq)]
2+
pub struct Span {
3+
pub start: usize,
4+
pub end: usize,
5+
}
6+
7+
impl Span {
8+
pub fn new(start: usize, end: usize) -> Self {
9+
Self { start, end }
10+
}
11+
}
212

313
pub struct SearchTerm {
414
line: String,

0 commit comments

Comments
 (0)