Skip to content

Completion Configuration

Mo Abualruz edited this page Dec 4, 2025 · 1 revision

Code Completion Configuration

Status: ✅ Complete

Phase: Phase 3 - MVP Features

Last Updated: December 4, 2025


Overview

Code Completion behavior is configured through YAML configuration files. This guide explains all configuration options and how to customize completion for your needs.

Configuration Files

Configuration files are loaded in this order (later overrides earlier):

  1. Built-in Defaults: Default configuration for each language
  2. User Configuration: ~/.ricecoder/completion.yaml
  3. Project Configuration: .ricecoder/completion.yaml
  4. Runtime Overrides: CLI flags or API calls

Configuration Structure

Top-Level Options

# Enable/disable completion
enabled: true

# Maximum number of suggestions to return
max_suggestions: 20

# Timeout for completion generation (milliseconds)
timeout_ms: 100

# Enable ghost text (inline suggestions)
ghost_text:
  enabled: true
  style: "lighter"  # lighter, italic, dimmed

# Track completion usage for frequency/recency scoring
track_frequency: true

# Language-specific configurations
languages:
  rust: { ... }
  typescript: { ... }
  python: { ... }

Language Configuration

Each language can define:

languages:
  rust:
    # Enable/disable for this language
    enabled: true
    
    # Language-specific keywords
    keywords:
      - fn
      - let
      - mut
      - struct
      - impl
      - trait
    
    # Code snippets
    snippets:
      - label: "fn main"
        template: "fn main() {\n    ${1}\n}"
        description: "Main function"
    
    # Ranking weights
    ranking_weights:
      relevance: 0.5
      frequency: 0.3
      recency: 0.2
    
    # Reference to language-specific provider
    provider: "rust"

Configuration Options

Global Options

enabled

Enable or disable completion globally.

enabled: true  # Default: true

max_suggestions

Maximum number of suggestions to return.

max_suggestions: 20  # Default: 20, Range: 1-100

timeout_ms

Timeout for completion generation in milliseconds.

timeout_ms: 100  # Default: 100, Range: 50-500

ghost_text

Ghost text (inline suggestion) configuration.

ghost_text:
  enabled: true      # Default: true
  style: "lighter"   # Default: "lighter", Options: lighter, italic, dimmed

track_frequency

Track completion usage for frequency and recency scoring.

track_frequency: true  # Default: true

Language-Specific Options

enabled

Enable or disable completion for a specific language.

languages:
  rust:
    enabled: true  # Default: true

keywords

Language-specific keywords to suggest.

languages:
  rust:
    keywords:
      - fn
      - let
      - mut
      - struct
      - impl
      - trait
      - match
      - if
      - for
      - while

snippets

Code snippets for common patterns.

languages:
  rust:
    snippets:
      - label: "fn main"
        template: "fn main() {\n    ${1}\n}"
        description: "Main function"
      - label: "println!"
        template: "println!(\"${1}\");"
        description: "Print macro"

Snippet placeholders:

  • ${1}, ${2}, etc.: Tab stops for cursor positioning
  • ${1:default}: Tab stop with default value
  • $0: Final cursor position

ranking_weights

Weights for different scoring factors (must sum to 1.0).

languages:
  rust:
    ranking_weights:
      relevance: 0.5  # How well completion matches context
      frequency: 0.3  # How often completion is used
      recency: 0.2    # How recently completion was used

provider

Reference to language-specific provider.

languages:
  rust:
    provider: "rust"  # Built-in: rust, typescript, python, generic

Examples

Minimal Configuration

# ~/.ricecoder/completion.yaml
enabled: true
max_suggestions: 20

Rust-Focused Configuration

# .ricecoder/completion.yaml
enabled: true
max_suggestions: 30

languages:
  rust:
    enabled: true
    keywords:
      - fn
      - let
      - mut
      - struct
      - impl
      - trait
      - match
    ranking_weights:
      relevance: 0.6
      frequency: 0.2
      recency: 0.2
    provider: "rust"
  
  typescript:
    enabled: false  # Disable TypeScript

Multi-Language Configuration

