@@ -45,7 +45,7 @@ import {
4545 emitServiceInvocationTelemetry ,
4646 emitUserTriggerDecisionTelemetry ,
4747} from '../telemetry/telemetry'
48- import { EMPTY_RESULT } from '../contants/constants'
48+ import { EDITOR_STATE_MAX_LENGTH , EMPTY_RESULT } from '../contants/constants'
4949import { IdleWorkspaceManager } from '../../workspaceContext/IdleWorkspaceManager'
5050import { mergeSuggestionsWithRightContext } from '../utils/mergeRightUtils'
5151import { getTextDocument } from '../utils/textDocumentUtils'
@@ -331,9 +331,36 @@ export class InlineCompletionHandler {
331331
332332 if ( codeWhispererService instanceof CodeWhispererServiceToken ) {
333333 const tokenRequest = requestContext as GenerateTokenSuggestionsRequest
334+
335+ // Build editorState with truncation for token-based requests
336+ const documentText = textDocument . getText ( )
337+ const cursorOffset = textDocument . offsetAt ( params . position )
338+ let fileText = documentText
339+ if ( documentText . length > EDITOR_STATE_MAX_LENGTH ) {
340+ const halfLength = Math . floor ( EDITOR_STATE_MAX_LENGTH / 2 )
341+ const leftPart = documentText . substring ( Math . max ( 0 , cursorOffset - halfLength ) , cursorOffset )
342+ const rightPart = documentText . substring ( cursorOffset , cursorOffset + halfLength )
343+ fileText = leftPart + rightPart
344+ }
345+
334346 generateCompletionReq = {
335347 ...tokenRequest ,
336348 ...( workspaceId ? { workspaceId } : { } ) ,
349+ editorState : {
350+ document : {
351+ relativeFilePath : textDocument . uri ,
352+ programmingLanguage : {
353+ languageName : fileContext . programmingLanguage . languageName ,
354+ } ,
355+ text : fileText ,
356+ } ,
357+ cursorState : {
358+ position : {
359+ line : params . position . line ,
360+ character : params . position . character ,
361+ } ,
362+ } ,
363+ } ,
337364 }
338365 } else {
339366 const iamRequest = requestContext as GenerateIAMSuggestionsRequest
@@ -344,7 +371,9 @@ export class InlineCompletionHandler {
344371
345372 try {
346373 const authType = codeWhispererService instanceof CodeWhispererServiceToken ? 'token' : 'iam'
347- this . logging . debug ( `[INLINE_COMPLETION] API call - generateSuggestions (new session, ${ authType } )` )
374+ this . logging . debug (
375+ `[INLINE_COMPLETION] API call - generateSuggestions (new session, ${ authType } ), generateCompletion request = ${ JSON . stringify ( generateCompletionReq ) } `
376+ )
348377 const suggestionResponse = await codeWhispererService . generateSuggestions ( generateCompletionReq )
349378 return await this . processSuggestionResponse ( suggestionResponse , newSession , true , selectionRange )
350379 } catch ( error ) {
0 commit comments