From f6da4c7c88121b9244990e0644a3782867f6169b Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Fri, 6 Dec 2024 01:08:36 +0000 Subject: [PATCH 1/6] feat: improve information on the amount of files loaded --- helix-term/src/application.rs | 11 +++++++++-- helix-view/src/editor.rs | 6 +++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index a567815fcaa6..b7ec922e7277 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -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 @@ -189,6 +189,7 @@ impl Application { Some(Layout::Horizontal) => Action::HorizontalSplit, None => Action::Load, }; + let old_id = editor.buf_id_by_path(&file); let doc_id = match editor.open(&file, action) { // Ignore irregular files during application init. Err(DocumentOpenError::IrregularFile) => { @@ -196,7 +197,13 @@ impl Application { continue; } Err(err) => return Err(anyhow::anyhow!(err)), - Ok(doc_id) => doc_id, + Ok(doc_id) => { + // We can't open more than 1 buffer for 1 file, in this case we already have opened this file previously + if old_id == Some(doc_id) { + nr_of_files -= 1; + } + doc_id + } }; // with Action::Load all documents have the same view // NOTE: this isn't necessarily true anymore. If diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index aa9a11533bbb..deccdf9023ed 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -1718,10 +1718,14 @@ impl Editor { Ok(doc_id) } + pub fn buf_id_by_path(&self, path: &Path) -> Option { + self.document_by_path(&path).map(|doc| doc.id) + } + // ??? possible use for integration tests pub fn open(&mut self, path: &Path, action: Action) -> Result { let path = helix_stdx::path::canonicalize(path); - let id = self.document_by_path(&path).map(|doc| doc.id); + let id = self.buf_id_by_path(&path); let id = if let Some(id) = id { id From 6370a12418136011bb7b263d8464884f73f7295d Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Fri, 6 Dec 2024 01:16:54 +0000 Subject: [PATCH 2/6] refactor: naming consitency Doc and not Buf --- helix-view/src/editor.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index deccdf9023ed..1ddc0a52752d 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -1718,14 +1718,14 @@ impl Editor { Ok(doc_id) } - pub fn buf_id_by_path(&self, path: &Path) -> Option { + pub fn document_id_by_path(&self, path: &Path) -> Option { self.document_by_path(&path).map(|doc| doc.id) } // ??? possible use for integration tests pub fn open(&mut self, path: &Path, action: Action) -> Result { let path = helix_stdx::path::canonicalize(path); - let id = self.buf_id_by_path(&path); + let id = self.document_id_by_path(&path); let id = if let Some(id) = id { id From 21b05ba1c15a032a93f3fe673f2cc113c2ac70bd Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Fri, 6 Dec 2024 01:20:25 +0000 Subject: [PATCH 3/6] fix: correct name of method --- helix-term/src/application.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index b7ec922e7277..701e58339ec9 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -189,7 +189,7 @@ impl Application { Some(Layout::Horizontal) => Action::HorizontalSplit, None => Action::Load, }; - let old_id = editor.buf_id_by_path(&file); + 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) => { From 13e4527d0b9b6123e41b19355897c651a2a436ca Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Fri, 6 Dec 2024 01:21:02 +0000 Subject: [PATCH 4/6] chore: appease clippy --- helix-view/src/editor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 1ddc0a52752d..4fc3f4700a1e 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -1719,7 +1719,7 @@ impl Editor { } pub fn document_id_by_path(&self, path: &Path) -> Option { - self.document_by_path(&path).map(|doc| doc.id) + self.document_by_path(path).map(|doc| doc.id) } // ??? possible use for integration tests From b06c12711aad1c9deff0b10f6a774841f7601b6d Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Fri, 6 Dec 2024 01:23:36 +0000 Subject: [PATCH 5/6] feat: more human error information when Helix cannot start --- helix-term/src/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs index a3a27a07626a..516bfd7c31b1 100644 --- a/helix-term/src/main.rs +++ b/helix-term/src/main.rs @@ -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?; From 2558b3eb7f783fdb0fa981be3537c54d5671fb63 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Sat, 7 Dec 2024 17:16:04 +0000 Subject: [PATCH 6/6] refatcor: use if guard on match arm --- helix-term/src/application.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 701e58339ec9..36cb295cea4c 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -197,13 +197,12 @@ impl Application { continue; } Err(err) => return Err(anyhow::anyhow!(err)), - Ok(doc_id) => { - // We can't open more than 1 buffer for 1 file, in this case we already have opened this file previously - if old_id == Some(doc_id) { - nr_of_files -= 1; - } + // 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 // NOTE: this isn't necessarily true anymore. If