@@ -3,7 +3,7 @@ use errors::*;
33use std::borrow::Cow;
44use std::fs::{self, File};
55use std::io;
6−use std::path::PathBuf;
6+use std::path::{Path, PathBuf};
77use syntect::dumps::{dump_to_file, from_binary, from_reader};
88use syntect::highlighting::{Theme, ThemeSet};
99use syntect::parsing::SyntaxSet;
@@ -22,11 +22,10 @@ impl HighlightingAssets {
2222 Self::from_cache().unwrap_or_else(|_| Self::from_binary())
2323 }
2424
25− pub fn from_files() -> Result<Self> {
26− let config_dir = PROJECT_DIRS.config_dir();
27−
28− let theme_dir = config_dir.join("themes");
25+ pub fn from_files(dir: Option<&Path>) -> Result<Self> {
26+ let source_dir = dir.unwrap_or_else(|| PROJECT_DIRS.config_dir());
2927
28+ let theme_dir = source_dir.join("themes");
3029 let theme_set = ThemeSet::load_from_folder(&theme_dir).map_err(|_| {
3130 io::Error::new(
3231 io::ErrorKind::Other,
@@ -38,7 +37,13 @@ impl HighlightingAssets {
3837 })?;
3938
4039 let mut syntax_set = SyntaxSet::new();
41− let syntax_dir = config_dir.join("syntax");
40+ let syntax_dir = source_dir.join("syntaxes");
41+ if !syntax_dir.exists() {
42+ return Err(format!(
43+ "Could not load syntaxes from '{}'",
44+ syntax_dir.to_string_lossy()
45+ ).into());
46+ }
4247 let _ = syntax_set.load_syntaxes(syntax_dir, true);
4348 syntax_set.load_plain_text_syntax();
4449
@@ -77,9 +82,9 @@ impl HighlightingAssets {
7782 }
7883
7984 fn from_binary() -> Self {
80− let mut syntax_set: SyntaxSet = from_binary(include_bytes!("../assets/syntax_set"));
85+ let mut syntax_set: SyntaxSet = from_binary(include_bytes!("../assets/syntaxes.bin"));
8186 syntax_set.link_syntaxes();
82− let theme_set: ThemeSet = from_binary(include_bytes!("../assets/theme_set"));
87+ let theme_set: ThemeSet = from_binary(include_bytes!("../assets/themes.bin"));
8388
8489 HighlightingAssets {
8590 syntax_set,
@@ -87,11 +92,11 @@ impl HighlightingAssets {
8792 }
8893 }
8994
90− pub fn save(&self) -> Result<()> {
91− let cache_dir = PROJECT_DIRS.cache_dir();
92− let _ = fs::create_dir(cache_dir);
93− let theme_set_path = theme_set_path();
94− let syntax_set_path = syntax_set_path();
95+ pub fn save(&self, dir: Option<&Path>) -> Result<()> {
96+ let target_dir = dir.unwrap_or_else(|| PROJECT_DIRS.cache_dir());
97+ let _ = fs::create_dir(target_dir);
98+ let theme_set_path = target_dir.join("themes.bin");
99+ let syntax_set_path = target_dir.join("syntaxes.bin");
95100
96101 print!(
97102 "Writing theme set to {} ... ",
@@ -137,11 +142,11 @@ impl HighlightingAssets {
137142}
138143
139144pub fn theme_set_path() -> PathBuf {
140− PROJECT_DIRS.cache_dir().join("theme_set")
145+ PROJECT_DIRS.cache_dir().join("themes.bin")
141146}
142147
143148pub fn syntax_set_path() -> PathBuf {
144− PROJECT_DIRS.cache_dir().join("syntax_set")
149+ PROJECT_DIRS.cache_dir().join("syntaxes.bin")
145150}
146151
147152pub fn config_dir() -> Cow<'static, str> {