@@ -8,6 +8,7 @@ import * as codewhispererClient from '../client/codewhisperer'
88import * as path from 'path'
99import * as CodeWhispererConstants from '../models/constants'
1010import { getTabSizeSetting } from '../../shared/utilities/editorUtilities'
11+ import { truncate } from '../../shared/utilities/textUtilities'
1112import { getLogger } from '../../shared/logger/logger'
1213import { runtimeLanguageContext } from './runtimeLanguageContext'
1314import { fetchSupplementalContext } from './supplementalContext/supplementalContextUtil'
@@ -223,10 +224,13 @@ export function getEditorState(editor: vscode.TextEditor, fileContext: codewhisp
223224 // Truncate if document content is too large (defined in constants.ts)
224225 let fileText = documentText
225226 if ( documentText . length > editorStateMaxLength ) {
226- const startOffset = Math . max ( 0 , cursorOffset - Math . floor ( editorStateMaxLength / 2 ) )
227- const endOffset = Math . min ( documentText . length , cursorOffset + Math . floor ( editorStateMaxLength / 2 ) )
227+ const halfLength = Math . floor ( editorStateMaxLength / 2 )
228228
229- fileText = documentText . substring ( startOffset , endOffset )
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
230234 }
231235
232236 return {
@@ -291,8 +295,8 @@ function logSupplementalContext(supplementalContext: CodeWhispererSupplementalCo
291295 logString += indent ( `\nChunk ${ index } :\n` , 4 , true )
292296 logString += indent (
293297 `Path: ${ context . filePath }
294- Length: ${ context . content . length }
295- Score: ${ context . score } `,
298+ Length: ${ context . content . length }
299+ Score: ${ context . score } ` ,
296300 8 ,
297301 true
298302 )
0 commit comments