@@ -8,10 +8,11 @@ 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'
14- import { supplementalContextTimeoutInMs } from '../models/constants'
15+ import { editorStateMaxLength , supplementalContextTimeoutInMs } from '../models/constants'
1516import { getSelectedCustomization } from './customizationUtil'
1617import { selectFrom } from '../../shared/utilities/tsUtils'
1718import { checkLeftContextKeywordsForJson } from './commonUtil'
@@ -216,13 +217,29 @@ export function getTabSize(): number {
216217
217218export function getEditorState ( editor : vscode . TextEditor , fileContext : codewhispererClient . FileContext ) : any {
218219 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+
219236 return {
220237 document : {
221238 programmingLanguage : {
222239 languageName : fileContext . programmingLanguage . languageName ,
223240 } ,
224241 relativeFilePath : fileContext . filename ,
225- text : editor . document . getText ( ) ,
242+ text : fileText ,
226243 } ,
227244 cursorState : {
228245 position : {
0 commit comments