From 5d7ad7c8950de517e16fd6c0f32c5c31e7d02380 Mon Sep 17 00:00:00 2001 From: Felix Zeller Date: Tue, 5 Dec 2023 23:54:46 -0500 Subject: [PATCH] more vault api refactoring. Adding path to each link --- src/gotodef.rs | 10 +++++----- src/vault.rs | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/gotodef.rs b/src/gotodef.rs index 3bfe39b8..d6895329 100644 --- a/src/gotodef.rs +++ b/src/gotodef.rs @@ -8,12 +8,12 @@ pub fn goto_definition(vault: &Vault, cursor_position: Position, path: &Path) -> // First, find the link that the cursor is in. Get a links for the file and match the cursor position up to one of them let links = vault.select_links(Some(&path))?; let cursors_link = links.iter().find(|&l| - l.range.start.line <= cursor_position.line && - l.range.end.line >= cursor_position.line && - l.range.start.character <= cursor_position.character && - l.range.end.character >= cursor_position.character + l.1.range.start.line <= cursor_position.line && + l.1.range.end.line >= cursor_position.line && + l.1.range.start.character <= cursor_position.character && + l.1.range.end.character >= cursor_position.character )?; - let reference_text = &cursors_link.reference_text; + let reference_text = &cursors_link.1.reference_text; // Now we have the reference text. We need to find where this is actually referencing, or if it is referencing anything. // Lets get all of the linkable nodes diff --git a/src/vault.rs b/src/vault.rs index a18138fd..9f239e31 100644 --- a/src/vault.rs +++ b/src/vault.rs @@ -181,10 +181,10 @@ impl Linkable<'_> { impl Vault { /// Select all links ([[Link]]) in a file - pub fn select_links(&self, path: Option<&Path>) -> Option> { + pub fn select_links(&self, path: Option<&Path>) -> Option> { match path { - Some(path) => self.files.get(path).map(|md| &md.links).map(|vec| vec.iter().collect()), - None => Some(self.files.values().flat_map(|md| &md.links).collect()) + Some(path) => self.files.get(path).map(|md| &md.links).map(|vec| vec.iter().map(|i| (path, i)).collect()), + None => Some(self.files.iter().map(|(path, md)| md.links.iter().map(|link| (path.as_path(), link))).flatten().collect()) } } // TODO: less cloning?