# .ricecoder/completion.yaml
enabled: true
max_suggestions: 20
ghost_text:
  enabled: true
  style: "lighter"

languages:
  rust:
    enabled: true
    provider: "rust"
    ranking_weights:
      relevance: 0.5
      frequency: 0.3
      recency: 0.2
  
  typescript:
    enabled: true
    provider: "typescript"
    ranking_weights:
      relevance: 0.5
      frequency: 0.3
      recency: 0.2
  
  python:
    enabled: true
    provider: "python"
    ranking_weights:
      relevance: 0.5
      frequency: 0.3
      recency: 0.2

Custom Snippets

# .ricecoder/completion.yaml
languages:
  rust:
    snippets:
      - label: "Result type"
        template: "Result<${1:T}, ${2:E}>"
        description: "Result type with generics"
      
      - label: "Option type"
        template: "Option<${1:T}>"
        description: "Option type with generic"
      
      - label: "match statement"
        template: "match ${1:expr} {\n    ${2:pattern} => ${3:value},\n}"
        description: "Match statement template"

Configuration Validation

Configuration files are validated on load. Invalid configuration will be rejected with clear error messages.

Common Errors

Missing Required Fields

Error: Configuration error: missing required field 'language'

Solution: Ensure all required fields are present in configuration.

Invalid Ranking Weights

Error: Configuration error: ranking weights must sum to 1.0

Solution: Ensure relevance + frequency + recency = 1.0

Unknown Provider

Error: Configuration error: unknown provider 'custom'

Solution: Use built-in providers: rust, typescript, python, generic

Invalid Timeout

Error: Configuration error: timeout must be between 50 and 500 ms

Solution: Set timeout between 50 and 500 milliseconds.

Runtime Configuration

CLI Commands

# Enable/disable completion
ricecoder config completion.enabled true
ricecoder config completion.enabled false

# Set maximum suggestions
ricecoder config completion.max_suggestions 30

# Set timeout
ricecoder config completion.timeout_ms 150

# Enable/disable ghost text
ricecoder config completion.ghost_text.enabled true

# Set ghost text style
ricecoder config completion.ghost_text.style "italic"

# Enable/disable language
ricecoder config completion.languages.rust.enabled true

# Set ranking weights
ricecoder config completion.languages.rust.ranking_weights.relevance 0.6

API Configuration

use ricecoder_completion::config::*;

// Load configuration
let config = ConfigLoader::load_from_file("~/.ricecoder/completion.yaml")?;

// Modify configuration
let mut config = config;
config.enabled = true;
config.max_suggestions = 30;

// Save configuration
config.save_to_file("~/.ricecoder/completion.yaml")?;

Best Practices

1. Start with Defaults

Use default configuration and customize only what you need:

# Good: Minimal customization
enabled: true
max_suggestions: 20

# Avoid: Over-configuration
enabled: true
max_suggestions: 20
ghost_text:
  enabled: true
  style: "lighter"
track_frequency: true
languages:
  rust:
    enabled: true
    keywords: [...]
    snippets: [...]
    ranking_weights: {...}
    provider: "rust"

2. Use Project Configuration

Store project-specific configuration in .ricecoder/completion.yaml:

# .ricecoder/completion.yaml
# Project-specific completion settings
languages:
  rust:
    snippets:
      - label: "project-specific snippet"
        template: "..."

3. Adjust Ranking Weights

Tune ranking weights based on your preferences:

# Prefer relevance over frequency
ranking_weights:
  relevance: 0.7
  frequency: 0.2
  recency: 0.1

# Prefer frequency over relevance
ranking_weights:
  relevance: 0.3
  frequency: 0.5
  recency: 0.2

4. Disable Unused Languages

Disable languages you don't use to improve performance:

languages:
  rust:
    enabled: true
  typescript:
    enabled: false  # Not using TypeScript
  python:
    enabled: false  # Not using Python

5. Customize Snippets

Add project-specific snippets:

languages:
  rust:
    snippets:
      - label: "project error type"
        template: "ProjectError::${1:Variant}"
        description: "Project-specific error type"

See Also


Last updated: December 4, 2025

Clone this wiki locally