pub trait ContextAnalyzer: Send + Sync {
// Required methods
fn analyze_context<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
code: &'life1 str,
position: Position,
language: &'life2 str,
) -> Pin<Box<dyn Future<Output = CompletionResult<CompletionContext>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn get_available_symbols(
&self,
context: &CompletionContext,
code: &str,
) -> Vec<Symbol>;
fn infer_expected_type(&self, context: &CompletionContext) -> Option<Type>;
}Expand description
Context analyzer trait for analyzing code context
Implementations analyze code context to determine available symbols, scopes, and expected types. This information is used by the completion generator to provide relevant suggestions.
§Example
ⓘ
use ricecoder_completion::context::*;
use ricecoder_completion::types::*;
let analyzer = GenericContextAnalyzer;
let context = analyzer.analyze_context(
"fn main() { let x = ",
Position::new(0, 20),
"rust",
).await?;
println!("Scope: {:?}", context.scope);
println!("Available symbols: {:?}", context.available_symbols);Required Methods§
Sourcefn analyze_context<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
code: &'life1 str,
position: Position,
language: &'life2 str,
) -> Pin<Box<dyn Future<Output = CompletionResult<CompletionContext>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn analyze_context<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
code: &'life1 str,
position: Position,
language: &'life2 str,
) -> Pin<Box<dyn Future<Output = CompletionResult<CompletionContext>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Analyze the code context at the given position
§Arguments
code- The source code to analyzeposition- The cursor position where context is requestedlanguage- The programming language identifier
§Returns
A CompletionContext containing scope, available symbols, and expected type information.
§Errors
Returns CompletionError if:
- The language is not supported
- Code parsing fails
- Context analysis fails