symgraph 2026.6.14

Semantic code intelligence library and MCP server - build knowledge graphs of codebases
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
//! Language-specific configurations for tree-sitter extraction

use tree_sitter::Language as TsLanguage;

use crate::types::{Language, NodeKind};

/// Language-specific configuration for extraction
pub struct LanguageConfig {
    /// Node types that map to functions
    pub function_types: &'static [&'static str],
    /// Node types that map to methods
    pub method_types: &'static [&'static str],
    /// Node types that map to classes
    pub class_types: &'static [&'static str],
    /// Node types that map to structs
    pub struct_types: &'static [&'static str],
    /// Node types that map to interfaces/traits
    pub interface_types: &'static [&'static str],
    /// Node types that map to enums
    pub enum_types: &'static [&'static str],
    /// Node types that map to imports
    pub import_types: &'static [&'static str],
    /// Node types that represent function calls
    pub call_types: &'static [&'static str],
    /// Node types that map to type aliases
    pub type_alias_types: &'static [&'static str],
    /// Node types that map to constants
    pub constant_types: &'static [&'static str],
    /// Node types that map to variables (reserved for future use)
    #[allow(dead_code)]
    pub variable_types: &'static [&'static str],
    /// Node types that map to modules/namespaces
    pub module_types: &'static [&'static str],
    /// Node types that represent a field/member access (e.g. `obj.field`)
    pub field_access_types: &'static [&'static str],
    /// tree-sitter field name holding the accessed member identifier
    /// (e.g. "field" in Rust, "property" in TS, "attribute" in Python).
    /// Empty string disables field-access extraction for the language.
    pub field_name_field: &'static str,
    /// Node types that represent an assignment; the left-hand side of one of
    /// these is treated as a field *write* (Mutates) rather than read.
    pub assignment_types: &'static [&'static str],
    /// Node types that represent a match/switch construct, used to detect
    /// scattered enum dispatch (control coupling).
    pub enum_match_types: &'static [&'static str],
    /// Node types that map to struct/class fields
    pub field_types: &'static [&'static str],
    /// Node types that map to enum variants/members
    pub enum_member_types: &'static [&'static str],
}

impl LanguageConfig {
    /// Convert a tree-sitter node type to our NodeKind
    pub fn node_type_to_kind(&self, node_type: &str) -> Option<NodeKind> {
        if self.function_types.contains(&node_type) {
            return Some(NodeKind::Function);
        }
        if self.method_types.contains(&node_type) {
            return Some(NodeKind::Method);
        }
        if self.class_types.contains(&node_type) {
            return Some(NodeKind::Class);
        }
        if self.struct_types.contains(&node_type) {
            return Some(NodeKind::Struct);
        }
        if self.interface_types.contains(&node_type) {
            return Some(NodeKind::Interface);
        }
        if self.enum_types.contains(&node_type) {
            return Some(NodeKind::Enum);
        }
        // Enum members before fields: some grammars reuse field-ish nodes.
        if self.enum_member_types.contains(&node_type) {
            return Some(NodeKind::EnumMember);
        }
        if self.field_types.contains(&node_type) {
            return Some(NodeKind::Field);
        }
        if self.import_types.contains(&node_type) {
            return Some(NodeKind::Import);
        }
        if self.type_alias_types.contains(&node_type) {
            return Some(NodeKind::TypeAlias);
        }
        if self.constant_types.contains(&node_type) {
            return Some(NodeKind::Constant);
        }
        if self.module_types.contains(&node_type) {
            return Some(NodeKind::Module);
        }
        None
    }

    /// Check if a node type represents a function call
    pub fn is_call_node(&self, node_type: &str) -> bool {
        self.call_types.contains(&node_type)
    }

    /// Check if a node type represents a field/member access
    pub fn is_field_access_node(&self, node_type: &str) -> bool {
        !self.field_name_field.is_empty() && self.field_access_types.contains(&node_type)
    }

    /// Check if a node type represents an assignment
    pub fn is_assignment_node(&self, node_type: &str) -> bool {
        self.assignment_types.contains(&node_type)
    }

    /// Check if a node type represents an import statement
    pub fn is_import_node(&self, node_type: &str) -> bool {
        self.import_types.contains(&node_type)
    }

    /// Check if a node type represents a match/switch construct
    pub fn is_enum_match_node(&self, node_type: &str) -> bool {
        self.enum_match_types.contains(&node_type)
    }
}

