Skip to main content

dk_engine/parser/langs/
ruby.rs

1//! Ruby 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/// Ruby language configuration for [`QueryDrivenParser`](crate::parser::engine::QueryDrivenParser).
8pub struct RubyConfig;
9
10impl LanguageConfig for RubyConfig {
11    fn language(&self) -> Language {
12        tree_sitter_ruby::LANGUAGE.into()
13    }
14
15    fn extensions(&self) -> &'static [&'static str] {
16        &["rb"]
17    }
18
19    fn symbols_query(&self) -> &'static str {
20        include_str!("../queries/ruby_symbols.scm")
21    }
22
23    fn calls_query(&self) -> &'static str {
24        include_str!("../queries/ruby_calls.scm")
25    }
26
27    fn imports_query(&self) -> &'static str {
28        include_str!("../queries/ruby_imports.scm")
29    }
30
31    fn comment_style(&self) -> CommentStyle {
32        CommentStyle::Hash
33    }
34
35    fn resolve_visibility(&self, _modifiers: Option<&str>, _name: &str) -> Visibility {
36        // Ruby methods are public by default. The `private`/`protected`
37        // keywords are method calls that change visibility for subsequent
38        // definitions, but they don't appear as AST modifiers on the method
39        // node itself. We default everything to Public.
40        Visibility::Public
41    }
42
43    fn is_external_import(&self, module_path: &str) -> bool {
44        // `require` imports are external (gems, stdlib).
45        // `require_relative` imports are handled by the engine's @_relative
46        // capture — they are always marked internal before this method is
47        // called. This method only runs for `require` calls.
48        //
49        // Paths starting with '.' are also internal (e.g. require './foo').
50        !module_path.starts_with('.')
51    }
52}