Skip to main content

dk_engine/parser/langs/
go.rs

1//! Go language configuration for the query-driven parser.
2
3use crate::parser::lang_config::{CommentStyle, LanguageConfig};
4use dk_core::Visibility;
5use tree_sitter::Language;
6
7/// Go language configuration for [`QueryDrivenParser`](crate::parser::engine::QueryDrivenParser).
8pub struct GoConfig;
9
10impl LanguageConfig for GoConfig {
11    fn language(&self) -> Language {
12        tree_sitter_go::LANGUAGE.into()
13    }
14
15    fn extensions(&self) -> &'static [&'static str] {
16        &["go"]
17    }
18
19    fn symbols_query(&self) -> &'static str {
20        include_str!("../queries/go_symbols.scm")
21    }
22
23    fn calls_query(&self) -> &'static str {
24        include_str!("../queries/go_calls.scm")
25    }
26
27    fn imports_query(&self) -> &'static str {
28        include_str!("../queries/go_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        // Go visibility: uppercase first letter = exported (Public),
37        // lowercase = unexported (Private).
38        match name.chars().next() {
39            Some(c) if c.is_uppercase() => Visibility::Public,
40            _ => Visibility::Private,
41        }
42    }
43
44    fn is_external_import(&self, _module_path: &str) -> bool {
45        // Go standard library packages have no dots in the path.
46        // Third-party packages use domain-based paths (e.g. "github.com/...").
47        // We treat both as external since Go doesn't have relative imports.
48        // The only truly "internal" packages would be in the same module,
49        // but we can't determine that without go.mod context.
50        true
51    }
52}