/// Get the tree-sitter language for a given Language
pub fn get_language(lang: Language) -> Option<TsLanguage> {
    match lang {
        Language::Rust => Some(tree_sitter_rust::LANGUAGE.into()),
        Language::TypeScript | Language::Tsx => {
            Some(tree_sitter_typescript::LANGUAGE_TYPESCRIPT.into())
        }
        Language::JavaScript | Language::Jsx => Some(tree_sitter_javascript::LANGUAGE.into()),
        Language::Python => Some(tree_sitter_python::LANGUAGE.into()),
        Language::Go => Some(tree_sitter_go::LANGUAGE.into()),
        Language::Java => Some(tree_sitter_java::LANGUAGE.into()),
        Language::C => Some(tree_sitter_c::LANGUAGE.into()),
        Language::Cpp => Some(tree_sitter_cpp::LANGUAGE.into()),
        Language::CSharp => Some(tree_sitter_c_sharp::LANGUAGE.into()),
        Language::Kotlin => Some(tree_sitter_kotlin_ng::LANGUAGE.into()),
        Language::Scala => Some(tree_sitter_scala::LANGUAGE.into()),
        Language::Groovy => Some(tree_sitter_groovy::LANGUAGE.into()),
        Language::Ruby => Some(tree_sitter_ruby::LANGUAGE.into()),
        _ => None,
    }
}

/// Get the language configuration for a given Language
pub fn get_config(lang: Language) -> &'static LanguageConfig {
    match lang {
        Language::Rust => &RUST_CONFIG,
        Language::TypeScript | Language::Tsx => &TYPESCRIPT_CONFIG,
        Language::JavaScript | Language::Jsx => &JAVASCRIPT_CONFIG,
        Language::Python => &PYTHON_CONFIG,
        Language::Go => &GO_CONFIG,
        Language::Java => &JAVA_CONFIG,
        Language::C => &C_CONFIG,
        Language::Cpp => &CPP_CONFIG,
        Language::CSharp => &CSHARP_CONFIG,
        Language::Kotlin => &KOTLIN_CONFIG,
        Language::Scala => &SCALA_CONFIG,
        Language::Groovy => &GROOVY_CONFIG,
        Language::Ruby => &RUBY_CONFIG,
        _ => &DEFAULT_CONFIG,
    }
}

static DEFAULT_CONFIG: LanguageConfig = LanguageConfig {
    function_types: &[],
    method_types: &[],
    class_types: &[],
    struct_types: &[],
    interface_types: &[],
    enum_types: &[],
    import_types: &[],
    call_types: &[],
    type_alias_types: &[],
    constant_types: &[],
    variable_types: &[],
    module_types: &[],
    field_access_types: &[],
    field_name_field: "",
    assignment_types: &[],
    enum_match_types: &[],
    field_types: &[],
    enum_member_types: &[],
};

static RUST_CONFIG: LanguageConfig = LanguageConfig {
    function_types: &["function_item"],
    method_types: &["function_item"], // Methods are also function_item in impl blocks
    class_types: &[],
    struct_types: &["struct_item"],
    interface_types: &["trait_item"],
    enum_types: &["enum_item"],
    import_types: &["use_declaration"],
    call_types: &["call_expression", "macro_invocation"],
    type_alias_types: &["type_item"],
    constant_types: &["const_item", "static_item"],
    variable_types: &["let_declaration"],
    module_types: &["mod_item"],
    field_access_types: &["field_expression"],
    field_name_field: "field",
    assignment_types: &["assignment_expression", "compound_assignment_expr"],
    enum_match_types: &["match_expression"],
    field_types: &["field_declaration"],
    enum_member_types: &["enum_variant"],
};

static TYPESCRIPT_CONFIG: LanguageConfig = LanguageConfig {
    function_types: &[
        "function_declaration",
        "arrow_function",
        "function_expression",
        "generator_function_declaration",
    ],
    method_types: &["method_definition", "method_signature"],
    class_types: &["class_declaration", "class"],
    struct_types: &[],
    interface_types: &["interface_declaration"],
    enum_types: &["enum_declaration"],
    import_types: &["import_statement", "import_clause"],
    call_types: &["call_expression", "new_expression"],
    type_alias_types: &["type_alias_declaration"],
    constant_types: &[],
    variable_types: &["variable_declaration", "lexical_declaration"],
    module_types: &["module", "namespace_declaration"],
    field_access_types: &["member_expression"],
    field_name_field: "property",
    assignment_types: &["assignment_expression", "augmented_assignment_expression"],
    enum_match_types: &["switch_statement"],
    field_types: &["public_field_definition", "property_signature"],
    enum_member_types: &["enum_assignment"],
};

