Function lang_name_from_file_ext

Source
pub fn lang_name_from_file_ext<'cfg>(
    ext: &str,
    grammar_config: &'cfg GrammarConfig,
) -> Result<&'cfg str, LoadingError>
Expand description

Load a language name from a file extension.

This will return the name of a language, like “python” based on the file extension and configured file associations.

§Arguments

  • ext - The file extension string, without the leading period character. For example: “md”, “py”.
  • config - The grammar config. This holds file associations between extensions and language names.

§Errors

This will return an error if an associated language is not found for the given file extension. If this is the case, this function returns an UnsupportedExt error.

§Examples

use libdiffsitter::parse::{GrammarConfig, lang_name_from_file_ext};

let config = GrammarConfig::default();
let lang_name = lang_name_from_file_ext("py", &config);

assert_eq!(lang_name.unwrap(), "python");