pub struct Config {
pub location: PathBuf,
pub config: Value,
}
Expand description
Holds the contents of tree-sitter’s configuration file.
The file typically lives at ~/.config/tree-sitter/config.json
, but see the Config::load
method for the full details on where it might be located.
This type holds the generic JSON content of the configuration file. Individual tree-sitter
components will use the Config::get
method to parse that JSON to extract configuration
fields that are specific to that component.
Fields§
§location: PathBuf
§config: Value
Implementations§
Source§impl Config
impl Config
pub fn find_config_file() -> Result<Option<PathBuf>>
Sourcepub fn load(path: Option<PathBuf>) -> Result<Self>
pub fn load(path: Option<PathBuf>) -> Result<Self>
Locates and loads in the user’s configuration file. We search for the configuration file in the following locations, in order:
- Location specified by the path parameter if provided
$TREE_SITTER_DIR/config.json
, if theTREE_SITTER_DIR
environment variable is settree-sitter/config.json
in your default user configuration directory, as determined byetcetera::choose_base_strategy
$HOME/.tree-sitter/config.json
as a fallback from where tree-sitter used to store its configuration
Sourcepub fn initial() -> Result<Self>
pub fn initial() -> Result<Self>
Creates an empty initial configuration file. You can then use the Config::add
method
to add the component-specific configuration types for any components that want to add
content to the default file, and then use Config::save
to write the configuration to
disk.
(Note that this is typically only done by the tree-sitter init-config
command.)
Sourcepub fn save(&self) -> Result<()>
pub fn save(&self) -> Result<()>
Saves this configuration to the file that it was originally loaded from.
Sourcepub fn get<C>(&self) -> Result<C>where
C: for<'de> Deserialize<'de>,
pub fn get<C>(&self) -> Result<C>where
C: for<'de> Deserialize<'de>,
Parses a component-specific configuration from the configuration file. The type C
must
be deserializable from a JSON
object, and must only include the fields relevant to that component.