Add streaming_diff crate (#23264)

This PR extracts the streaming diff implementation to its own
`streaming_diff` crate.

It was duplicated between `assistant` and `assistant2`, but their
implementations were exactly the same (and I don't see a reason why they
would need to diverge).

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-01-16 18:12:46 -05:00 committed by GitHub
parent 4d22f7e529
commit 24495f09f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 41 additions and 1113 deletions

14
Cargo.lock generated
View file

@ -405,7 +405,6 @@ dependencies = [
"menu", "menu",
"multi_buffer", "multi_buffer",
"open_ai", "open_ai",
"ordered-float 2.10.1",
"parking_lot", "parking_lot",
"paths", "paths",
"picker", "picker",
@ -428,6 +427,7 @@ dependencies = [
"similar", "similar",
"smallvec", "smallvec",
"smol", "smol",
"streaming_diff",
"strum", "strum",
"telemetry", "telemetry",
"telemetry_events", "telemetry_events",
@ -479,7 +479,6 @@ dependencies = [
"markdown", "markdown",
"menu", "menu",
"multi_buffer", "multi_buffer",
"ordered-float 2.10.1",
"parking_lot", "parking_lot",
"picker", "picker",
"project", "project",
@ -492,6 +491,7 @@ dependencies = [
"settings", "settings",
"similar", "similar",
"smol", "smol",
"streaming_diff",
"telemetry_events", "telemetry_events",
"terminal", "terminal",
"terminal_view", "terminal_view",
@ -12347,6 +12347,16 @@ dependencies = [
"ui", "ui",
] ]
[[package]]
name = "streaming_diff"
version = "0.1.0"
dependencies = [
"ordered-float 2.10.1",
"rand 0.8.5",
"rope",
"util",
]
[[package]] [[package]]
name = "strict-num" name = "strict-num"
version = "0.1.1" version = "0.1.1"

View file

@ -116,6 +116,7 @@ members = [
"crates/sqlez_macros", "crates/sqlez_macros",
"crates/story", "crates/story",
"crates/storybook", "crates/storybook",
"crates/streaming_diff",
"crates/sum_tree", "crates/sum_tree",
"crates/supermaven", "crates/supermaven",
"crates/supermaven_api", "crates/supermaven_api",
@ -307,6 +308,7 @@ sqlez = { path = "crates/sqlez" }
sqlez_macros = { path = "crates/sqlez_macros" } sqlez_macros = { path = "crates/sqlez_macros" }
story = { path = "crates/story" } story = { path = "crates/story" }
storybook = { path = "crates/storybook" } storybook = { path = "crates/storybook" }
streaming_diff = { path = "crates/streaming_diff" }
sum_tree = { path = "crates/sum_tree" } sum_tree = { path = "crates/sum_tree" }
supermaven = { path = "crates/supermaven" } supermaven = { path = "crates/supermaven" }
supermaven_api = { path = "crates/supermaven_api" } supermaven_api = { path = "crates/supermaven_api" }

View file

@ -51,7 +51,6 @@ lsp.workspace = true
menu.workspace = true menu.workspace = true
multi_buffer.workspace = true multi_buffer.workspace = true
open_ai = { workspace = true, features = ["schemars"] } open_ai = { workspace = true, features = ["schemars"] }
ordered-float.workspace = true
parking_lot.workspace = true parking_lot.workspace = true
paths.workspace = true paths.workspace = true
picker.workspace = true picker.workspace = true
@ -71,6 +70,7 @@ settings.workspace = true
similar.workspace = true similar.workspace = true
smallvec.workspace = true smallvec.workspace = true
smol.workspace = true smol.workspace = true
streaming_diff.workspace = true
strum.workspace = true strum.workspace = true
telemetry.workspace = true telemetry.workspace = true
telemetry_events.workspace = true telemetry_events.workspace = true

View file

@ -9,7 +9,6 @@ mod prompt_library;
mod slash_command; mod slash_command;
pub(crate) mod slash_command_picker; pub(crate) mod slash_command_picker;
pub mod slash_command_settings; pub mod slash_command_settings;
mod streaming_diff;
mod terminal_inline_assistant; mod terminal_inline_assistant;
use std::path::PathBuf; use std::path::PathBuf;
@ -39,7 +38,6 @@ pub use crate::context_store::*;
pub(crate) use crate::inline_assistant::*; pub(crate) use crate::inline_assistant::*;
pub use crate::patch::*; pub use crate::patch::*;
use crate::slash_command_settings::SlashCommandSettings; use crate::slash_command_settings::SlashCommandSettings;
pub(crate) use crate::streaming_diff::*;
actions!( actions!(
assistant, assistant,

View file

@ -1,7 +1,6 @@
use crate::{ use crate::{
humanize_token_count, AssistantPanel, AssistantPanelEvent, CharOperation, humanize_token_count, AssistantPanel, AssistantPanelEvent, CycleNextInlineAssist,
CycleNextInlineAssist, CyclePreviousInlineAssist, LineDiff, LineOperation, RequestType, CyclePreviousInlineAssist, RequestType,
StreamingDiff,
}; };
use anyhow::{anyhow, Context as _, Result}; use anyhow::{anyhow, Context as _, Result};
use assistant_settings::AssistantSettings; use assistant_settings::AssistantSettings;
@ -56,6 +55,7 @@ use std::{
task::{self, Poll}, task::{self, Poll},
time::{Duration, Instant}, time::{Duration, Instant},
}; };
use streaming_diff::{CharOperation, LineDiff, LineOperation, StreamingDiff};
use telemetry_events::{AssistantEvent, AssistantKind, AssistantPhase}; use telemetry_events::{AssistantEvent, AssistantKind, AssistantPhase};
use terminal_view::terminal_panel::TerminalPanel; use terminal_view::terminal_panel::TerminalPanel;
use text::{OffsetRangeExt, ToPoint as _}; use text::{OffsetRangeExt, ToPoint as _};

View file

@ -43,7 +43,6 @@ lsp.workspace = true
markdown.workspace = true markdown.workspace = true
menu.workspace = true menu.workspace = true
multi_buffer.workspace = true multi_buffer.workspace = true
ordered-float.workspace = true
parking_lot.workspace = true parking_lot.workspace = true
picker.workspace = true picker.workspace = true
project.workspace = true project.workspace = true
@ -55,6 +54,7 @@ serde_json.workspace = true
settings.workspace = true settings.workspace = true
similar.workspace = true similar.workspace = true
smol.workspace = true smol.workspace = true
streaming_diff.workspace = true
telemetry_events.workspace = true telemetry_events.workspace = true
terminal.workspace = true terminal.workspace = true
terminal_view.workspace = true terminal_view.workspace = true

View file

@ -9,7 +9,6 @@ mod context_strip;
mod inline_assistant; mod inline_assistant;
mod inline_prompt_editor; mod inline_prompt_editor;
mod message_editor; mod message_editor;
mod streaming_diff;
mod terminal_codegen; mod terminal_codegen;
mod terminal_inline_assistant; mod terminal_inline_assistant;
mod thread; mod thread;

View file

@ -1,7 +1,6 @@
use crate::context::attach_context_to_message; use crate::context::attach_context_to_message;
use crate::context_store::ContextStore; use crate::context_store::ContextStore;
use crate::inline_prompt_editor::CodegenStatus; use crate::inline_prompt_editor::CodegenStatus;
use crate::streaming_diff::{CharOperation, LineDiff, LineOperation, StreamingDiff};
use anyhow::{Context as _, Result}; use anyhow::{Context as _, Result};
use client::telemetry::Telemetry; use client::telemetry::Telemetry;
use collections::HashSet; use collections::HashSet;
@ -29,6 +28,7 @@ use std::{
task::{self, Poll}, task::{self, Poll},
time::Instant, time::Instant,
}; };
use streaming_diff::{CharOperation, LineDiff, LineOperation, StreamingDiff};
use telemetry_events::{AssistantEvent, AssistantKind, AssistantPhase}; use telemetry_events::{AssistantEvent, AssistantKind, AssistantPhase};
pub struct BufferCodegen { pub struct BufferCodegen {

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,20 @@
[package]
name = "streaming_diff"
version = "0.1.0"
edition = "2021"
publish = false
license = "GPL-3.0-or-later"
[lints]
workspace = true
[lib]
path = "src/streaming_diff.rs"
[dependencies]
ordered-float.workspace = true
rope.workspace = true
[dev-dependencies]
rand.workspace = true
util = { workspace = true, features = ["test-support"] }

View file

@ -0,0 +1 @@
../../LICENSE-GPL