forked from Ataraxy-Labs/sem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlanguages.rs
More file actions
1695 lines (1482 loc) · 57.4 KB
/
Copy pathlanguages.rs
File metadata and controls
1695 lines (1482 loc) · 57.4 KB
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
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
use std::collections::HashMap;
use tree_sitter::Language;
use crate::parser::graph::EntityInfo;
pub struct SuppressedNestedEntity {
pub parent_entity_node_type: &'static str,
pub child_entity_node_type: &'static str,
}
#[allow(dead_code)]
pub struct LanguageConfig {
pub id: &'static str,
pub extensions: &'static [&'static str],
pub entity_node_types: &'static [&'static str],
pub container_node_types: &'static [&'static str],
pub call_entity_identifiers: &'static [&'static str],
pub suppressed_nested_entities: &'static [SuppressedNestedEntity],
/// Node types that introduce a new scope. The general (non-container) recursion
/// in visit_node will not descend into these nodes, preventing local variables
/// inside function bodies from being extracted as top-level entities.
pub scope_boundary_types: &'static [&'static str],
pub get_language: fn() -> Option<Language>,
pub scope_resolve: Option<&'static ScopeResolveConfig>,
}
// ─── Scope Resolve Config Types ───────────────────────────────────────────────
/// Configuration for scope-aware reference resolution.
/// Captures the AST node names and strategies that differ per language.
pub struct ScopeResolveConfig {
/// AST node types that create class/struct scopes
pub class_scope_nodes: &'static [&'static str],
/// AST node types that create impl scopes (Rust impl_item, Swift extension)
pub impl_scope_nodes: &'static [&'static str],
/// AST node types that create function/method scopes
pub function_scope_nodes: &'static [&'static str],
/// How to extract the class name from a class scope node
pub class_name_field: ClassNameField,
/// Rules for scanning variable assignments to track types
pub assignment_rules: &'static [AssignmentRule],
/// Node types to recurse into when scanning assignments
pub assignment_recurse_into: &'static [&'static str],
/// Rules for extracting typed parameters from function signatures
pub param_rules: &'static [ParamRule],
/// Field name for return type annotation on function nodes (None = body heuristic only)
pub return_type_field: Option<&'static str>,
/// AST node types that represent function/method calls
pub call_nodes: &'static [&'static str],
/// How call nodes expose the callee. FunctionField = node has a "function" field containing
/// an identifier or member_expression. DirectMethod = node has object+name fields directly.
pub call_style: CallNodeStyle,
/// AST node types for `new Foo()` expressions
pub new_expr_nodes: &'static [&'static str],
/// Field name on new-expression nodes that holds the type/constructor name.
pub new_expr_type_field: &'static str,
/// AST node types for struct/composite literals (Go `Foo{}`)
pub composite_literal_nodes: &'static [&'static str],
/// How member access / method calls are represented in the AST
pub member_access: &'static [MemberAccess],
/// Scoped identifier nodes (Rust `Type::method`)
pub scoped_call_nodes: &'static [&'static str],
/// Self/this keywords to recognize
pub self_keywords: &'static [&'static str],
/// Strategy for extracting instance attribute types
pub init_strategy: InitStrategy,
/// Import extraction function (the only truly per-language piece)
pub import_extractor: Option<ImportExtractorFn>,
/// Whether methods are declared externally with receiver types (Go-style)
pub external_method: bool,
/// Language builtins to skip during resolution
pub builtins: &'static [&'static str],
}
/// How call nodes expose the callee/function.
pub enum CallNodeStyle {
/// The call node has a field (e.g. "function") containing either an identifier
/// (bare call) or a member_expression (method call). Python, TS, Rust, Go, C#, C++.
FunctionField(&'static str),
/// The call node directly has object (optional) + method name fields.
/// Java: method_invocation(object, name). Ruby: call(receiver, method).
DirectMethod { object_field: &'static str, method_field: &'static str },
/// The callee is the first named child of the call node (no field name).
/// Swift: call_expression(simple_identifier|navigation_expression, call_suffix)
/// Kotlin: call_expression(identifier|navigation_expression, value_arguments)
FirstChild,
}
/// How to extract the class/struct name from a scope node.
pub enum ClassNameField {
/// Simple field lookup: `node.child_by_field_name(field)`
Simple(&'static str),
/// Go-style: look for a child of type `spec_kind`, then get field `field` from it
TypeSpec { spec_kind: &'static str, field: &'static str },
/// Rust impl: get name from `node.child_by_field_name(field)` (the "type" field)
ImplType(&'static str),
}
/// A rule for scanning assignment nodes to extract type bindings.
pub struct AssignmentRule {
pub node_kind: &'static str,
pub strategy: AssignmentStrategy,
}
/// Strategy for extracting variable name and type from an assignment node.
pub enum AssignmentStrategy {
/// Python/TS: `x = Foo()` - left/right fields on assignment node
LeftRight,
/// TS: `const x = new Foo()` - variable_declarator children
Declarators,
/// Rust: `let x: Type = value` - pattern + type + value fields
PatternBased,
/// Go: `x := Foo{}` - expression_list left/right
ShortVar,
/// Go: `var x Type = ...` - var_spec children
VarSpec,
}
/// A rule for extracting typed parameters from function signatures.
pub struct ParamRule {
pub node_kind: &'static str,
pub name_field: ParamNameField,
pub type_field: &'static str,
pub skip_names: &'static [&'static str],
}
/// How to extract the parameter name.
pub enum ParamNameField {
/// Simple field name: `child_by_field_name(field)`
Simple(&'static str),
/// Field with fallback to first named child if identifier
WithFallback(&'static str),
/// Rust pattern matching (identifier, mut_pattern, reference_pattern)
RustPattern,
}
/// How member access (obj.field / obj.method()) is represented in the AST.
pub struct MemberAccess {
pub node_kind: &'static str,
pub object_field: &'static str,
pub property_field: &'static str,
}
/// Strategy for extracting instance attribute types from class definitions.
pub enum InitStrategy {
/// Python/TS: scan constructor body for self.attr = param patterns
ConstructorBody {
class_nodes: &'static [&'static str],
init_names: &'static [&'static str],
init_node_kind: &'static str,
self_keyword: &'static str,
access_kind: &'static str,
obj_field: &'static str,
prop_field: &'static str,
},
/// Rust/Go: extract field types directly from struct declarations
StructFields {
struct_nodes: &'static [&'static str],
},
/// No instance attribute tracking
None,
}
/// Function pointer type for import extraction.
pub type ImportExtractorFn = fn(
node: tree_sitter::Node,
file_path: &str,
source: &[u8],
symbol_table: &HashMap<String, Vec<String>>,
entity_map: &HashMap<String, EntityInfo>,
import_table: &mut HashMap<(String, String), String>,
scopes: &mut Vec<crate::parser::scope_resolve::Scope>,
);
/// Import node kind + extractor function pair
pub struct ImportRule {
pub node_kind: &'static str,
pub extractor: ImportExtractorFn,
}
#[cfg(feature = "lang-typescript")]
fn get_typescript() -> Option<Language> {
Some(tree_sitter_typescript::LANGUAGE_TYPESCRIPT.into())
}
#[cfg(feature = "lang-typescript")]
fn get_tsx() -> Option<Language> {
Some(tree_sitter_typescript::LANGUAGE_TSX.into())
}
#[cfg(feature = "lang-javascript")]
fn get_javascript() -> Option<Language> {
Some(tree_sitter_javascript::LANGUAGE.into())
}
#[cfg(feature = "lang-python")]
fn get_python() -> Option<Language> {
Some(tree_sitter_python::LANGUAGE.into())
}
#[cfg(feature = "lang-go")]
fn get_go() -> Option<Language> {
Some(tree_sitter_go::LANGUAGE.into())
}
#[cfg(feature = "lang-rust")]
fn get_rust() -> Option<Language> {
Some(tree_sitter_rust::LANGUAGE.into())
}
#[cfg(feature = "lang-java")]
fn get_java() -> Option<Language> {
Some(tree_sitter_java::LANGUAGE.into())
}
#[cfg(feature = "lang-c")]
fn get_c() -> Option<Language> {
Some(tree_sitter_c::LANGUAGE.into())
}
#[cfg(feature = "lang-cpp")]
fn get_cpp() -> Option<Language> {
Some(tree_sitter_cpp::LANGUAGE.into())
}
#[cfg(feature = "lang-ruby")]
fn get_ruby() -> Option<Language> {
Some(tree_sitter_ruby::LANGUAGE.into())
}
#[cfg(feature = "lang-csharp")]
fn get_csharp() -> Option<Language> {
Some(tree_sitter_c_sharp::LANGUAGE.into())
}
#[cfg(feature = "lang-php")]
fn get_php() -> Option<Language> {
Some(tree_sitter_php::LANGUAGE_PHP.into())
}
#[cfg(feature = "lang-fortran")]
fn get_fortran() -> Option<Language> {
Some(tree_sitter_fortran::LANGUAGE.into())
}
#[cfg(feature = "lang-swift")]
fn get_swift() -> Option<Language> {
Some(tree_sitter_swift::LANGUAGE.into())
}
#[cfg(feature = "lang-elixir")]
fn get_elixir() -> Option<Language> {
Some(tree_sitter_elixir::LANGUAGE.into())
}
#[cfg(feature = "lang-bash")]
fn get_bash() -> Option<Language> {
Some(tree_sitter_bash::LANGUAGE.into())
}
#[cfg(feature = "lang-hcl")]
fn get_hcl() -> Option<Language> {
Some(tree_sitter_hcl::LANGUAGE.into())
}
#[cfg(feature = "lang-kotlin")]
fn get_kotlin() -> Option<Language> {
Some(tree_sitter_kotlin_ng::LANGUAGE.into())
}
#[cfg(feature = "lang-xml")]
fn get_xml() -> Option<Language> {
Some(tree_sitter_xml::LANGUAGE_XML.into())
}
#[cfg(feature = "lang-dart")]
fn get_dart() -> Option<Language> {
Some(tree_sitter_dart::LANGUAGE.into())
}
#[cfg(feature = "lang-perl")]
fn get_perl() -> Option<Language> {
Some(tree_sitter_perl_next::LANGUAGE.into())
}
#[cfg(feature = "lang-ocaml")]
fn get_ocaml() -> Option<Language> {
Some(tree_sitter_ocaml::LANGUAGE_OCAML.into())
}
#[cfg(feature = "lang-ocaml")]
fn get_ocaml_interface() -> Option<Language> {
Some(tree_sitter_ocaml::LANGUAGE_OCAML_INTERFACE.into())
}
#[cfg(feature = "lang-scala")]
fn get_scala() -> Option<Language> {
Some(tree_sitter_scala::LANGUAGE.into())
}
#[cfg(feature = "lang-zig")]
fn get_zig() -> Option<Language> {
Some(tree_sitter_zig::LANGUAGE.into())
}
#[cfg(feature = "lang-nix")]
fn get_nix() -> Option<Language> {
Some(tree_sitter_nix::LANGUAGE.into())
}
/// Inside JS/TS function bodies, suppress variable declarations so that local
/// variables are not extracted as nested entities. Inner function/class
/// declarations are still extracted for diff granularity.
const JS_TS_SUPPRESSED_NESTED: &[SuppressedNestedEntity] = &[
SuppressedNestedEntity {
parent_entity_node_type: "function_declaration",
child_entity_node_type: "lexical_declaration",
},
SuppressedNestedEntity {
parent_entity_node_type: "function_declaration",
child_entity_node_type: "variable_declaration",
},
SuppressedNestedEntity {
parent_entity_node_type: "generator_function_declaration",
child_entity_node_type: "lexical_declaration",
},
SuppressedNestedEntity {
parent_entity_node_type: "generator_function_declaration",
child_entity_node_type: "variable_declaration",
},
SuppressedNestedEntity {
parent_entity_node_type: "method_definition",
child_entity_node_type: "lexical_declaration",
},
SuppressedNestedEntity {
parent_entity_node_type: "method_definition",
child_entity_node_type: "variable_declaration",
},
// Scope boundaries: suppress local variables inside arrow functions,
// function expressions, and generator functions, while still allowing
// inner class/function declarations to be extracted.
SuppressedNestedEntity {
parent_entity_node_type: "arrow_function",
child_entity_node_type: "lexical_declaration",
},
SuppressedNestedEntity {
parent_entity_node_type: "arrow_function",
child_entity_node_type: "variable_declaration",
},
SuppressedNestedEntity {
parent_entity_node_type: "function_expression",
child_entity_node_type: "lexical_declaration",
},
SuppressedNestedEntity {
parent_entity_node_type: "function_expression",
child_entity_node_type: "variable_declaration",
},
SuppressedNestedEntity {
parent_entity_node_type: "generator_function",
child_entity_node_type: "lexical_declaration",
},
SuppressedNestedEntity {
parent_entity_node_type: "generator_function",
child_entity_node_type: "variable_declaration",
},
];
const JS_TS_SCOPE_BOUNDARIES: &[&str] = &[
"arrow_function",
"function_expression",
"generator_function",
];
/// Inside C function bodies, suppress `declaration` nodes so that block-local
/// variables are not extracted as nested entities. Inner type declarations are
/// still reached by traversal after the wrapper is skipped.
const C_SUPPRESSED_NESTED: &[SuppressedNestedEntity] = &[SuppressedNestedEntity {
parent_entity_node_type: "function_definition",
child_entity_node_type: "declaration",
}];
/// Inside C++ function-like bodies, suppress `declaration` nodes so that
/// block-local variables are not extracted as nested entities. Inner type
/// declarations are still reached by traversal after the wrapper is skipped.
const CPP_SUPPRESSED_NESTED: &[SuppressedNestedEntity] = &[
SuppressedNestedEntity {
parent_entity_node_type: "function_definition",
child_entity_node_type: "declaration",
},
SuppressedNestedEntity {
parent_entity_node_type: "lambda_expression",
child_entity_node_type: "declaration",
},
];
const CPP_SCOPE_BOUNDARIES: &[&str] = &["lambda_expression"];
#[cfg(feature = "lang-typescript")]
static TYPESCRIPT_CONFIG: LanguageConfig = LanguageConfig {
id: "typescript",
extensions: &[".ts", ".mts", ".cts"],
entity_node_types: &[
"function_declaration",
"generator_function_declaration",
"class_declaration",
"interface_declaration",
"type_alias_declaration",
"enum_declaration",
"export_statement",
"lexical_declaration",
"variable_declaration",
"method_definition",
"public_field_definition",
"function_signature",
"method_signature",
"property_signature",
],
container_node_types: &["class_body", "interface_body", "enum_body", "statement_block"],
call_entity_identifiers: &[],
suppressed_nested_entities: JS_TS_SUPPRESSED_NESTED,
scope_boundary_types: JS_TS_SCOPE_BOUNDARIES,
get_language: get_typescript,
scope_resolve: Some(&TS_SCOPE_CONFIG),
};
#[cfg(feature = "lang-typescript")]
static TSX_CONFIG: LanguageConfig = LanguageConfig {
id: "tsx",
extensions: &[".tsx"],
entity_node_types: &[
"function_declaration",
"generator_function_declaration",
"class_declaration",
"interface_declaration",
"type_alias_declaration",
"enum_declaration",
"export_statement",
"lexical_declaration",
"variable_declaration",
"method_definition",
"public_field_definition",
"function_signature",
"method_signature",
"property_signature",
],
container_node_types: &["class_body", "interface_body", "enum_body", "statement_block"],
call_entity_identifiers: &[],
suppressed_nested_entities: JS_TS_SUPPRESSED_NESTED,
scope_boundary_types: JS_TS_SCOPE_BOUNDARIES,
get_language: get_tsx,
scope_resolve: Some(&TS_SCOPE_CONFIG),
};
#[cfg(feature = "lang-javascript")]
static JAVASCRIPT_CONFIG: LanguageConfig = LanguageConfig {
id: "javascript",
extensions: &[".js", ".jsx", ".mjs", ".cjs", ".es6"],
entity_node_types: &[
"function_declaration",
"generator_function_declaration",
"class_declaration",
"export_statement",
"lexical_declaration",
"variable_declaration",
"method_definition",
"field_definition",
],
container_node_types: &["class_body", "statement_block"],
call_entity_identifiers: &[],
suppressed_nested_entities: JS_TS_SUPPRESSED_NESTED,
scope_boundary_types: JS_TS_SCOPE_BOUNDARIES,
get_language: get_javascript,
scope_resolve: Some(&TS_SCOPE_CONFIG),
};
#[cfg(feature = "lang-python")]
static PYTHON_CONFIG: LanguageConfig = LanguageConfig {
id: "python",
extensions: &[".py", ".pyi"],
entity_node_types: &[
"function_definition",
"class_definition",
"decorated_definition",
],
container_node_types: &["block"],
call_entity_identifiers: &[],
suppressed_nested_entities: &[],
scope_boundary_types: &[],
get_language: get_python,
scope_resolve: Some(&PYTHON_SCOPE_CONFIG),
};
#[cfg(feature = "lang-go")]
static GO_CONFIG: LanguageConfig = LanguageConfig {
id: "go",
extensions: &[".go"],
entity_node_types: &[
"function_declaration",
"method_declaration",
"type_declaration",
"var_declaration",
"const_declaration",
],
container_node_types: &["block"],
call_entity_identifiers: &[],
suppressed_nested_entities: &[],
scope_boundary_types: &[],
get_language: get_go,
scope_resolve: Some(&GO_SCOPE_CONFIG),
};
#[cfg(feature = "lang-rust")]
static RUST_CONFIG: LanguageConfig = LanguageConfig {
id: "rust",
extensions: &[".rs"],
entity_node_types: &[
"function_item",
"struct_item",
"enum_item",
"impl_item",
"trait_item",
"mod_item",
"const_item",
"static_item",
"type_item",
"macro_definition",
],
container_node_types: &["declaration_list", "block"],
call_entity_identifiers: &[],
suppressed_nested_entities: &[],
scope_boundary_types: &[],
get_language: get_rust,
scope_resolve: Some(&RUST_SCOPE_CONFIG),
};
#[cfg(feature = "lang-java")]
static JAVA_CONFIG: LanguageConfig = LanguageConfig {
id: "java",
extensions: &[".java"],
entity_node_types: &[
"class_declaration",
"method_declaration",
"interface_declaration",
"enum_declaration",
"record_declaration",
"field_declaration",
"constructor_declaration",
"annotation_type_declaration",
],
container_node_types: &["class_body", "interface_body", "enum_body", "record_body", "block"],
call_entity_identifiers: &[],
suppressed_nested_entities: &[],
scope_boundary_types: &[],
get_language: get_java,
scope_resolve: Some(&JAVA_SCOPE_CONFIG),
};
#[cfg(feature = "lang-c")]
static C_CONFIG: LanguageConfig = LanguageConfig {
id: "c",
extensions: &[".c", ".h"],
entity_node_types: &[
"function_definition",
"struct_specifier",
"enum_specifier",
"union_specifier",
"type_definition",
"declaration",
],
container_node_types: &["compound_statement"],
call_entity_identifiers: &[],
suppressed_nested_entities: C_SUPPRESSED_NESTED,
scope_boundary_types: &[],
get_language: get_c,
scope_resolve: None,
};
#[cfg(feature = "lang-cpp")]
static CPP_CONFIG: LanguageConfig = LanguageConfig {
id: "cpp",
extensions: &[".cpp", ".cc", ".cxx", ".hpp", ".hh", ".hxx"],
entity_node_types: &[
"function_definition",
"class_specifier",
"struct_specifier",
"enum_specifier",
"namespace_definition",
"template_declaration",
"declaration",
"type_definition",
],
container_node_types: &["field_declaration_list", "declaration_list", "compound_statement"],
call_entity_identifiers: &[],
suppressed_nested_entities: CPP_SUPPRESSED_NESTED,
scope_boundary_types: CPP_SCOPE_BOUNDARIES,
get_language: get_cpp,
scope_resolve: Some(&CPP_SCOPE_CONFIG),
};
#[cfg(feature = "lang-ruby")]
static RUBY_CONFIG: LanguageConfig = LanguageConfig {
id: "ruby",
extensions: &[".rb"],
entity_node_types: &[
"method",
"singleton_method",
"class",
"module",
],
container_node_types: &["body_statement"],
call_entity_identifiers: &[],
suppressed_nested_entities: &[],
scope_boundary_types: &[],
get_language: get_ruby,
scope_resolve: Some(&RUBY_SCOPE_CONFIG),
};
#[cfg(feature = "lang-csharp")]
static CSHARP_CONFIG: LanguageConfig = LanguageConfig {
id: "csharp",
extensions: &[".cs"],
entity_node_types: &[
"method_declaration",
"class_declaration",
"interface_declaration",
"enum_declaration",
"struct_declaration",
"record_declaration",
"record_struct_declaration",
"namespace_declaration",
"property_declaration",
"constructor_declaration",
"field_declaration",
],
container_node_types: &["declaration_list", "record_body", "block"],
call_entity_identifiers: &[],
suppressed_nested_entities: &[],
scope_boundary_types: &[],
get_language: get_csharp,
scope_resolve: Some(&CSHARP_SCOPE_CONFIG),
};
#[cfg(feature = "lang-php")]
static PHP_CONFIG: LanguageConfig = LanguageConfig {
id: "php",
extensions: &[".php", ".inc", ".phtml", ".module"],
entity_node_types: &[
"function_definition",
"class_declaration",
"method_declaration",
"interface_declaration",
"trait_declaration",
"enum_declaration",
"namespace_definition",
],
container_node_types: &["declaration_list", "enum_declaration_list", "compound_statement"],
call_entity_identifiers: &[],
suppressed_nested_entities: &[],
scope_boundary_types: &[],
get_language: get_php,
scope_resolve: Some(&PHP_SCOPE_CONFIG),
};
#[cfg(feature = "lang-fortran")]
static FORTRAN_CONFIG: LanguageConfig = LanguageConfig {
id: "fortran",
extensions: &[".f90", ".f95", ".f03", ".f08", ".f", ".for"],
entity_node_types: &[
"function",
"subroutine",
"module",
"program",
"interface",
"type_declaration",
],
container_node_types: &["module", "program", "internal_procedures"],
call_entity_identifiers: &[],
suppressed_nested_entities: &[],
scope_boundary_types: &[],
get_language: get_fortran,
scope_resolve: None,
};
#[cfg(feature = "lang-swift")]
static SWIFT_CONFIG: LanguageConfig = LanguageConfig {
id: "swift",
extensions: &[".swift"],
entity_node_types: &[
"function_declaration",
"class_declaration",
"protocol_declaration",
"struct_declaration",
"enum_declaration",
"init_declaration",
"deinit_declaration",
"subscript_declaration",
"typealias_declaration",
"property_declaration",
"operator_declaration",
"associatedtype_declaration",
],
container_node_types: &["class_body", "protocol_body", "enum_class_body", "struct_body", "function_body"],
call_entity_identifiers: &[],
suppressed_nested_entities: &[],
scope_boundary_types: &[],
get_language: get_swift,
scope_resolve: Some(&SWIFT_SCOPE_CONFIG),
};
#[cfg(feature = "lang-elixir")]
static ELIXIR_CONFIG: LanguageConfig = LanguageConfig {
id: "elixir",
extensions: &[".ex", ".exs"],
entity_node_types: &[],
container_node_types: &["do_block"],
call_entity_identifiers: &[
"defmodule", "def", "defp", "defmacro", "defmacrop",
"defguard", "defguardp", "defprotocol", "defimpl",
"defstruct", "defexception", "defdelegate",
],
suppressed_nested_entities: &[],
scope_boundary_types: &[],
get_language: get_elixir,
scope_resolve: None,
};
#[cfg(feature = "lang-bash")]
static BASH_CONFIG: LanguageConfig = LanguageConfig {
id: "bash",
extensions: &[".sh"],
entity_node_types: &["function_definition"],
container_node_types: &["compound_statement"],
call_entity_identifiers: &[],
suppressed_nested_entities: &[],
scope_boundary_types: &[],
get_language: get_bash,
scope_resolve: Some(&BASH_SCOPE_CONFIG),
};
#[cfg(feature = "lang-hcl")]
static HCL_CONFIG: LanguageConfig = LanguageConfig {
id: "hcl",
extensions: &[".hcl", ".tf", ".tfvars"],
entity_node_types: &["block", "attribute"],
container_node_types: &["body"],
call_entity_identifiers: &[],
suppressed_nested_entities: &[SuppressedNestedEntity {
parent_entity_node_type: "block",
child_entity_node_type: "attribute",
}],
scope_boundary_types: &[],
get_language: get_hcl,
scope_resolve: None,
};
#[cfg(feature = "lang-kotlin")]
static KOTLIN_CONFIG: LanguageConfig = LanguageConfig {
id: "kotlin",
extensions: &[".kt", ".kts"],
entity_node_types: &[
"function_declaration",
"class_declaration",
"object_declaration",
"property_declaration",
"companion_object",
"secondary_constructor",
"type_alias",
],
container_node_types: &["class_body", "enum_class_body"],
call_entity_identifiers: &[],
suppressed_nested_entities: &[],
scope_boundary_types: &[],
get_language: get_kotlin,
scope_resolve: Some(&KOTLIN_SCOPE_CONFIG),
};
#[cfg(feature = "lang-xml")]
static XML_CONFIG: LanguageConfig = LanguageConfig {
id: "xml",
extensions: &[".xml", ".plist", ".svg", ".xhtml", ".csproj", ".fsproj", ".vbproj", ".props", ".targets", ".nuspec", ".resx", ".xaml", ".axml"],
entity_node_types: &["element"],
container_node_types: &["content"],
call_entity_identifiers: &[],
suppressed_nested_entities: &[],
scope_boundary_types: &[],
get_language: get_xml,
scope_resolve: None,
};
#[cfg(feature = "lang-dart")]
static DART_CONFIG: LanguageConfig = LanguageConfig {
id: "dart",
extensions: &[".dart"],
entity_node_types: &[
"class_declaration",
"mixin_declaration",
"extension_declaration",
"extension_type_declaration",
"enum_declaration",
"type_alias",
"class_member",
"function_signature",
"getter_signature",
"setter_signature",
],
container_node_types: &["class_body", "enum_body", "extension_body"],
call_entity_identifiers: &[],
suppressed_nested_entities: &[],
scope_boundary_types: &[],
get_language: get_dart,
scope_resolve: Some(&DART_SCOPE_CONFIG),
};
#[cfg(feature = "lang-perl")]
static PERL_CONFIG: LanguageConfig = LanguageConfig {
id: "perl",
extensions: &[".pl", ".pm", ".t"],
entity_node_types: &[
"subroutine_declaration_statement",
"package_statement",
],
container_node_types: &["block"],
call_entity_identifiers: &[],
suppressed_nested_entities: &[],
scope_boundary_types: &[],
get_language: get_perl,
scope_resolve: None,
};
#[cfg(feature = "lang-ocaml")]
static OCAML_CONFIG: LanguageConfig = LanguageConfig {
id: "ocaml",
extensions: &[".ml"],
entity_node_types: &[
"value_definition",
"module_definition",
"module_type_definition",
"type_definition",
"exception_definition",
"class_definition",
"class_type_definition",
"external",
],
container_node_types: &["structure", "module_binding"],
call_entity_identifiers: &[],
suppressed_nested_entities: &[],
scope_boundary_types: &[],
get_language: get_ocaml,
scope_resolve: None,
};
#[cfg(feature = "lang-ocaml")]
static OCAML_INTERFACE_CONFIG: LanguageConfig = LanguageConfig {
id: "ocaml_interface",
extensions: &[".mli"],
entity_node_types: &[
"value_specification",
"module_definition",
"module_type_definition",
"type_definition",
"exception_definition",
"class_definition",
"class_type_definition",
"external",
],
container_node_types: &["signature", "module_binding"],
call_entity_identifiers: &[],
suppressed_nested_entities: &[],
scope_boundary_types: &[],
get_language: get_ocaml_interface,
scope_resolve: None,
};
#[cfg(feature = "lang-scala")]
static SCALA_CONFIG: LanguageConfig = LanguageConfig {
id: "scala",
extensions: &[".scala", ".sc", ".sbt", ".kojo", ".mill"],
entity_node_types: &[
"class_definition",
"object_definition",
"trait_definition",
"enum_definition",
"function_definition",
"function_declaration",
"val_definition",
"given_definition",
"extension_definition",
"type_definition",
"package_object",
],
container_node_types: &["template_body", "enum_body", "with_template_body"],
call_entity_identifiers: &[],
suppressed_nested_entities: &[],
scope_boundary_types: &[],
get_language: get_scala,
scope_resolve: Some(&SCALA_SCOPE_CONFIG),
};
#[cfg(feature = "lang-zig")]
static ZIG_CONFIG: LanguageConfig = LanguageConfig {
id: "zig",
extensions: &[".zig"],
entity_node_types: &[
"function_declaration",
"test_declaration",
"variable_declaration",
],
container_node_types: &["block"],
call_entity_identifiers: &[],
suppressed_nested_entities: &[
SuppressedNestedEntity {
parent_entity_node_type: "function_declaration",
child_entity_node_type: "variable_declaration",
},
],
scope_boundary_types: &[],
get_language: get_zig,
scope_resolve: Some(&ZIG_SCOPE_CONFIG),
};
#[cfg(feature = "lang-nix")]
static NIX_CONFIG: LanguageConfig = LanguageConfig {
id: "nix",
extensions: &[".nix"],
entity_node_types: &["binding", "inherit", "inherit_from"],
container_node_types: &["binding_set"],
call_entity_identifiers: &[],
suppressed_nested_entities: &[],
scope_boundary_types: &[],
get_language: get_nix,
scope_resolve: None,
};
// ─── Scope Resolve Configs for Supported Languages ────────────────────────────
static PYTHON_SCOPE_CONFIG: ScopeResolveConfig = ScopeResolveConfig {
class_scope_nodes: &["class_definition"],
impl_scope_nodes: &[],
function_scope_nodes: &["function_definition"],
class_name_field: ClassNameField::Simple("name"),
assignment_rules: &[
AssignmentRule { node_kind: "assignment", strategy: AssignmentStrategy::LeftRight },
AssignmentRule { node_kind: "expression_statement", strategy: AssignmentStrategy::LeftRight },
],
assignment_recurse_into: &["block"],
param_rules: &[
ParamRule { node_kind: "typed_parameter", name_field: ParamNameField::WithFallback("name"), type_field: "type", skip_names: &["self", "cls"] },
ParamRule { node_kind: "typed_default_parameter", name_field: ParamNameField::WithFallback("name"), type_field: "type", skip_names: &["self", "cls"] },
],
return_type_field: None,
call_nodes: &["call"],
call_style: CallNodeStyle::FunctionField("function"),
new_expr_nodes: &[],
new_expr_type_field: "constructor",
composite_literal_nodes: &[],
member_access: &[MemberAccess { node_kind: "attribute", object_field: "object", property_field: "attribute" }],
scoped_call_nodes: &[],
self_keywords: &["self", "cls"],
init_strategy: InitStrategy::ConstructorBody {
class_nodes: &["class_definition"],
init_names: &["__init__"],
init_node_kind: "function_definition",
self_keyword: "self",
access_kind: "attribute",
obj_field: "object",
prop_field: "attribute",
},
import_extractor: None, // set via import_rules
external_method: false,
builtins: &[
"print", "len", "range", "str", "int", "float", "bool",
"list", "dict", "set", "tuple", "type", "super",
"isinstance", "issubclass", "getattr", "setattr",
"hasattr", "delattr", "open", "input", "map",
"filter", "zip", "enumerate", "sorted", "reversed",
"min", "max", "sum", "any", "all", "abs",
"round", "format", "repr", "id", "hash",
"ValueError", "TypeError", "KeyError", "RuntimeError",
"Exception", "StopIteration",
],
};