Module config

Module config 

Source
Expand description

RiceCoder Completion Engine

A language-agnostic code completion engine with pluggable providers for language-specific behavior.

§Architecture

The completion engine follows a layered architecture with external LSP integration:

  1. External LSP Layer (Primary): Query external LSP servers (rust-analyzer, tsserver, pylsp, etc.) for semantic completions when available
  2. Configuration Layer: Load and manage language-specific completion configurations
  3. Context Analysis Layer: Analyze code context to determine available symbols and expected types
  4. Completion Generation Layer: Generate completion suggestions (generic or language-specific)
  5. Ranking Layer: Rank completions by relevance, frequency, and recency
  6. Fallback Layer: Use internal providers when external LSP is unavailable

§Language Support

The engine supports multiple languages through a pluggable provider system:

  • Rust: External LSP (rust-analyzer) with fallback to internal provider
  • TypeScript: External LSP (typescript-language-server) with fallback to internal provider
  • Python: External LSP (pylsp) with fallback to internal provider
  • Go: External LSP (gopls) with fallback to internal provider
  • Java: External LSP (jdtls) with fallback to internal provider
  • Kotlin: External LSP (kotlin-language-server) with fallback to internal provider
  • Dart: External LSP (dart-language-server) with fallback to internal provider
  • Generic: Fallback for unconfigured languages using text-based completion

§External LSP Integration

The completion engine integrates with external LSP servers through the ExternalLspCompletionProxy. When a completion request is made:

  1. If an external LSP server is configured and available, the request is forwarded to it
  2. The external LSP response is transformed to ricecoder’s internal model
  3. External completions are merged with internal completions (external takes priority)
  4. If the external LSP is unavailable, the system falls back to internal providers

This provides production-quality semantic completions while maintaining graceful degradation.

§Fallback Providers

IMPORTANT: Internal completion providers are now fallback providers used only when external LSP servers are unavailable. They provide basic keyword and pattern-based completions but lack semantic understanding.

See the providers module documentation for details on fallback behavior and limitations.

§Core Components

§CompletionEngine

The main trait that orchestrates the completion process. Implementations:

§ContextAnalyzer

Analyzes code context to determine available symbols and expected types. Implementations:

§CompletionGenerator

Generates completion suggestions. Implementations:

  • Built-in generic generator for text-based completions
  • Language-specific providers (Rust, TypeScript, Python)

§CompletionRanker

Ranks completions by relevance, frequency, and recency. Implementations:

§CompletionProvider

Pluggable providers for language-specific behavior. Implementations:

§Ghost Text

Ghost text displays inline suggestions in a lighter color. Components:

§Configuration

Configuration is loaded from YAML/JSON files and supports:

  • Language-specific keywords and snippets
  • Ranking weights for relevance, frequency, and recency
  • Provider references for language-specific behavior

§Example: Basic Usage

use ricecoder_completion::engine::*;
use ricecoder_completion::types::*;
use ricecoder_completion::context::*;
use ricecoder_completion::ranker::*;
use std::sync::Arc;

// Create components
let context_analyzer = Arc::new(GenericContextAnalyzer);
let generator = Arc::new(BasicCompletionGenerator);
let ranker = Arc::new(BasicCompletionRanker::default_weights());
let mut registry = ProviderRegistry::new();

// Create engine
let engine = GenericCompletionEngine::new(
    context_analyzer,
    generator,
    ranker,
    registry,
);

// Generate completions
let completions = engine.generate_completions(
    "fn main() { let x = ",
    Position::new(0, 20),
    "rust",
).await?;

§Example: With Language-Specific Provider

use ricecoder_completion::providers::RustCompletionProvider;
use std::sync::Arc;

// Register Rust provider
let mut registry = ProviderRegistry::new();
registry.register(Arc::new(RustCompletionProvider));

// Now Rust code will use language-specific completions

§Example: Ghost Text

use ricecoder_completion::ghost_text::*;
use ricecoder_completion::types::*;

let generator = BasicGhostTextGenerator;
let completion = CompletionItem::new(
    "println!".to_string(),
    CompletionItemKind::Macro,
    "println!(\"{}\", {})".to_string(),
);

let ghost_text = generator.generate_ghost_text(&completion, Position::new(0, 5))?;

Structs§

ConfigLoader
Completion configuration loader with storage integration
LanguageConfigRegistry
Language configuration registry with storage integration

Enums§

ConfigFormat
Configuration format