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
//! [`LanguageAdapter`] trait — the extension point for per-language AST parsing.
use Path;
use crateFeatureRecord;
/// Extension point for language-specific parsing implementations.
///
/// Implement this trait to add support for a new programming language.
/// Each adapter identifies files by extension and extracts a [`FeatureRecord`]
/// from the file's tree-sitter AST.
///
/// Implementations must be `Send + Sync` to support rayon parallelism. Because
/// `tree_sitter::Parser` is not `Send`, adapters must use `thread_local!`
/// storage for their parsers rather than storing them in the struct.
///
/// # Examples
///
/// ```rust
/// use sdivi_parsing::adapter::LanguageAdapter;
/// use sdivi_parsing::feature_record::FeatureRecord;
/// use std::path::Path;
///
/// struct NoopAdapter;
///
/// impl LanguageAdapter for NoopAdapter {
/// fn language_name(&self) -> &'static str { "noop" }
/// fn file_extensions(&self) -> &[&'static str] { &[".noop"] }
/// fn parse_file(&self, path: &Path, _content: String) -> FeatureRecord {
/// FeatureRecord {
/// path: path.to_path_buf(),
/// language: "noop".to_string(),
/// imports: vec![],
/// exports: vec![],
/// signatures: vec![],
/// pattern_hints: vec![],
/// }
/// }
/// }
///
/// let adapter = NoopAdapter;
/// assert_eq!(adapter.language_name(), "noop");
/// ```