Skip to main content
Polaris provides intelligent code suggestions that appear as ghost text while you code. As you type, the AI analyzes your code context and suggests the next logical completion, helping you write code faster and more accurately.

How It Works

The suggestion system uses CodeMirror’s decoration API to display AI-generated completions as low-opacity text at your cursor position. The system:
  1. Monitors your typing - Triggers after 300ms of inactivity (debounced)
  2. Analyzes context - Sends your current line, surrounding code, and cursor position to the AI
  3. Generates suggestions - Claude 3.7 Sonnet predicts what you’re likely to type next
  4. Displays inline - Shows the suggestion as ghost text at 40% opacity
  5. Accepts with Tab - Press Tab to insert the full suggestion
Suggestions appear automatically as you type. No manual trigger is required.

Context Sent to AI

When generating a suggestion, Polaris sends:
  • File name - Helps the AI understand the file type and purpose
  • Current line - The line where your cursor is positioned
  • Text before cursor - Everything typed on the current line up to the cursor
  • Text after cursor - Remaining text on the current line after the cursor
  • Previous 5 lines - Code context before the current line
  • Next 5 lines - Code context after the current line
  • Full file content - Complete code for broader context
  • Line number - Current position in the file
This comprehensive context allows the AI to make intelligent predictions that fit naturally into your codebase.

Using Suggestions

1

Start typing

Begin writing code in any file. The suggestion engine activates automatically.
2

Wait briefly

After 300ms of inactivity, ghost text appears showing the AI’s suggestion.
function calculateTotal(items) {
  return items.reduce((sum, item) => sum + item.price, 0);
                                              // Ghost text appears here ↑
}
3

Accept or continue

  • Press Tab to accept and insert the entire suggestion
  • Keep typing to ignore the suggestion and continue manually
  • Move your cursor to dismiss the current suggestion

Smart Suggestion Logic

The AI follows intelligent rules to avoid unhelpful suggestions:
If your line ends with a complete statement (;, }, )), no suggestion appears:
const total = calculatePrice(); // ← No suggestion (complete statement)

Performance Features

Debouncing

Suggestions are debounced to 300ms to prevent excessive API calls while you’re actively typing. Each new keystroke resets the timer.

Request Cancellation

When a new suggestion request starts, any pending request is automatically cancelled using an AbortController. This ensures:
  • No wasted API calls for outdated contexts
  • Faster response times for your current position
  • Reduced server load

Visual Feedback

Ghost text is styled with:
  • 40% opacity for clear visibility without distraction
  • pointer-events: none so it doesn’t interfere with clicking or selection
  • Automatic positioning right after your cursor

Implementation Details

Suggestions are powered by Claude 3.7 Sonnet via the /api/suggestion endpoint.
The system is implemented in /src/features/editor/extensions/suggestion/index.ts:1 using:
  • StateField - Stores the current suggestion text in editor state
  • StateEffect - Updates suggestion state on changes
  • ViewPlugin - Handles debouncing and API requests
  • WidgetType - Renders ghost text as a custom DOM element
  • Keymap - Binds Tab key to accept suggestions

Configuration

SettingValueLocation
Debounce delay300msindex.ts:56
Context lines (before)5index.ts:68
Context lines (after)5index.ts:75
Ghost text opacity0.4index.ts:48
Accept keyTabindex.ts:200
ModelClaude 3.7 Sonnetroute.ts:86
Timeout10 secondsfetcher.ts:34

Error Handling

If a suggestion request fails, the system:
  • Shows a toast notification: “Failed to fetch AI completion”
  • Returns null to clear any pending ghost text
  • Allows you to continue typing without interruption
Aborted requests (from new keystrokes) fail silently without showing errors.

Tips for Best Results

  1. Pause briefly - Give the AI 300ms to generate suggestions
  2. Provide context - The AI works better with well-structured surrounding code
  3. Use descriptive names - Variable and function names help the AI understand intent
  4. Trust the suggestions - The AI learns patterns from your codebase structure

Keyboard Shortcuts

KeyAction
TabAccept current suggestion
Any keyDismiss suggestion and type manually
Arrow keysMove cursor (dismisses suggestion)
  • Quick Edit - Edit selected code with natural language instructions
  • Conversations - Chat with AI about your entire project

Build docs developers (and LLMs) love