dk_engine/parser/langs/
swift.rs1use crate::parser::lang_config::{CommentStyle, LanguageConfig};
4use dk_core::{Symbol, SymbolKind, Visibility};
5use tree_sitter::Language;
6
7pub struct SwiftConfig;
9
10impl LanguageConfig for SwiftConfig {
11 fn language(&self) -> Language {
12 tree_sitter_swift::LANGUAGE.into()
13 }
14
15 fn extensions(&self) -> &'static [&'static str] {
16 &["swift"]
17 }
18
19 fn symbols_query(&self) -> &'static str {
20 include_str!("../queries/swift_symbols.scm")
21 }
22
23 fn calls_query(&self) -> &'static str {
24 include_str!("../queries/swift_calls.scm")
25 }
26
27 fn imports_query(&self) -> &'static str {
28 include_str!("../queries/swift_imports.scm")
29 }
30
31 fn comment_style(&self) -> CommentStyle {
32 CommentStyle::SlashSlash
33 }
34
35 fn resolve_visibility(&self, modifiers: Option<&str>, _name: &str) -> Visibility {
36 match modifiers {
37 Some(m) if m.contains("public") => Visibility::Public,
38 Some(m) if m.contains("open") => Visibility::Public,
39 Some(m) if m.contains("fileprivate") => Visibility::Private,
42 Some(m) if m.contains("private") => Visibility::Private,
43 _ => Visibility::Private,
45 }
46 }
47
48 fn adjust_symbol(&self, sym: &mut Symbol, node: &tree_sitter::Node, _source: &[u8]) {
49 if node.kind() == "class_declaration" && sym.kind == SymbolKind::Class {
55 let mut cursor = node.walk();
56 for child in node.children(&mut cursor) {
57 if child.kind() == "enum_class_body" {
58 sym.kind = SymbolKind::Enum;
59 break;
60 }
61 }
62
63 if sym.kind == SymbolKind::Class {
65 let mut cursor = node.walk();
66 for child in node.children(&mut cursor) {
67 if child.kind() == "struct" {
68 sym.kind = SymbolKind::Struct;
69 break;
70 }
71 }
72 }
73 }
74 }
75
76 fn is_external_import(&self, _module_path: &str) -> bool {
77 true
80 }
81}