Struct Config

Source
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

Source

pub fn find_config_file() -> Result<Option<PathBuf>>

Source

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 the TREE_SITTER_DIR environment variable is set
  • tree-sitter/config.json in your default user configuration directory, as determined by etcetera::choose_base_strategy
  • $HOME/.tree-sitter/config.json as a fallback from where tree-sitter used to store its configuration
Source

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.)

Source

pub fn save(&self) -> Result<()>

Saves this configuration to the file that it was originally loaded from.

Source

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.

Source

pub fn add<C>(&mut self, config: C) -> Result<()>
where C: Serialize,

Adds a component-specific configuration to the configuration file. The type C must be serializable into a JSON object, and must only include the fields relevant to that component.

Trait Implementations§

Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Config

§

impl RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl UnwindSafe for Config

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.