ContextAnalyzer

Trait ContextAnalyzer 

Source
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§

Source

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 analyze
  • position - The cursor position where context is requested
  • language - 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
Source

fn get_available_symbols( &self, context: &CompletionContext, code: &str, ) -> Vec<Symbol>

Get available symbols in the given context

§Arguments
  • context - The completion context
  • code - The source code
§Returns

A vector of symbols available in the given context.

Source

fn infer_expected_type(&self, context: &CompletionContext) -> Option<Type>

Infer the expected type at the given context

§Arguments
  • context - The completion context
§Returns

The expected type at the cursor position, or None if it cannot be inferred.

Implementors§