static JAVASCRIPT_CONFIG: LanguageConfig = LanguageConfig {
    function_types: &[
        "function_declaration",
        "arrow_function",
        "function_expression",
        "generator_function_declaration",
    ],
    method_types: &["method_definition"],
    class_types: &["class_declaration", "class"],
    struct_types: &[],
    interface_types: &[],
    enum_types: &[],
    import_types: &["import_statement"],
    call_types: &["call_expression", "new_expression"],
    type_alias_types: &[],
    constant_types: &[],
    variable_types: &["variable_declaration", "lexical_declaration"],
    module_types: &[],
    field_access_types: &["member_expression"],
    field_name_field: "property",
    assignment_types: &["assignment_expression", "augmented_assignment_expression"],
    enum_match_types: &["switch_statement"],
    field_types: &[],
    enum_member_types: &[],
};

static PYTHON_CONFIG: LanguageConfig = LanguageConfig {
    function_types: &["function_definition"],
    method_types: &[], // Python methods are function_definition inside class
    class_types: &["class_definition"],
    struct_types: &[],
    interface_types: &[],
    enum_types: &[],
    import_types: &["import_statement", "import_from_statement"],
    call_types: &["call"],
    type_alias_types: &[],
    constant_types: &[],
    variable_types: &["assignment"],
    module_types: &[],
    field_access_types: &["attribute"],
    field_name_field: "attribute",
    assignment_types: &["assignment", "augmented_assignment"],
    enum_match_types: &["match_statement"],
    field_types: &[],
    enum_member_types: &[],
};

static GO_CONFIG: LanguageConfig = LanguageConfig {
    function_types: &["function_declaration"],
    method_types: &["method_declaration"],
    class_types: &[],
    struct_types: &["type_declaration"], // Go structs are type declarations
    interface_types: &["type_declaration"], // Go interfaces too
    enum_types: &[],
    import_types: &["import_declaration", "import_spec"],
    call_types: &["call_expression"],
    type_alias_types: &["type_alias"],
    constant_types: &["const_declaration"],
    variable_types: &["var_declaration", "short_var_declaration"],
    module_types: &["package_clause"],
    field_access_types: &[],
    field_name_field: "",
    assignment_types: &[],
    enum_match_types: &[],
    field_types: &[],
    enum_member_types: &[],
};

static JAVA_CONFIG: LanguageConfig = LanguageConfig {
    function_types: &[],
    method_types: &["method_declaration", "constructor_declaration"],
    class_types: &["class_declaration"],
    struct_types: &[],
    interface_types: &["interface_declaration"],
    enum_types: &["enum_declaration"],
    import_types: &["import_declaration"],
    call_types: &["method_invocation", "object_creation_expression"],
    type_alias_types: &[],
    constant_types: &["field_declaration"],
    variable_types: &["local_variable_declaration"],
    module_types: &["package_declaration"],
    field_access_types: &[],
    field_name_field: "",
    assignment_types: &[],
    enum_match_types: &[],
    field_types: &[],
    enum_member_types: &[],
};

static C_CONFIG: LanguageConfig = LanguageConfig {
    function_types: &["function_definition"],
    method_types: &[],
    class_types: &[],
    struct_types: &["struct_specifier"],
    interface_types: &[],
    enum_types: &["enum_specifier"],
    import_types: &["preproc_include"],
    call_types: &["call_expression"],
    type_alias_types: &["type_definition"],
    constant_types: &["preproc_def"],
    variable_types: &["declaration"],
    module_types: &[],
    field_access_types: &[],
    field_name_field: "",
    assignment_types: &[],
    enum_match_types: &[],
    field_types: &[],
    enum_member_types: &[],
};

static CPP_CONFIG: LanguageConfig = LanguageConfig {
    function_types: &["function_definition"],
    method_types: &["function_definition"], // Methods are function_definition inside class
    class_types: &["class_specifier"],
    struct_types: &["struct_specifier"],
    interface_types: &[],
    enum_types: &["enum_specifier"],
    import_types: &["preproc_include"],
    call_types: &["call_expression"],
    type_alias_types: &["type_definition", "alias_declaration"],
    constant_types: &["preproc_def"],
    variable_types: &["declaration"],
    module_types: &["namespace_definition"],
    field_access_types: &[],
    field_name_field: "",
    assignment_types: &[],
    enum_match_types: &[],
    field_types: &[],
    enum_member_types: &[],
};

