@@ -21,17 +21,24 @@ The code completion system consists of several key components working together:
2121 - Records acceptance, decline, and ignore events
2222 - Captures timing and interaction data
2323
24- 3 . ** Factory** (` factory.ts ` )
24+ 3 . ** PromptContent** (` promptContent.ts ` )
25+
26+ - Handles extraction of code context for suggestions
27+ - Manages text fragments before and after cursor
28+ - Implements text length limits and cursor positioning
29+ - Creates structured prompt data for API requests
30+
31+ 4 . ** Factory** (` factory.ts ` )
2532
2633 - Creates and configures the completion provider
2734 - Wires together the completion and telemetry services
2835
29- 4 . ** Command Registration** (` registerCommands.ts ` )
36+ 5 . ** Command Registration** (` registerCommands.ts ` )
3037
3138 - Registers Monaco editor commands for completion actions
3239 - Handles accept/decline completion commands
3340
34- 5 . ** CodeAssistantTelemetry** (` CodeAssistantTelemetry.tsx ` )
41+ 6 . ** CodeAssistantTelemetry** (` CodeAssistantTelemetry.tsx ` )
3542 - Optional context caching mechanism
3643 - Tracks query history as virtual "open tabs"
3744 - Sends historical queries to the backend for context-aware suggestions
@@ -60,48 +67,62 @@ The code completion system consists of several key components working together:
6067 -> sendOpenTabs -> Backend Context Cache
6168 ```
6269
63- 2 . ** Suggestion Generation**
70+ 2 . ** Prompt Generation**
71+
72+ ```
73+ Editor Change -> PromptContent.getPromptFileContent
74+ -> Text Fragments with Cursor Position -> API Request
75+ ```
76+
77+ 3 . ** Suggestion Generation**
6478
6579 ```
66- Editor Change -> CodeCompletionService.provideInlineCompletions
80+ Prompt Data -> CodeCompletionService.provideInlineCompletions
6781 -> API Request (with cached context) -> Suggestions Returned -> Monaco Display
6882 ```
6983
70- 3 . ** Suggestion Acceptance**
84+ 4 . ** Suggestion Acceptance**
7185
7286 ```
7387 User Accept -> handleAccept -> TelemetryService.sendAcceptTelemetry
7488 -> API Telemetry Event
7589 ```
7690
77- 4 . ** Suggestion Rejection**
91+ 5 . ** Suggestion Rejection**
7892 ```
7993 User Decline -> commandDiscard -> TelemetryService.sendDeclineTelemetry
8094 -> API Telemetry Event
8195 ```
8296
8397## Key Features
8498
85- 1 . ** Context Caching**
99+ 1 . ** Prompt Generation**
100+
101+ - Extracts relevant code context around cursor
102+ - Implements smart text truncation (8000 chars before, 1000 after cursor)
103+ - Maintains cursor position information
104+ - Creates structured prompt format for API
105+
106+ 2 . ** Context Caching**
86107
87108 - Maintains history of queries as virtual open tabs
88109 - Each query is assigned a unique ID and treated as a ` .yql ` file
89110 - Provides historical context to improve suggestion relevance
90111 - Optional feature that can be enabled/disabled
91112
92- 2 . ** Suggestion Caching**
113+ 3 . ** Suggestion Caching**
93114
94115 - Caches suggestions to reduce API calls
95116 - Tracks suggestion display count
96117 - Manages suggestion lifecycle
97118
98- 3 . ** Telemetry**
119+ 4 . ** Telemetry**
99120
100121 - Tracks suggestion acceptance rate
101122 - Records user interaction patterns
102123 - Monitors suggestion quality
103124
104- 4 . ** Command Integration**
125+ 5 . ** Command Integration**
105126 - Keyboard shortcuts for completion actions
106127 - Context menu integration
107128 - Custom commands for completion workflow
@@ -117,6 +138,22 @@ interface ICodeCompletionAPI {
117138}
118139```
119140
141+ ## Prompt Format
142+
143+ The prompt generation creates structured data in this format:
144+
145+ ``` typescript
146+ interface PromptFile {
147+ Fragments: {
148+ Text: string ;
149+ Start: {Ln: number ; Col: number };
150+ End: {Ln: number ; Col: number };
151+ }[];
152+ Cursor: {Ln: number ; Col: number };
153+ Path: string ;
154+ }
155+ ```
156+
120157## Context Caching Format
121158
122159When using the context caching feature, queries are sent in this format:
@@ -164,25 +201,31 @@ registerCompletionCommands(editor, monaco, completionService);
164201
165202## Best Practices
166203
167- 1 . ** Context Management**
204+ 1 . ** Prompt Generation**
205+
206+ - Consider text limits for optimal performance
207+ - Maintain cursor position accuracy
208+ - Handle edge cases in text extraction
209+
210+ 2 . ** Context Management**
168211
169212 - Consider enabling context caching for better suggestions
170213 - Monitor the size of historical context
171214 - Clean up old context when no longer relevant
172215
173- 2 . ** Error Handling**
216+ 3 . ** Error Handling**
174217
175218 - All API calls should be wrapped in try-catch blocks
176219 - Failed suggestions should not break the editor
177220 - Telemetry failures should be logged but not impact user experience
178221
179- 3 . ** Performance**
222+ 4 . ** Performance**
180223
181224 - Suggestions are throttled to prevent excessive API calls
182225 - Caching reduces server load
183226 - Completion provider is disposed when not needed
184227
185- 4 . ** User Experience**
228+ 5 . ** User Experience**
186229 - Suggestions appear inline with minimal delay
187230 - Clear feedback for acceptance/rejection
188231 - Non-intrusive telemetry collection
@@ -197,6 +240,7 @@ When modifying the code completion system:
1972404 . Consider performance implications of changes
1982415 . Document new features or changes
1992426 . Consider impact on context caching when modifying query handling
243+ 7 . Follow text limit guidelines in prompt generation
200244
201245## Related Components
202246
0 commit comments