1use std::any::Any;
2use std::path::Path;
3
4use crate::error::IndexError;
5use crate::types::{
6 CheckType, DetailLevel, Finding, ParseResult, Predicate, ScoredResult, ScoringCandidate,
7 SearchResult, Span, TraceOptions, TraceResult, Triple,
8};
9
10pub trait Element: Send + Sync {
11 fn qualified_name(&self) -> &str;
12 fn kind(&self) -> &str;
13 fn file_path(&self) -> &Path;
14 fn span(&self) -> Span;
15 fn metadata(&self) -> &dyn Any;
16}
17
18pub trait Relationship: Send + Sync {
19 fn source(&self) -> &str;
20 fn target(&self) -> &str;
21 fn kind(&self) -> &str;
22 fn file_path(&self) -> &Path;
23 fn span(&self) -> Span;
24}
25
26pub trait Parser: Send + Sync {
27 type Elem: Element;
28 type Rel: Relationship;
29 type Error: std::error::Error;
30
31 fn parse(
32 &self,
33 source: &str,
34 path: &Path,
35 ) -> Result<ParseResult<Self::Elem, Self::Rel>, Self::Error>;
36 fn validate(&self, source: &str) -> Vec<crate::types::Diagnostic>;
37}
38
39pub trait KnowledgeGraph: Send + Sync {
40 type Elem: Element;
41 type Rel: Relationship;
42
43 fn index(&mut self, results: Vec<ParseResult<Self::Elem, Self::Rel>>)
44 -> Result<(), IndexError>;
45 fn search(&self, query: &str, level: DetailLevel, limit: usize) -> Vec<SearchResult>;
46 fn trace(&self, element: &str, opts: TraceOptions) -> TraceResult;
47 fn check(&self, check_type: CheckType) -> Vec<Finding>;
48 fn query(&self, predicate: Predicate) -> Vec<Triple>;
49 fn elements(&self) -> &[Self::Elem];
50 fn relationships(&self) -> &[Self::Rel];
51}
52
53pub trait Vocabulary: Send + Sync {
54 fn expand_kind(&self, kind: &str) -> Vec<&str>;
55 fn normalize_kind<'a>(&self, kind: &'a str) -> &'a str;
56 fn relationship_kinds(&self) -> &[&str];
57 fn element_kinds(&self) -> &[&str];
58}
59
60pub trait Scorer: Send + Sync {
61 fn score(&self, query: &str, candidates: &[ScoringCandidate]) -> Vec<ScoredResult>;
62 fn signals(&self) -> &[&str];
63}