@@ -8,10 +8,11 @@ import * as codewhispererClient from '../client/codewhisperer'
8
8
import * as path from 'path'
9
9
import * as CodeWhispererConstants from '../models/constants'
10
10
import { getTabSizeSetting } from '../../shared/utilities/editorUtilities'
11
+ import { truncate } from '../../shared/utilities/textUtilities'
11
12
import { getLogger } from '../../shared/logger/logger'
12
13
import { runtimeLanguageContext } from './runtimeLanguageContext'
13
14
import { fetchSupplementalContext } from './supplementalContext/supplementalContextUtil'
14
- import { supplementalContextTimeoutInMs } from '../models/constants'
15
+ import { editorStateMaxLength , supplementalContextTimeoutInMs } from '../models/constants'
15
16
import { getSelectedCustomization } from './customizationUtil'
16
17
import { selectFrom } from '../../shared/utilities/tsUtils'
17
18
import { checkLeftContextKeywordsForJson } from './commonUtil'
@@ -216,13 +217,29 @@ export function getTabSize(): number {
216
217
217
218
export function getEditorState ( editor : vscode . TextEditor , fileContext : codewhispererClient . FileContext ) : any {
218
219
try {
220
+ const cursorPosition = editor . selection . active
221
+ const cursorOffset = editor . document . offsetAt ( cursorPosition )
222
+ const documentText = editor . document . getText ( )
223
+
224
+ // Truncate if document content is too large (defined in constants.ts)
225
+ let fileText = documentText
226
+ if ( documentText . length > editorStateMaxLength ) {
227
+ const halfLength = Math . floor ( editorStateMaxLength / 2 )
228
+
229
+ // Use truncate function to get the text around the cursor position
230
+ const leftPart = truncate ( documentText . substring ( 0 , cursorOffset ) , - halfLength , '' )
231
+ const rightPart = truncate ( documentText . substring ( cursorOffset ) , halfLength , '' )
232
+
233
+ fileText = leftPart + rightPart
234
+ }
235
+
219
236
return {
220
237
document : {
221
238
programmingLanguage : {
222
239
languageName : fileContext . programmingLanguage . languageName ,
223
240
} ,
224
241
relativeFilePath : fileContext . filename ,
225
- text : editor . document . getText ( ) ,
242
+ text : fileText ,
226
243
} ,
227
244
cursorState : {
228
245
position : {
0 commit comments