Skip to content

Commit

Permalink
feat: display appropriate error msg when cwd does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
yo-main committed Jul 10, 2023
1 parent ae7ecf8 commit 70183d3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
20 changes: 18 additions & 2 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2062,7 +2062,7 @@ fn global_search(cx: &mut Context) {
.map(|comp| (0.., std::borrow::Cow::Owned(comp.clone())))
.collect()
},
move |_editor, regex, event| {
move |editor, regex, event| {
if event != PromptEvent::Validate {
return;
}
Expand All @@ -2076,6 +2076,11 @@ fn global_search(cx: &mut Context) {
.build();

let search_root = helix_loader::current_working_dir();
if !search_root.exists() {
editor.set_error("Current working directory does not exist");
return;
}

let dedup_symlinks = file_picker_config.deduplicate_links;
let absolute_root = search_root
.canonicalize()
Expand Down Expand Up @@ -2147,7 +2152,9 @@ fn global_search(cx: &mut Context) {
let call: job::Callback = Callback::EditorCompositor(Box::new(
move |editor: &mut Editor, compositor: &mut Compositor| {
if all_matches.is_empty() {
editor.set_status("No matches found");
if !editor.is_err() {
editor.set_status("No matches found");
}
return;
}

Expand Down Expand Up @@ -2492,6 +2499,10 @@ fn append_mode(cx: &mut Context) {

fn file_picker(cx: &mut Context) {
let root = find_workspace().0;
if !root.exists() {
cx.editor.set_error("Workspace directory does not exist");
return;
}
let picker = ui::file_picker(root, &cx.editor.config());
cx.push_layer(Box::new(overlaid(picker)));
}
Expand All @@ -2514,6 +2525,11 @@ fn file_picker_in_current_buffer_directory(cx: &mut Context) {
}
fn file_picker_in_current_directory(cx: &mut Context) {
let cwd = helix_loader::current_working_dir();
if !cwd.exists() {
cx.editor
.set_error("Current working directory does not exist");
return;
}
let picker = ui::file_picker(cwd, &cx.editor.config());
cx.push_layer(Box::new(overlaid(picker)));
}
Expand Down
9 changes: 7 additions & 2 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,8 +1112,13 @@ fn show_current_directory(
}

let cwd = helix_loader::current_working_dir();
cx.editor
.set_status(format!("Current working directory is {}", cwd.display()));
let message = format!("Current working directory is {}", cwd.display());

if cwd.exists() {
cx.editor.set_status(message);
} else {
cx.editor.set_error(format!("{} (deleted)", message));
}
Ok(())
}

Expand Down

0 comments on commit 70183d3

Please sign in to comment.