Cargo.lock 🔗
@@ -8041,6 +8041,7 @@ dependencies = [
"anyhow",
"async-trait",
"bincode",
+ "editor",
"futures 0.3.28",
"gpui",
"isahc",
KCaverly created
Cargo.lock | 1
crates/vector_store/Cargo.toml | 1
crates/vector_store/src/modal.rs | 36 ++++++++++++++++++++++++--
crates/vector_store/src/vector_store.rs | 33 ------------------------
4 files changed, 35 insertions(+), 36 deletions(-)
@@ -8041,6 +8041,7 @@ dependencies = [
"anyhow",
"async-trait",
"bincode",
+ "editor",
"futures 0.3.28",
"gpui",
"isahc",
@@ -16,6 +16,7 @@ workspace = { path = "../workspace" }
util = { path = "../util" }
picker = { path = "../picker" }
theme = { path = "../theme" }
+editor = { path = "../editor" }
anyhow.workspace = true
futures.workspace = true
smol.workspace = true
@@ -1,11 +1,12 @@
use crate::{SearchResult, VectorStore};
+use editor::{scroll::autoscroll::Autoscroll, Editor};
use gpui::{
actions, elements::*, AnyElement, AppContext, ModelHandle, MouseState, Task, ViewContext,
WeakViewHandle,
};
use picker::{Picker, PickerDelegate, PickerEvent};
-use project::Project;
-use std::{sync::Arc, time::Duration};
+use project::{Project, ProjectPath};
+use std::{path::Path, sync::Arc, time::Duration};
use util::ResultExt;
use workspace::Workspace;
@@ -50,7 +51,34 @@ impl PickerDelegate for SemanticSearchDelegate {
fn confirm(&mut self, cx: &mut ViewContext<SemanticSearch>) {
if let Some(search_result) = self.matches.get(self.selected_match_index) {
- // search_result.file_path
+ // Open Buffer
+ let search_result = search_result.clone();
+ let buffer = self.project.update(cx, |project, cx| {
+ project.open_buffer(
+ ProjectPath {
+ worktree_id: search_result.worktree_id,
+ path: search_result.file_path.clone().into(),
+ },
+ cx,
+ )
+ });
+
+ let workspace = self.workspace.clone();
+ let position = search_result.clone().offset;
+ cx.spawn(|_, mut cx| async move {
+ let buffer = buffer.await?;
+ workspace.update(&mut cx, |workspace, cx| {
+ let editor = workspace.open_project_item::<Editor>(buffer, cx);
+ editor.update(cx, |editor, cx| {
+ editor.change_selections(Some(Autoscroll::center()), cx, |s| {
+ s.select_ranges([position..position])
+ });
+ });
+ })?;
+ Ok::<_, anyhow::Error>(())
+ })
+ .detach_and_log_err(cx);
+ cx.emit(PickerEvent::Dismiss);
}
}
@@ -78,6 +106,8 @@ impl PickerDelegate for SemanticSearchDelegate {
cx.spawn(|this, mut cx| async move {
cx.background().timer(EMBEDDING_DEBOUNCE_INTERVAL).await;
+ log::info!("Searching for {:?}", &query);
+
let task = vector_store.update(&mut cx, |store, cx| {
store.search(&project, query.to_string(), 10, cx)
});
@@ -294,43 +294,10 @@ impl VectorStore {
let db_write_task = cx.background().spawn(
async move {
- // Initialize Database, creates database and tables if not exists
while let Ok((worktree_id, indexed_file)) = indexed_files_rx.recv().await {
db.insert_file(worktree_id, indexed_file).log_err();
}
- // ALL OF THE BELOW IS FOR TESTING,
- // This should be removed as we find and appropriate place for evaluate our search.
-
- // let queries = vec![
- // "compute embeddings for all of the symbols in the codebase, and write them to a database",
- // "compute an outline view of all of the symbols in a buffer",
- // "scan a directory on the file system and load all of its children into an in-memory snapshot",
- // ];
- // let embeddings = embedding_provider.embed_batch(queries.clone()).await?;
-
- // let t2 = Instant::now();
- // let documents = db.get_documents().unwrap();
- // let files = db.get_files().unwrap();
- // println!("Retrieving all documents from Database: {}", t2.elapsed().as_millis());
-
- // let t1 = Instant::now();
- // let mut bfs = BruteForceSearch::load(&db).unwrap();
- // println!("Loading BFS to Memory: {:?}", t1.elapsed().as_millis());
- // for (idx, embed) in embeddings.into_iter().enumerate() {
- // let t0 = Instant::now();
- // println!("\nQuery: {:?}", queries[idx]);
- // let results = bfs.top_k_search(&embed, 5).await;
- // println!("Search Elapsed: {}", t0.elapsed().as_millis());
- // for (id, distance) in results {
- // println!("");
- // println!(" distance: {:?}", distance);
- // println!(" document: {:?}", documents[&id].name);
- // println!(" path: {:?}", files[&documents[&id].file_id].relative_path);
- // }
-
- // }
-
anyhow::Ok(())
}
.log_err(),