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:- Monitors your typing - Triggers after 300ms of inactivity (debounced)
- Analyzes context - Sends your current line, surrounding code, and cursor position to the AI
- Generates suggestions - Claude 3.7 Sonnet predicts what you’re likely to type next
- Displays inline - Shows the suggestion as ghost text at 40% opacity
- 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
Using Suggestions
Smart Suggestion Logic
The AI follows intelligent rules to avoid unhelpful suggestions:- Complete Statements
- Existing Code
- Active Suggestions
If your line ends with a complete statement (
;, }, )), no suggestion appears: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 anAbortController. 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: noneso 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./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
| Setting | Value | Location |
|---|---|---|
| Debounce delay | 300ms | index.ts:56 |
| Context lines (before) | 5 | index.ts:68 |
| Context lines (after) | 5 | index.ts:75 |
| Ghost text opacity | 0.4 | index.ts:48 |
| Accept key | Tab | index.ts:200 |
| Model | Claude 3.7 Sonnet | route.ts:86 |
| Timeout | 10 seconds | fetcher.ts:34 |
Error Handling
Aborted requests (from new keystrokes) fail silently without showing errors.Tips for Best Results
- Pause briefly - Give the AI 300ms to generate suggestions
- Provide context - The AI works better with well-structured surrounding code
- Use descriptive names - Variable and function names help the AI understand intent
- Trust the suggestions - The AI learns patterns from your codebase structure
Keyboard Shortcuts
| Key | Action |
|---|---|
| Tab | Accept current suggestion |
| Any key | Dismiss suggestion and type manually |
| Arrow keys | Move cursor (dismisses suggestion) |
Related Features
- Quick Edit - Edit selected code with natural language instructions
- Conversations - Chat with AI about your entire project