Rewrite permission queries (it no longer blocks)
Co-authored-by: Kyle <kyle@zed.dev> Co-authored-by: Max <max@zed.dev>
This commit is contained in:
parent
d157e3598d
commit
31fb503418
2 changed files with 51 additions and 62 deletions
|
@ -2,7 +2,7 @@ use crate::{
|
||||||
NextHistoryQuery, PreviousHistoryQuery, SearchHistory, SearchOptions, SelectNextMatch,
|
NextHistoryQuery, PreviousHistoryQuery, SearchHistory, SearchOptions, SelectNextMatch,
|
||||||
SelectPrevMatch, ToggleCaseSensitive, ToggleWholeWord,
|
SelectPrevMatch, ToggleCaseSensitive, ToggleWholeWord,
|
||||||
};
|
};
|
||||||
use anyhow::Context;
|
use anyhow::{Context, Result};
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
use editor::{
|
use editor::{
|
||||||
items::active_match_index, scroll::autoscroll::Autoscroll, Anchor, Editor, MultiBuffer,
|
items::active_match_index, scroll::autoscroll::Autoscroll, Anchor, Editor, MultiBuffer,
|
||||||
|
@ -761,11 +761,13 @@ impl ProjectSearchView {
|
||||||
|
|
||||||
match mode {
|
match mode {
|
||||||
SearchMode::Semantic => {
|
SearchMode::Semantic => {
|
||||||
// let semantic_permissioned = self.semantic_permissioned.await;
|
let has_permission = self.semantic_permissioned(cx);
|
||||||
// if semantic_permissioned.is_ok_and(|permission| !permission) {
|
cx.spawn(|this, mut cx| async move {
|
||||||
if !self.semantic_permissioned(cx) {
|
let has_permission = has_permission.await?;
|
||||||
// TODO: Change this to read from the project name
|
|
||||||
let project = self.model.read(cx).project.clone();
|
if !has_permission {
|
||||||
|
let mut answer = this.update(&mut cx, |this, cx| {
|
||||||
|
let project = this.model.read(cx).project.clone();
|
||||||
let project_name = project
|
let project_name = project
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.worktree_root_names(cx)
|
.worktree_root_names(cx)
|
||||||
|
@ -777,30 +779,32 @@ impl ProjectSearchView {
|
||||||
if is_plural {
|
if is_plural {
|
||||||
"s"
|
"s"
|
||||||
} else {""});
|
} else {""});
|
||||||
let mut answer = cx.prompt(
|
cx.prompt(
|
||||||
PromptLevel::Info,
|
PromptLevel::Info,
|
||||||
prompt_text.as_str(),
|
prompt_text.as_str(),
|
||||||
&["Continue", "Cancel"],
|
&["Continue", "Cancel"],
|
||||||
);
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
cx.spawn(|search_view, mut cx| async move {
|
|
||||||
if answer.next().await == Some(0) {
|
if answer.next().await == Some(0) {
|
||||||
search_view.update(&mut cx, |search_view, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
search_view.semantic_permissioned = Some(true);
|
this.semantic_permissioned = Some(true);
|
||||||
search_view.index_project(cx);
|
|
||||||
})?;
|
})?;
|
||||||
anyhow::Ok(())
|
|
||||||
} else {
|
} else {
|
||||||
search_view.update(&mut cx, |search_view, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
search_view.activate_search_mode(SearchMode::Regex, cx);
|
this.semantic_permissioned = Some(false);
|
||||||
|
this.activate_search_mode(SearchMode::Regex, cx);
|
||||||
})?;
|
})?;
|
||||||
|
return anyhow::Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.update(&mut cx, |this, cx| {
|
||||||
|
this.index_project(cx);
|
||||||
|
})?;
|
||||||
|
|
||||||
anyhow::Ok(())
|
anyhow::Ok(())
|
||||||
}
|
}).detach_and_log_err(cx);
|
||||||
})
|
|
||||||
.detach_and_log_err(cx);
|
|
||||||
} else {
|
|
||||||
self.index_project(cx);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
SearchMode::Regex => {
|
SearchMode::Regex => {
|
||||||
if !self.is_option_enabled(SearchOptions::REGEX) {
|
if !self.is_option_enabled(SearchOptions::REGEX) {
|
||||||
|
@ -922,19 +926,18 @@ impl ProjectSearchView {
|
||||||
this.model_changed(cx);
|
this.model_changed(cx);
|
||||||
this
|
this
|
||||||
}
|
}
|
||||||
fn semantic_permissioned(&mut self, cx: &mut ViewContext<Self>) -> bool {
|
|
||||||
*self.semantic_permissioned.get_or_insert_with(|| {
|
fn semantic_permissioned(&mut self, cx: &mut ViewContext<Self>) -> Task<Result<bool>> {
|
||||||
|
if let Some(value) = self.semantic_permissioned {
|
||||||
|
return Task::ready(Ok(value));
|
||||||
|
}
|
||||||
|
|
||||||
SemanticIndex::global(cx)
|
SemanticIndex::global(cx)
|
||||||
.and_then(|semantic| {
|
.map(|semantic| {
|
||||||
let project = self.model.read(cx).project.clone();
|
let project = self.model.read(cx).project.clone();
|
||||||
smol::block_on(
|
semantic.update(cx, |this, cx| this.project_previously_indexed(project, cx))
|
||||||
semantic
|
|
||||||
.update(cx, |this, cx| this.project_previously_indexed(project, cx)),
|
|
||||||
)
|
|
||||||
.ok()
|
|
||||||
})
|
|
||||||
.unwrap_or_default()
|
|
||||||
})
|
})
|
||||||
|
.unwrap_or(Task::ready(Ok(false)))
|
||||||
}
|
}
|
||||||
pub fn new_search_in_directory(
|
pub fn new_search_in_directory(
|
||||||
workspace: &mut Workspace,
|
workspace: &mut Workspace,
|
||||||
|
|
|
@ -500,26 +500,12 @@ impl SemanticIndex {
|
||||||
project: ModelHandle<Project>,
|
project: ModelHandle<Project>,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Task<Result<bool>> {
|
) -> Task<Result<bool>> {
|
||||||
let worktree_scans_complete = project
|
|
||||||
.read(cx)
|
|
||||||
.worktrees(cx)
|
|
||||||
.map(|worktree| {
|
|
||||||
let scan_complete = worktree.read(cx).as_local().unwrap().scan_complete();
|
|
||||||
async move {
|
|
||||||
scan_complete.await;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
let worktrees_indexed_previously = project
|
let worktrees_indexed_previously = project
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.worktrees(cx)
|
.worktrees(cx)
|
||||||
.map(|worktree| self.worktree_previously_indexed(worktree.read(cx).abs_path()))
|
.map(|worktree| self.worktree_previously_indexed(worktree.read(cx).abs_path()))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
cx.spawn(|_, _cx| async move {
|
cx.spawn(|_, _cx| async move {
|
||||||
futures::future::join_all(worktree_scans_complete).await;
|
|
||||||
|
|
||||||
let worktree_indexed_previously =
|
let worktree_indexed_previously =
|
||||||
futures::future::join_all(worktrees_indexed_previously).await;
|
futures::future::join_all(worktrees_indexed_previously).await;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue