Skip to content

Commit 3bc7f4e

Browse files
use consistent path in trust-dialog instead of searching for it multiple times
1 parent 490ddc9 commit 3bc7f4e

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

helix-term/src/commands/typed.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2737,7 +2737,7 @@ fn trust_workspace(
27372737
if event != PromptEvent::Validate {
27382738
return Ok(());
27392739
}
2740-
cx.editor.trust_workspace()
2740+
cx.editor.trust_current_workspace()
27412741
}
27422742

27432743
fn untrust_workspace(
@@ -2749,7 +2749,7 @@ fn untrust_workspace(
27492749
return Ok(());
27502750
}
27512751

2752-
cx.editor.untrust_workspace()
2752+
cx.editor.untrust_current_workspace()
27532753
}
27542754

27552755
fn trust_dialog(

helix-term/src/handlers/trust.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ Ensure you trust the source of the {file_or_workspace} before trusting it.");
7878
}
7979

8080
let maybe_err = match option {
81-
TrustOptions::Trust => editor.trust_workspace(),
82-
TrustOptions::DoNotTrust => editor.untrust_workspace(),
81+
TrustOptions::Trust => editor.trust_workspace(&path_clone),
82+
TrustOptions::DoNotTrust => editor.untrust_workspace(&path_clone),
8383
TrustOptions::DistrustParent | TrustOptions::TrustParent => {
8484
let path = path_clone.clone();
8585
let option = option.clone();
@@ -122,9 +122,9 @@ fn choose_parent_dialog(path: impl AsRef<Path>, trust: bool) -> impl Component +
122122
path.display()
123123
))
124124
} else if trust {
125-
cx.editor.trust_workspace()
125+
cx.editor.trust_workspace(path)
126126
} else {
127-
cx.editor.untrust_workspace()
127+
cx.editor.untrust_workspace(path)
128128
};
129129
if let Err(e) = result {
130130
cx.editor.set_error(e.to_string());

helix-term/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use anyhow::{Context, Error, Result};
2-
use helix_loader::trust_db::Trust;
32
use helix_loader::{trust_db, VERSION_AND_GIT_HASH};
43
use helix_term::application::Application;
54
use helix_term::args::Args;

helix-view/src/editor.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,23 +2382,27 @@ impl Editor {
23822382
self.last_cwd.as_deref()
23832383
}
23842384

2385-
pub fn trust_workspace(&mut self) -> anyhow::Result<()> {
2385+
pub fn trust_current_workspace(&mut self) -> anyhow::Result<()> {
23862386
let Some(path) = doc!(self).path() else {
23872387
bail!("Document does not have a path; you need to add a path to trust it.")
23882388
};
23892389
let workspace = helix_loader::find_workspace_in(path).0;
2390+
self.trust_workspace(workspace)
2391+
}
2392+
2393+
pub fn trust_workspace(&mut self, workspace: impl AsRef<Path>) -> anyhow::Result<()> {
23902394
match trust_db::trust_path(&workspace) {
23912395
Err(e) => bail!("Couldn't edit trust database: {e}"),
23922396
Ok(is_new_entry) => {
23932397
if is_new_entry {
23942398
self.set_status(format!(
23952399
"Workspace '{}' unrestricted; LSPs, debuggers and formatters available.",
2396-
workspace.display()
2400+
workspace.as_ref().display()
23972401
))
23982402
} else {
23992403
self.set_status(format!(
24002404
"Workspace '{}' is already trusted.",
2401-
workspace.display()
2405+
workspace.as_ref().display()
24022406
));
24032407
}
24042408
self.documents_mut()
@@ -2409,23 +2413,27 @@ impl Editor {
24092413
Ok(())
24102414
}
24112415

2412-
pub fn untrust_workspace(&mut self) -> anyhow::Result<()> {
2416+
pub fn untrust_current_workspace(&mut self) -> anyhow::Result<()> {
24132417
let Some(path) = doc!(self).path() else {
24142418
bail!("Document does not have a path; it is already untrusted.")
24152419
};
24162420
let workspace = helix_loader::find_workspace_in(path).0;
2421+
self.untrust_workspace(workspace)
2422+
}
2423+
2424+
pub fn untrust_workspace(&mut self, workspace: impl AsRef<Path>) -> anyhow::Result<()> {
24172425
match trust_db::untrust_path(&workspace) {
24182426
Err(e) => bail!("Couldn't edit trust database: {e}"),
24192427
Ok(was_removed) => {
24202428
if was_removed {
24212429
self.set_status(format!(
24222430
"Workspace '{}' restricted; LSPs, formatters and debuggers do not work.",
2423-
workspace.display()
2431+
workspace.as_ref().display()
24242432
));
24252433
} else {
24262434
self.set_status(format!(
24272435
"Workspace '{}' was already untrusted.",
2428-
workspace.display()
2436+
workspace.as_ref().display()
24292437
));
24302438
}
24312439
self.documents_mut()

0 commit comments

Comments
 (0)