-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
443 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/target | ||
/Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "neorg-breeze" | ||
description = "A library for parsing entire directories of Norg files in a multithreaded fashion." | ||
repository = "https://github.com/nvim-neorg/neorg-breeze" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
anyhow = "1.0.69" | ||
crossbeam-channel = "0.5.7" | ||
neorg-dirman = "0.1.0" | ||
rusty_pool = "0.7.0" | ||
tree-sitter = "0.20.9" | ||
tree-sitter-norg = "0.1.1" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use tree_sitter::Tree; | ||
use rusty_pool::Builder; | ||
use std::io::Read; | ||
use std::fs::File; | ||
use anyhow::{Result, anyhow}; | ||
|
||
pub mod c_functions; | ||
|
||
fn parse_file(filepath: &std::path::PathBuf) -> Result<Tree> { | ||
let mut file = File::open(filepath)?; | ||
|
||
let mut content = String::new(); | ||
file.read_to_string(&mut content)?; | ||
|
||
let mut parser = tree_sitter::Parser::new(); | ||
parser.set_language(tree_sitter_norg::language())?; | ||
|
||
parser.parse(content, None).ok_or_else(|| anyhow!(format!("Parsing for file {} timed out!", filepath.display()))) | ||
} | ||
|
||
// TODO: Change Vec<Option<Tree>> to Result<Vec<Tree>, (Err, output.filter(|x| x.is_some()))> | ||
// | ||
pub fn parse_files(workspace: neorg_dirman::workspace::Workspace) -> Vec<Option<Tree>> { | ||
let files = workspace.files(); | ||
|
||
let threadpool = Builder::new().name("neorg".into()).build(); | ||
|
||
let mut output: Vec<Option<Tree>> = vec![None; files.len()]; | ||
let file_count = files.len(); | ||
|
||
let (tx, rx) = crossbeam_channel::bounded(file_count); | ||
|
||
for (i, file) in files.into_iter().enumerate() { | ||
let tx_clone = tx.clone(); | ||
|
||
threadpool.execute(move || { | ||
let parsed = parse_file(&file).unwrap(); | ||
tx_clone.send((i, parsed)).unwrap(); | ||
}); | ||
} | ||
|
||
for _ in 0..file_count { | ||
let (i, tree) = rx.recv().unwrap(); | ||
output[i] = Some(tree); | ||
} | ||
|
||
output | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use std::path::PathBuf; | ||
use neorg_dirman::workspace::Workspace; | ||
|
||
#[test] | ||
fn test_parse_file() { | ||
let filepath = PathBuf::from("test/example_workspace/file1.norg"); | ||
let tree = parse_file(&filepath).unwrap(); | ||
|
||
assert!(tree.root_node().kind() == "document"); | ||
} | ||
|
||
#[test] | ||
fn test_parse_files() { | ||
let workspace = Workspace { | ||
name: "example workspace".into(), | ||
path: "test/example_workspace".into(), | ||
}; | ||
let trees = parse_files(workspace); | ||
|
||
assert!(trees[0].is_some()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* This is hidden hehe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! | ||
* File 1! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! | ||
* File 2! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! | ||
* File 3! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! | ||
* File 4! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! | ||
* File 5! |
Oops, something went wrong.