Skip to content

Commit

Permalink
more vault api refactoring. Adding path to each link
Browse files Browse the repository at this point in the history
  • Loading branch information
Feel-ix-343 committed Dec 6, 2023
1 parent 382d16e commit 5d7ad7c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/gotodef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ impl Linkable<'_> {

impl Vault {
/// Select all links ([[Link]]) in a file
pub fn select_links(&self, path: Option<&Path>) -> Option<Vec<&Link>> {
pub fn select_links(&self, path: Option<&Path>) -> Option<Vec<(&Path, &Link)>> {
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?
Expand Down

0 comments on commit 5d7ad7c

Please sign in to comment.