chore(config): apply clippy fixes
This commit is contained in:
parent
14641d170d
commit
1b44a6f912
1 changed files with 8 additions and 9 deletions
|
|
@ -39,7 +39,7 @@ impl Config {
|
|||
}
|
||||
|
||||
let legacy_path = dirs::home_dir()
|
||||
.ok_or(anyhow!("Cannot determine home directory"))?
|
||||
.ok_or_else(|| anyhow!("Cannot determine home directory"))?
|
||||
.join(".tree-sitter")
|
||||
.join("config.json");
|
||||
if legacy_path.is_file() {
|
||||
|
|
@ -51,7 +51,7 @@ impl Config {
|
|||
|
||||
fn xdg_config_file() -> Result<PathBuf> {
|
||||
let xdg_path = dirs::config_dir()
|
||||
.ok_or(anyhow!("Cannot determine config directory"))?
|
||||
.ok_or_else(|| anyhow!("Cannot determine config directory"))?
|
||||
.join("tree-sitter")
|
||||
.join("config.json");
|
||||
Ok(xdg_path)
|
||||
|
|
@ -65,16 +65,15 @@ impl Config {
|
|||
/// by [`dirs::config_dir`](https://docs.rs/dirs/*/dirs/fn.config_dir.html)
|
||||
/// - `$HOME/.tree-sitter/config.json` as a fallback from where tree-sitter _used_ to store
|
||||
/// its configuration
|
||||
pub fn load() -> Result<Config> {
|
||||
let location = match Self::find_config_file()? {
|
||||
Some(location) => location,
|
||||
None => return Config::initial(),
|
||||
pub fn load() -> Result<Self> {
|
||||
let Some(location) = Self::find_config_file()? else {
|
||||
return Self::initial();
|
||||
};
|
||||
let content = fs::read_to_string(&location)
|
||||
.with_context(|| format!("Failed to read {}", &location.to_string_lossy()))?;
|
||||
let config = serde_json::from_str(&content)
|
||||
.with_context(|| format!("Bad JSON config {}", &location.to_string_lossy()))?;
|
||||
Ok(Config { location, config })
|
||||
Ok(Self { location, config })
|
||||
}
|
||||
|
||||
/// Creates an empty initial configuration file. You can then use the [`Config::add`][] method
|
||||
|
|
@ -83,7 +82,7 @@ impl Config {
|
|||
/// disk.
|
||||
///
|
||||
/// (Note that this is typically only done by the `tree-sitter init-config` command.)
|
||||
pub fn initial() -> Result<Config> {
|
||||
pub fn initial() -> Result<Self> {
|
||||
let location = if let Ok(path) = env::var("TREE_SITTER_DIR") {
|
||||
let mut path = PathBuf::from(path);
|
||||
path.push("config.json");
|
||||
|
|
@ -92,7 +91,7 @@ impl Config {
|
|||
Self::xdg_config_file()?
|
||||
};
|
||||
let config = serde_json::json!({});
|
||||
Ok(Config { location, config })
|
||||
Ok(Self { location, config })
|
||||
}
|
||||
|
||||
/// Saves this configuration to the file that it was originally loaded from.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue