Skip to content

Commit

Permalink
idk what changes these were but idc rn
Browse files Browse the repository at this point in the history
  • Loading branch information
Feel-ix-343 committed Nov 18, 2023
1 parent 4f1e8aa commit f58d5ca
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 183 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"

[dependencies]
itertools = "0.10.5"
once_cell = "1.18.0"
rayon = "1.7.0"
regex = "1.10.2"
tree-sitter = "0.20.10"
Expand Down
77 changes: 30 additions & 47 deletions src/ide/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{path::Path, collections::HashMap};
use itertools::Itertools;
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};

use super::parsing::{Vault, get_parsed_vault, Match};
use super::parsing::{Vault, Match};

//pub mod graph;
//pub mod analyzer;
Expand All @@ -17,71 +17,54 @@ pub struct Analysis {

impl Analysis {
pub fn new(dir: &str) -> Result<Analysis, std::io::Error> {
let vault = get_parsed_vault(dir)?;
let vault = Vault::new(dir)?;

return Ok(Analysis {
vault
})
}

/// Find all of the paragraphs and headings that have this file_ref as an outgoing link. Return a match to these paragraphs and headings
pub fn file_incoming(&self, file_ref: &str) -> Option<Vec<&Match>> {
let file_ref_string = String::from(file_ref);
pub fn get_references() {
// Get the linking node that the cursor is over through getting all linking nodes in the file and if not on any of them, return the file itself.

let paragraph_matches = self.vault.files.iter()
.flat_map(|(r, f)| &f.paragraphs)
.filter(|p| p.resolved_links.iter().map(|l| &l.link_ref).any(|l| l == &file_ref_string || l.starts_with(&format!("{}#", file_ref_string))))
.map(|p| &p.file_match)
.collect_vec();
// Find links that reference this node
}

let heading_matches = self.vault.files.iter()
.flat_map(|(r, f)| &f.headings)
.filter(|h| h.resolved_links.iter().map(|l| &l.link_ref).any(|l| l == &file_ref_string || l.starts_with(&format!("{}#", file_ref_string))))
.map(|p| &p.file_match)
.collect_vec();

let matches = paragraph_matches.into_iter().chain(heading_matches.into_iter()).collect_vec();
if matches.is_empty() {
return None;
} else {
return Some(matches)
}
}
pub fn file_incoming(&self, file_ref: &str) -> Vec<&Match> {
let file_ref_string = String::from(file_ref);

pub fn heading_incoming(&self, file_ref: &str, heading: &str) -> Option<Vec<&Match>> {
let heading_ref = format!("{}#{}", file_ref, heading);
let paragraph_matches = self.vault.files.iter()
.flat_map(|(r, f)| &f.paragraphs)
.filter(|p| p.resolved_links.iter().map(|l| &l.link_ref).contains(&heading_ref))
.map(|p| &p.file_match)
// Check all linking nodes in the vault for this file_ref.
return self.vault.get_linking_nodes().iter()
.flat_map(|n| n.get_links())
.filter(|l| l.link_ref == file_ref_string || l.link_ref.starts_with(&format!("{}#", file_ref_string)))
.map(|l| &l.link_match)
.collect_vec();
}

let heading_matches = self.vault.files.iter()
.flat_map(|(r, f)| &f.headings)
.filter(|h| h.resolved_links.iter().map(|l| &l.link_ref).contains(&heading_ref))
.map(|p| &p.file_match)
pub fn heading_incoming(&self, file_ref: &str, heading: &str) -> Vec<&Match> {
let heading_ref = format!("{}#{}", file_ref, heading);
return self.vault.get_linking_nodes().iter()
.flat_map(|n| n.get_links())
.filter(|l| l.link_ref == heading_ref)
.map(|l| &l.link_match)
.collect_vec();

let matches = paragraph_matches.into_iter().chain(heading_matches.into_iter()).collect_vec();
if matches.is_empty() {
return None;
} else {
return Some(matches)
}
}

pub fn tags_incoming(&self, tag: &str) -> Option<Vec<&Match>> {
let tags = self.vault.files.iter()
pub fn tags_incoming(&self, tag: &str) -> Vec<&Match> {
return self.vault.files.iter()
.flat_map(|(_r, f)| &f.tags)
.filter(|t| t.tag == String::from(tag) || t.tag.starts_with(&format!("{}/", tag)))
.map(|t| &t.file_match)
.collect_vec();
}

if tags.is_empty() {
return None
} else {
return Some(tags)
}

pub fn block_incoming(&self, file_ref: &str, block_index: &str) -> Vec<&Match> {
let block_ref = format!("{}#^{}", file_ref, block_index);
return self.vault.get_linking_nodes().iter()
.flat_map(|n| n.get_links())
.filter(|l| l.link_ref == block_ref)
.map(|l| &l.link_match)
.collect_vec()
}
}
Loading

0 comments on commit f58d5ca

Please sign in to comment.