Skip to main content

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:
1

Context collection

Polaris captures 5 lines before and after your cursor position, along with the current line and cursor state.
2

AI generation

The context is sent to the AI model with a specialized prompt that understands code structure.
3

Ghost text display

Suggestions appear as dimmed text at your cursor, non-intrusively showing the proposed completion.

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:
{
  fileName: string,           // Current file name
  code: string,               // Full file content
  currentLine: string,        // Line where cursor is located
  previousLines: string,      // 5 lines before cursor
  textBeforeCursor: string,   // Text before cursor on current line
  textAfterCursor: string,    // Text after cursor on current line
  nextLines: string,          // 5 lines after cursor
  lineNumber: number          // Current line number (1-based)
}

Suggestion logic

The AI follows these rules when generating suggestions:
1

Check for existing code

If nextLines contains code that continues from the cursor position, return empty string (code already exists).
2

Check for complete statements

If textBeforeCursor ends with a complete statement (;, }, )), return empty string.
3

Generate completion

Only if steps 1 and 2 don’t apply, suggest what should be typed at the cursor position using full code context.
Suggestions are inserted immediately after the cursor, so the system never suggests code that’s already in the file.

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:
POST /api/suggestion

{
  "fileName": "src/components/Button.tsx",
  "code": "import React from 'react'\n\nconst Button = () => {\n  ",
  "currentLine": "  ",
  "previousLines": "import React from 'react'\n\nconst Button = () => {",
  "textBeforeCursor": "  ",
  "textAfterCursor": "",
  "nextLines": "",
  "lineNumber": 4
}

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:
  1. Debouncing - 300ms delay before triggering suggestion
  2. Context limiting - Only 5 lines before/after cursor (not entire file)
  3. Smart caching - Provider metadata tracked for monitoring
  4. 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

Build docs developers (and LLMs) love