static CSHARP_CONFIG: LanguageConfig = LanguageConfig {
    function_types: &[],
    method_types: &[
        "method_declaration",
        "constructor_declaration",
        "destructor_declaration",
        "operator_declaration",
        "conversion_operator_declaration",
    ],
    class_types: &["class_declaration", "record_declaration"],
    struct_types: &["struct_declaration"],
    interface_types: &["interface_declaration"],
    enum_types: &["enum_declaration"],
    import_types: &["using_directive"],
    call_types: &["invocation_expression", "object_creation_expression"],
    type_alias_types: &["delegate_declaration"],
    constant_types: &["field_declaration"], // C# constants are field_declaration with const modifier
    variable_types: &["variable_declaration"],
    module_types: &["namespace_declaration"],
    field_access_types: &[],
    field_name_field: "",
    assignment_types: &[],
    enum_match_types: &[],
    field_types: &[],
    enum_member_types: &[],
};

static KOTLIN_CONFIG: LanguageConfig = LanguageConfig {
    function_types: &["function_declaration", "anonymous_function"],
    method_types: &["function_declaration"], // Methods are function_declaration inside class
    class_types: &["class_declaration", "object_declaration"],
    struct_types: &[],
    interface_types: &["class_declaration"], // Interfaces use class_declaration with interface modifier
    enum_types: &["class_declaration"],      // Enums use class_declaration with enum modifier
    import_types: &["import"],
    call_types: &["call_expression", "constructor_invocation"],
    type_alias_types: &["type_alias"],
    constant_types: &["property_declaration"],
    variable_types: &["property_declaration"],
    module_types: &["package_header", "companion_object"],
    field_access_types: &[],
    field_name_field: "",
    assignment_types: &[],
    enum_match_types: &[],
    field_types: &[],
    enum_member_types: &[],
};

static SCALA_CONFIG: LanguageConfig = LanguageConfig {
    function_types: &["function_definition", "function_declaration"],
    method_types: &["function_definition", "function_declaration"],
    class_types: &["class_definition", "object_definition"],
    struct_types: &[],
    interface_types: &["trait_definition"],
    enum_types: &["enum_definition"],
    import_types: &["import_declaration"],
    call_types: &["call_expression"],
    type_alias_types: &["type_definition"],
    constant_types: &["val_definition", "val_declaration"],
    variable_types: &["var_definition", "var_declaration"],
    module_types: &["package_clause", "package_object"],
    field_access_types: &[],
    field_name_field: "",
    assignment_types: &[],
    enum_match_types: &[],
    field_types: &[],
    enum_member_types: &[],
};

static RUBY_CONFIG: LanguageConfig = LanguageConfig {
    function_types: &["method", "singleton_method"],
    method_types: &["method", "singleton_method"],
    class_types: &["class"],
    struct_types: &[],
    interface_types: &["module"],
    enum_types: &[],
    import_types: &["call"], // require/require_relative are call expressions
    call_types: &["call", "method_call"],
    type_alias_types: &[],
    constant_types: &["assignment"], // ALLCAPS = ... — best-effort
    variable_types: &["assignment"],
    module_types: &["module"],
    field_access_types: &[],
    field_name_field: "",
    assignment_types: &[],
    enum_match_types: &[],
    field_types: &[],
    enum_member_types: &[],
};

static GROOVY_CONFIG: LanguageConfig = LanguageConfig {
    function_types: &["function_definition"],
    method_types: &["method_declaration", "constructor_declaration"],
    class_types: &["class_declaration"],
    struct_types: &[],
    interface_types: &["interface_declaration"],
    enum_types: &["enum_declaration"],
    import_types: &["import_declaration"],
    call_types: &[
        "method_invocation",
        "juxt_function_call",
        "object_creation_expression",
    ],
    type_alias_types: &[],
    constant_types: &["constant_declaration", "field_declaration"],
    variable_types: &["local_variable_declaration"],
    module_types: &["package_declaration"],
    field_access_types: &[],
    field_name_field: "",
    assignment_types: &[],
    enum_match_types: &[],
    field_types: &[],
    enum_member_types: &[],
};