Skip to main content

aft/
language.rs

1use std::path::Path;
2
3use crate::error::AftError;
4pub use crate::symbols::{Range, Symbol, SymbolMatch};
5
6/// Trait for language-specific symbol resolution.
7///
8/// S02 implements this with tree-sitter parsing via `TreeSitterProvider`.
9pub trait LanguageProvider {
10    /// Resolve a symbol by name within a file. Returns all matches.
11    fn resolve_symbol(&self, file: &Path, name: &str) -> Result<Vec<SymbolMatch>, AftError>;
12
13    /// List all top-level symbols in a file.
14    fn list_symbols(&self, file: &Path) -> Result<Vec<Symbol>, AftError>;
15
16    /// Downcast to concrete type for provider-specific operations.
17    fn as_any(&self) -> &dyn std::any::Any;
18}
19
20/// Placeholder provider that rejects all calls.
21///
22/// Retained for tests and fallback. Production code uses `TreeSitterProvider`.
23pub struct StubProvider;
24
25impl LanguageProvider for StubProvider {
26    fn resolve_symbol(&self, _file: &Path, _name: &str) -> Result<Vec<SymbolMatch>, AftError> {
27        Err(AftError::InvalidRequest {
28            message: "no language provider configured".to_string(),
29        })
30    }
31
32    fn list_symbols(&self, _file: &Path) -> Result<Vec<Symbol>, AftError> {
33        Err(AftError::InvalidRequest {
34            message: "no language provider configured".to_string(),
35        })
36    }
37
38    fn as_any(&self) -> &dyn std::any::Any {
39        self
40    }
41}