Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 21 additions & 64 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ posthog-rs = "0.7.0"
pretty_assertions = "1.4.1"
proc-macro2 = "1.0"
quote = "1.0"
reedline = "=0.47.0"
rustyline = "18.0.0"
regex = "1.12.3"
reqwest = { version = "0.12.23", features = [
Expand Down
3 changes: 1 addition & 2 deletions crates/forge_main/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ colored.workspace = true
anyhow.workspace = true
derive_setters.workspace = true
lazy_static.workspace = true
reedline.workspace = true
crossterm = "0.29.0"
rustyline.workspace = true
nu-ansi-term.workspace = true
tracing.workspace = true
chrono.workspace = true
Expand Down
14 changes: 5 additions & 9 deletions crates/forge_main/src/completer/command.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::sync::Arc;

use forge_select::ForgeWidget;
use reedline::{Completer, Span, Suggestion};

use crate::completer::input_completer::InputSuggestion;
use crate::completer::search_term::Span;
use crate::model::{ForgeCommand, ForgeCommandManager};

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

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

Expand Down Expand Up @@ -74,15 +75,10 @@ impl Completer for CommandCompleter {

match builder.prompt() {
Ok(Some(row)) => {
vec![Suggestion {
vec![InputSuggestion {
value: row.0.name,
description: None,
style: None,
extra: None,
span: Span::new(0, line.len()),
append_whitespace: true,
match_indices: None,
display_override: None,
}]
}
_ => vec![],
Expand Down
20 changes: 9 additions & 11 deletions crates/forge_main/src/completer/input_completer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ use std::sync::Arc;

use forge_select::{ForgeWidget, PreviewLayout, PreviewPlacement, SelectRow};
use forge_walker::Walker;
use reedline::{Completer, Span, Suggestion};

use crate::completer::CommandCompleter;
use crate::completer::search_term::SearchTerm;
use crate::completer::search_term::{SearchTerm, Span};
use crate::model::ForgeCommandManager;

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

pub struct InputSuggestion {
pub value: String,
pub span: Span,
pub append_whitespace: bool,
}

impl InputCompleter {
pub fn new(cwd: PathBuf, command_manager: Arc<ForgeCommandManager>) -> Self {
Self { cwd, command: CommandCompleter::new(command_manager) }
}
}

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

if let Ok(Some(selected)) = select_workspace_file(&self.cwd, initial_text) {
let value = format!("[{}]", selected);
return vec![Suggestion {
description: None,
return vec![InputSuggestion {
value,
style: None,
extra: None,
span: Span::new(query.span.start, query.span.end),
append_whitespace: true,
match_indices: None,
display_override: None,
}];
}
}
Expand Down
12 changes: 11 additions & 1 deletion crates/forge_main/src/completer/search_term.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
use reedline::Span;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Span {
pub start: usize,
pub end: usize,
}

impl Span {
pub fn new(start: usize, end: usize) -> Self {
Self { start, end }
}
}

pub struct SearchTerm {
line: String,
Expand Down
Loading
Loading