mirror of
https://github.com/helix-editor/helix.git
synced 2024-12-18 22:11:55 +04:00
fix: report correct amount of files opened and improved error message when Helix can't parse directory as file (#12199)
* feat: improve information on the amount of files loaded * refactor: naming consitency Doc and not Buf * fix: correct name of method * chore: appease clippy * feat: more human error information when Helix cannot start * refatcor: use if guard on match arm
This commit is contained in:
parent
271c32f2e6
commit
db1d84256f
@ -175,7 +175,7 @@ pub fn new(args: Args, config: Config, lang_loader: syntax::Loader) -> Result<Se
|
|||||||
nr_of_files += 1;
|
nr_of_files += 1;
|
||||||
if file.is_dir() {
|
if file.is_dir() {
|
||||||
return Err(anyhow::anyhow!(
|
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 {
|
} else {
|
||||||
// If the user passes in either `--vsplit` or
|
// If the user passes in either `--vsplit` or
|
||||||
@ -189,6 +189,7 @@ pub fn new(args: Args, config: Config, lang_loader: syntax::Loader) -> Result<Se
|
|||||||
Some(Layout::Horizontal) => Action::HorizontalSplit,
|
Some(Layout::Horizontal) => Action::HorizontalSplit,
|
||||||
None => Action::Load,
|
None => Action::Load,
|
||||||
};
|
};
|
||||||
|
let old_id = editor.document_id_by_path(&file);
|
||||||
let doc_id = match editor.open(&file, action) {
|
let doc_id = match editor.open(&file, action) {
|
||||||
// Ignore irregular files during application init.
|
// Ignore irregular files during application init.
|
||||||
Err(DocumentOpenError::IrregularFile) => {
|
Err(DocumentOpenError::IrregularFile) => {
|
||||||
@ -196,6 +197,11 @@ pub fn new(args: Args, config: Config, lang_loader: syntax::Loader) -> Result<Se
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Err(err) => return Err(anyhow::anyhow!(err)),
|
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,
|
Ok(doc_id) => doc_id,
|
||||||
};
|
};
|
||||||
// with Action::Load all documents have the same view
|
// with Action::Load all documents have the same view
|
||||||
|
@ -154,8 +154,7 @@ async fn main_impl() -> Result<i32> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// TODO: use the thread local executor to spawn the application task separately from the work pool
|
// TODO: use the thread local executor to spawn the application task separately from the work pool
|
||||||
let mut app =
|
let mut app = Application::new(args, config, lang_loader).context("unable to start Helix")?;
|
||||||
Application::new(args, config, lang_loader).context("unable to create new application")?;
|
|
||||||
|
|
||||||
let exit_code = app.run(&mut EventStream::new()).await?;
|
let exit_code = app.run(&mut EventStream::new()).await?;
|
||||||
|
|
||||||
|
@ -1718,10 +1718,14 @@ pub fn new_file_from_stdin(&mut self, action: Action) -> Result<DocumentId, Erro
|
|||||||
Ok(doc_id)
|
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
|
// ??? possible use for integration tests
|
||||||
pub fn open(&mut self, path: &Path, action: Action) -> Result<DocumentId, DocumentOpenError> {
|
pub fn open(&mut self, path: &Path, action: Action) -> Result<DocumentId, DocumentOpenError> {
|
||||||
let path = helix_stdx::path::canonicalize(path);
|
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 {
|
let id = if let Some(id) = id {
|
||||||
id
|
id
|
||||||
|
Loading…
Reference in New Issue
Block a user