Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gibbz00 committed Jan 24, 2023
1 parent 3cac825 commit 4d02459
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion helix-core/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl LanguageConfigurations {

impl Default for LanguageConfigurations {
fn default() -> Self {
toml::from_slice(&std::fs::read(helix_loader::repo_paths::default_lang_configs()).unwrap())
toml::from_str(&std::fs::read_to_string(helix_loader::repo_paths::default_lang_configs()).unwrap())
.expect("Failed to deserialize built-in languages.toml")
}
}
Expand Down
4 changes: 2 additions & 2 deletions helix-core/tests/indent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ fn test_treesitter_indent(file_name: &str, lang_scope: &str) {

let mut config_file = test_dir;
config_file.push("languages.toml");
let config = std::fs::read(config_file).unwrap();
let config = toml::from_slice(&config).unwrap();
let config = std::fs::read_to_string(config_file).unwrap();
let config = toml::from_str(&config).unwrap();
let loader = Loader::new(config);

// set runtime path so we can find the queries
Expand Down
20 changes: 12 additions & 8 deletions helix-loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ fn merge_toml_by_config_paths(config_paths: Vec<PathBuf>) -> Result<toml::Value,
let mut configs: Vec<toml::Value> = Vec::with_capacity(config_paths.len());
for config_path in config_paths {
if config_path.exists() {
let config_string = std::fs::read(&config_path)?;
let config = toml::from_slice(&config_string)?;
let config_string = std::fs::read_to_string(&config_path)?;
let config = toml::from_str(&config_string)?;
configs.push(config);
}
}
Expand Down Expand Up @@ -263,11 +263,13 @@ mod merge_toml_tests {
indent = { tab-width = 4, unit = " ", test = "aaa" }
"#;

let base: Value = toml::from_slice(include_bytes!("../../languages.toml"))
.expect("Couldn't parse built-in languages config");
// NOTE: Exact duplicate of helix_core::LanguageConfigurations::default()
let default: Value =
toml::from_str(&std::fs::read_to_string(crate::repo_paths::default_lang_configs()).unwrap())
.expect("Failed to deserialize built-in languages.toml");
let user: Value = toml::from_str(USER).unwrap();

let merged = merge_toml_values(base, user, 3);
let merged = merge_toml_values(default, user, 3);
let languages = merged.get("language").unwrap().as_array().unwrap();
let nix = languages
.iter()
Expand Down Expand Up @@ -296,11 +298,13 @@ mod merge_toml_tests {
language-server = { command = "deno", args = ["lsp"] }
"#;

let base: Value = toml::from_slice(include_bytes!("../../languages.toml"))
.expect("Couldn't parse built-in languages config");
// NOTE: Exact duplicate of helix_core::LanguageConfigurations::default()
let default: Value =
toml::from_str(&std::fs::read_to_string(crate::repo_paths::default_lang_configs()).unwrap())
.expect("Failed to deserialize built-in languages.toml");
let user: Value = toml::from_str(USER).unwrap();

let merged = merge_toml_values(base, user, 3);
let merged = merge_toml_values(default, user, 3);
let languages = merged.get("language").unwrap().as_array().unwrap();
let ts = languages
.iter()
Expand Down
4 changes: 2 additions & 2 deletions helix-term/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pub struct Config {
impl Config {
/// Merge user config with system keymap
pub fn merged() -> Result<Self, Error> {
let config_string = std::fs::read(helix_loader::config_file())?;
toml::from_slice(&config_string)
let config_string = std::fs::read_to_string(helix_loader::config_file())?;
toml::from_str(&config_string)
.map(|config: Config| config.merge_in_default_keymap())
.map_err(|error| anyhow!("{}", error))
}
Expand Down
2 changes: 1 addition & 1 deletion helix-term/tests/test/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub async fn test_key_sequence_with_input_text<T: Into<TestCase>>(
/// added in `overrides`.
pub fn test_syntax_conf(overrides: Option<String>) -> LanguageConfigurations {
let mut lang: toml::Value =
toml::from_slice(&std::fs::read(helix_loader::repo_paths::default_lang_configs()).unwrap())
toml::from_str(&std::fs::read_to_string(helix_loader::repo_paths::default_lang_configs()).unwrap())
.unwrap();

for lang_config in lang
Expand Down
8 changes: 4 additions & 4 deletions helix-view/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ use crate::graphics::UnderlineStyle;
pub use crate::graphics::{Color, Modifier, Style};

pub static DEFAULT_THEME_DATA: Lazy<Value> = Lazy::new(|| {
toml::from_slice(&std::fs::read(repo_paths::default_theme()).unwrap())
toml::from_str(&std::fs::read_to_string(repo_paths::default_theme()).unwrap())
.expect("Failed to parse default theme")
});

pub static BASE16_DEFAULT_THEME_DATA: Lazy<Value> = Lazy::new(|| {
toml::from_slice(&std::fs::read(repo_paths::default_base16_theme()).unwrap())
toml::from_str(&std::fs::read_to_string(repo_paths::default_base16_theme()).unwrap())
.expect("Failed to parse base 16 default theme")
});

Expand Down Expand Up @@ -149,8 +149,8 @@ impl Loader {

// Loads the theme data as `toml::Value` first from the user_dir then in default_dir
fn load_toml(&self, path: PathBuf) -> Result<Value> {
let data = std::fs::read(&path)?;
let value = toml::from_slice(data.as_slice())?;
let data = std::fs::read_to_string(&path)?;
let value = toml::from_str(&data)?;

Ok(value)
}
Expand Down
4 changes: 2 additions & 2 deletions xtask/src/themelint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ pub fn lint(file: String) -> Result<(), DynError> {
return Ok(());
}
let path = repo_paths::themes().join(file.clone() + ".toml");
let theme = std::fs::read(&path).unwrap();
let theme: Theme = toml::from_slice(&theme).expect("Failed to parse theme");
let theme = std::fs::read_to_string(&path).unwrap();
let theme: Theme = toml::from_str(&theme).expect("Failed to parse theme");

let mut messages: Vec<String> = vec![];
get_rules().iter().for_each(|lint| match lint {
Expand Down

0 comments on commit 4d02459

Please sign in to comment.