Skip to main content

normalize_languages/
ini.rs

1//! INI configuration file support.
2
3use crate::{Language, LanguageSymbols};
4use tree_sitter::Node;
5
6/// INI language support.
7pub struct Ini;
8
9impl Language for Ini {
10    fn name(&self) -> &'static str {
11        "INI"
12    }
13    fn extensions(&self) -> &'static [&'static str] {
14        &["ini", "cfg", "conf", "properties"]
15    }
16    fn grammar_name(&self) -> &'static str {
17        "ini"
18    }
19
20    fn as_symbols(&self) -> Option<&dyn LanguageSymbols> {
21        Some(self)
22    }
23
24    fn node_name<'a>(&self, node: &Node, content: &'a str) -> Option<&'a str> {
25        node.child_by_field_name("name")
26            .map(|n| &content[n.byte_range()])
27            .map(|s| s.trim_matches(|c| c == '[' || c == ']'))
28    }
29}
30
31impl LanguageSymbols for Ini {}
32
33#[cfg(test)]
34mod tests {
35    use super::*;
36    use crate::validate_unused_kinds_audit;
37
38    #[test]
39    fn unused_node_kinds_audit() {
40        #[rustfmt::skip]
41        let documented_unused: &[&str] = &[];
42        validate_unused_kinds_audit(&Ini, documented_unused)
43            .expect("INI unused node kinds audit failed");
44    }
45}