added initial keymap for toggle semantic search

Co-authored-by: maxbrunsfeld <max@zed.dev>
This commit is contained in:
KCaverly
2023-07-11 17:13:58 -04:00
co-authored by maxbrunsfeld
parent 2ca4b3f4cc
commit af7b2f17ae
2 changed files with 23 additions and 20 deletions
+1
View File
@@ -405,6 +405,7 @@
"cmd-k cmd-t": "theme_selector::Toggle",
"cmd-k cmd-s": "zed::OpenKeymap",
"cmd-t": "project_symbols::Toggle",
"cmd-alt-t": "semantic_search::Toggle",
"cmd-p": "file_finder::Toggle",
"cmd-shift-p": "command_palette::Toggle",
"cmd-shift-m": "diagnostics::Deploy",
+22 -20
View File
@@ -49,7 +49,6 @@ pub fn init(
}
settings::register::<VectorStoreSettings>(cx);
if !settings::get::<VectorStoreSettings>(cx).enable {
return;
}
@@ -58,6 +57,27 @@ pub fn init(
.join(Path::new(RELEASE_CHANNEL_NAME.as_str()))
.join("embeddings_db");
SemanticSearch::init(cx);
cx.add_action(
|workspace: &mut Workspace, _: &Toggle, cx: &mut ViewContext<Workspace>| {
eprintln!("semantic_search::Toggle action");
if cx.has_global::<ModelHandle<VectorStore>>() {
let vector_store = cx.global::<ModelHandle<VectorStore>>().clone();
workspace.toggle_modal(cx, |workspace, cx| {
let project = workspace.project().clone();
let workspace = cx.weak_handle();
cx.add_view(|cx| {
SemanticSearch::new(
SemanticSearchDelegate::new(workspace, project, vector_store),
cx,
)
})
});
}
},
);
cx.spawn(move |mut cx| async move {
let vector_store = VectorStore::new(
fs,
@@ -73,6 +93,7 @@ pub fn init(
.await?;
cx.update(|cx| {
cx.set_global(vector_store.clone());
cx.subscribe_global::<WorkspaceCreated, _>({
let vector_store = vector_store.clone();
move |event, cx| {
@@ -88,25 +109,6 @@ pub fn init(
}
})
.detach();
cx.add_action({
// "semantic search: Toggle"
move |workspace: &mut Workspace, _: &Toggle, cx: &mut ViewContext<Workspace>| {
let vector_store = vector_store.clone();
workspace.toggle_modal(cx, |workspace, cx| {
let project = workspace.project().clone();
let workspace = cx.weak_handle();
cx.add_view(|cx| {
SemanticSearch::new(
SemanticSearchDelegate::new(workspace, project, vector_store),
cx,
)
})
})
}
});
SemanticSearch::init(cx);
});
anyhow::Ok(())