Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: report correct amount of files opened and improved error message when Helix can't parse directory as file #12199

Merged
merged 6 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl Application {
nr_of_files += 1;
if file.is_dir() {
return Err(anyhow::anyhow!(
"expected a path to file, found a directory. (to open a directory pass it as first argument)"
"expected a path to file, but found a directory: {file:?}. (to open a directory pass it as first argument)"
));
} else {
// If the user passes in either `--vsplit` or
Expand All @@ -189,13 +189,19 @@ impl Application {
Some(Layout::Horizontal) => Action::HorizontalSplit,
None => Action::Load,
};
let old_id = editor.document_id_by_path(&file);
let doc_id = match editor.open(&file, action) {
// Ignore irregular files during application init.
Err(DocumentOpenError::IrregularFile) => {
nr_of_files -= 1;
continue;
}
Err(err) => return Err(anyhow::anyhow!(err)),
// We can't open more than 1 buffer for 1 file, in this case we already have opened this file previously
Ok(doc_id) if old_id == Some(doc_id) => {
nr_of_files -= 1;
doc_id
}
Ok(doc_id) => doc_id,
};
// with Action::Load all documents have the same view
Expand Down
3 changes: 1 addition & 2 deletions helix-term/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ FLAGS:
});

// TODO: use the thread local executor to spawn the application task separately from the work pool
let mut app =
Application::new(args, config, lang_loader).context("unable to create new application")?;
let mut app = Application::new(args, config, lang_loader).context("unable to start Helix")?;

let exit_code = app.run(&mut EventStream::new()).await?;

Expand Down
6 changes: 5 additions & 1 deletion helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1718,10 +1718,14 @@ impl Editor {
Ok(doc_id)
}

pub fn document_id_by_path(&self, path: &Path) -> Option<DocumentId> {
self.document_by_path(path).map(|doc| doc.id)
}

// ??? possible use for integration tests
pub fn open(&mut self, path: &Path, action: Action) -> Result<DocumentId, DocumentOpenError> {
let path = helix_stdx::path::canonicalize(path);
let id = self.document_by_path(&path).map(|doc| doc.id);
let id = self.document_id_by_path(&path);

let id = if let Some(id) = id {
id
Expand Down
Loading