normalize_languages/
fish.rs1use crate::{Import, Language, LanguageSymbols};
4use tree_sitter::Node;
5
6pub struct Fish;
8
9impl Language for Fish {
10 fn name(&self) -> &'static str {
11 "Fish"
12 }
13 fn extensions(&self) -> &'static [&'static str] {
14 &["fish"]
15 }
16 fn grammar_name(&self) -> &'static str {
17 "fish"
18 }
19
20 fn as_symbols(&self) -> Option<&dyn LanguageSymbols> {
21 Some(self)
22 }
23
24 fn extract_imports(&self, node: &Node, content: &str) -> Vec<Import> {
25 if node.kind() != "command" {
26 return Vec::new();
27 }
28
29 let text = &content[node.byte_range()];
30 if !text.starts_with("source ") {
31 return Vec::new();
32 }
33
34 let module = text.strip_prefix("source ").map(|s| s.trim().to_string());
35
36 if let Some(module) = module {
37 return vec![Import {
38 module,
39 names: Vec::new(),
40 alias: None,
41 is_wildcard: false,
42 is_relative: true,
43 line: node.start_position().row + 1,
44 }];
45 }
46
47 Vec::new()
48 }
49
50 fn format_import(&self, import: &Import, _names: Option<&[&str]>) -> String {
51 format!("source {}", import.module)
53 }
54
55 fn is_test_symbol(&self, symbol: &crate::Symbol) -> bool {
56 let name = symbol.name.as_str();
57 match symbol.kind {
58 crate::SymbolKind::Function | crate::SymbolKind::Method => name.starts_with("test_"),
59 crate::SymbolKind::Module => name == "tests" || name == "test",
60 _ => false,
61 }
62 }
63}
64
65impl LanguageSymbols for Fish {}
66
67#[cfg(test)]
68mod tests {
69 use super::*;
70 use crate::validate_unused_kinds_audit;
71
72 #[test]
73 fn unused_node_kinds_audit() {
74 #[rustfmt::skip]
75 let documented_unused: &[&str] = &[
76 "else_clause", "negated_statement", "redirect_statement", "return",
77 "begin_statement",
79 "switch_statement",
80 "for_statement",
81 "case_clause",
82 "if_statement",
83 "else_if_clause",
84 "while_statement",
85 ];
86 validate_unused_kinds_audit(&Fish, documented_unused)
87 .expect("Fish unused node kinds audit failed");
88 }
89}