Overview
Polaris IDE provides intelligent code suggestions as you type, powered by AI models that understand your code context. Suggestions appear as ghost text at your cursor position, helping you write code faster with minimal interruption to your workflow.Code suggestions use a 300ms debounce to avoid excessive API calls while typing.
How it works
The suggestion system analyzes your current code context and generates inline completions based on:Context collection
Polaris captures 5 lines before and after your cursor position, along with the current line and cursor state.
AI generation
The context is sent to the AI model with a specialized prompt that understands code structure.
AI models used
Polaris uses a fallback provider system to ensure reliable suggestions:- Primary: Moonshot AI Kimi K2.5 (via OpenRouter)
- Fallback: Cerebras GLM-4.7
The system automatically falls back to Cerebras if OpenRouter is unavailable, ensuring uninterrupted coding experience.
Context window
The suggestion API receives structured context from your editor:Suggestion logic
The AI follows these rules when generating suggestions:Check for existing code
If
nextLines contains code that continues from the cursor position, return empty string (code already exists).Check for complete statements
If
textBeforeCursor ends with a complete statement (;, }, )), return empty string.Accepting suggestions
Interact with code suggestions using keyboard shortcuts:- Tab - Accept the entire suggestion
- → (Right Arrow) - Accept suggestion word by word
- Esc - Dismiss the suggestion
- Continue typing - Suggestion updates or disappears based on new context
API implementation
The suggestion endpoint is located at/api/suggestion:
Configuration
Suggestion generation uses these parameters:- Temperature:
0.7(balanced creativity and consistency) - Max tokens:
500(limits suggestion length) - Debounce:
300ms(prevents excessive API calls)
Performance optimization
Polaris optimizes suggestion performance through:- Debouncing - 300ms delay before triggering suggestion
- Context limiting - Only 5 lines before/after cursor (not entire file)
- Smart caching - Provider metadata tracked for monitoring
- Fallback system - Automatic failover to secondary AI provider
The suggestion system is designed to be non-blocking and won’t interrupt your typing flow even if the API is slow.
Source code reference
Implementation details:- API route:
src/app/api/suggestion/route.ts:46 - AI provider with fallback:
src/lib/ai-provider-with-fallback.ts:27 - Suggestion schema validation:
src/app/api/suggestion/route.ts:8