1use crate::{ContainerBody, Import, Language, LanguageSymbols, Visibility};
4use tree_sitter::Node;
5
6pub struct VB;
8
9impl Language for VB {
10 fn name(&self) -> &'static str {
11 "Visual Basic"
12 }
13 fn extensions(&self) -> &'static [&'static str] {
14 &["vb", "vbs"]
15 }
16 fn grammar_name(&self) -> &'static str {
17 "vb"
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() != "imports_statement" {
26 return Vec::new();
27 }
28
29 let text = &content[node.byte_range()];
30 vec![Import {
31 module: text.trim().to_string(),
32 names: Vec::new(),
33 alias: None,
34 is_wildcard: false,
35 is_relative: false,
36 line: node.start_position().row + 1,
37 }]
38 }
39
40 fn format_import(&self, import: &Import, _names: Option<&[&str]>) -> String {
41 format!("Imports {}", import.module)
43 }
44
45 fn get_visibility(&self, node: &Node, content: &str) -> Visibility {
46 let text = &content[node.byte_range()];
47 let lower = text.to_lowercase();
48 if lower.contains("private") {
49 Visibility::Private
50 } else if lower.contains("protected") {
51 Visibility::Protected
52 } else {
53 Visibility::Public
54 }
55 }
56
57 fn is_test_symbol(&self, symbol: &crate::Symbol) -> bool {
58 let name = symbol.name.as_str();
59 match symbol.kind {
60 crate::SymbolKind::Function | crate::SymbolKind::Method => name.starts_with("test_"),
61 crate::SymbolKind::Module => name == "tests" || name == "test",
62 _ => false,
63 }
64 }
65
66 fn test_file_globs(&self) -> &'static [&'static str] {
67 &["**/*Test.vb", "**/*Tests.vb"]
68 }
69
70 fn container_body<'a>(&self, node: &'a Node<'a>) -> Option<Node<'a>> {
71 node.child_by_field_name("body")
72 }
73
74 fn analyze_container_body(
75 &self,
76 body_node: &Node,
77 content: &str,
78 inner_indent: &str,
79 ) -> Option<ContainerBody> {
80 crate::body::analyze_end_body(body_node, content, inner_indent)
81 }
82}
83
84impl LanguageSymbols for VB {}
85
86#[cfg(test)]
87mod tests {
88 use super::*;
89 use crate::validate_unused_kinds_audit;
90
91 #[test]
92 fn unused_node_kinds_audit() {
93 #[rustfmt::skip]
94 let documented_unused: &[&str] = &[
95 "namespace_block",
97 "field_declaration", "constructor_declaration", "event_declaration",
99 "type_declaration", "const_declaration", "enum_member",
100 "statement", "assignment_statement", "compound_assignment_statement",
102 "call_statement", "dim_statement", "redim_statement", "re_dim_clause",
103 "exit_statement", "continue_statement", "return_statement", "goto_statement",
104 "label_statement", "throw_statement", "empty_statement",
105 "try_statement", "catch_block", "finally_block",
107 "case_block", "case_else_block", "else_clause", "elseif_clause",
108 "with_statement", "with_initializer",
109 "using_statement", "sync_lock_statement",
110 "expression", "binary_expression", "unary_expression", "ternary_expression",
112 "parenthesized_expression", "lambda_expression", "new_expression",
113 "type", "generic_type", "array_type", "primitive_type",
115 "type_parameters", "type_parameter", "type_constraint",
116 "type_argument_list", "array_rank_specifier",
117 "as_clause", "inherits_clause", "implements_clause",
119 "modifier", "modifiers",
121 "add_handler_block", "remove_handler_block", "raise_event_block",
123 "identifier", "attribute_block", "option_statements",
125 "relational_operator", "lambda_parameter",
126 "case_clause",
128 "while_statement",
129 "for_statement",
130 "for_each_statement",
131 "imports_statement",
132 "do_statement",
133 "if_statement",
134 "select_case_statement",
135 ];
136 validate_unused_kinds_audit(&VB, documented_unused)
137 .expect("Visual Basic unused node kinds audit failed");
138 }
139}