aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs51
1 files changed, 26 insertions, 25 deletions
diff --git a/src/main.rs b/src/main.rs
index 31bd882..0fe5c93 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,17 +3,13 @@ mod parsers;
use core::str;
use std::{
- cell::RefCell,
- collections::HashMap,
- env::{
+ cell::RefCell, collections::HashMap, env::{
args,
current_dir,
- },
- fs::{
+ }, fs::{
create_dir,
read,
- },
- process::Command,
+ }, ops::Deref, process::Command
};
use dirs::cache_dir;
@@ -22,6 +18,7 @@ use libloading::Library;
use parsers::{
ALIASES,
PARSERS,
+ QUERIES,
};
use tree_sitter::Language;
use tree_sitter_highlight::{
@@ -43,11 +40,6 @@ fn get_config<'a>(
let mut cache_dir = cache_dir().expect("Cache directory should be available");
cache_dir.push("yah");
- let mut query_dir = current_dir().expect("Current directory should be available");
- query_dir.push("nvim-treesitter");
- query_dir.push("queries");
- query_dir.push(lang);
-
let mut parsers_dir = current_dir().expect("Current directory should be available");
parsers_dir.push(".parsers");
if !parsers_dir.exists() {
@@ -133,18 +125,24 @@ fn get_config<'a>(
let mut config = HighlightConfiguration::new(
parser,
*lang,
- read(query_dir.join("highlights.scm"))
- .map(|v| String::from_utf8(v).unwrap())
- .unwrap_or(String::from(""))
- .as_str(),
- read(query_dir.join("injections.scm"))
- .map(|v| String::from_utf8(v).unwrap())
- .unwrap_or(String::from(""))
- .as_str(),
- read(query_dir.join("locals.scm"))
- .map(|v| String::from_utf8(v).unwrap())
- .unwrap_or(String::from(""))
- .as_str(),
+ QUERIES
+ .get(lang)
+ .unwrap()
+ .get("highlights")
+ .map(Deref::deref)
+ .unwrap_or(""),
+ QUERIES
+ .get(lang)
+ .unwrap()
+ .get("injections")
+ .map(Deref::deref)
+ .unwrap_or(""),
+ QUERIES
+ .get(lang)
+ .unwrap()
+ .get("locals")
+ .map(Deref::deref)
+ .unwrap_or(""),
)
.unwrap();
config.configure(HIGHLIGHTS);
@@ -188,7 +186,10 @@ fn main() {
output.extend(b"\"");
})
.unwrap();
- print!("{}", String::from_utf8(renderer.html).expect("`renderer.html` should contain valid UTF-8"))
+ print!(
+ "{}",
+ String::from_utf8(renderer.html).expect("`renderer.html` should contain valid UTF-8")
+ )
} else {
panic!(
"Need <lang> <code_path> as arguments, got {:?}",