Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/core/src/codewhisperer/models/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ export const lineBreakWin = '\r\n'
export const supplementalContextTimeoutInMs = 100

export const supplementalContextMaxTotalLength = 20480

export const editorStateMaxLength = 40000

/**
* Ux of recommendations
*/
Expand Down
17 changes: 15 additions & 2 deletions packages/core/src/codewhisperer/util/editorContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getTabSizeSetting } from '../../shared/utilities/editorUtilities'
import { getLogger } from '../../shared/logger/logger'
import { runtimeLanguageContext } from './runtimeLanguageContext'
import { fetchSupplementalContext } from './supplementalContext/supplementalContextUtil'
import { supplementalContextTimeoutInMs } from '../models/constants'
import { editorStateMaxLength, supplementalContextTimeoutInMs } from '../models/constants'
import { getSelectedCustomization } from './customizationUtil'
import { selectFrom } from '../../shared/utilities/tsUtils'
import { checkLeftContextKeywordsForJson } from './commonUtil'
Expand Down Expand Up @@ -216,13 +216,26 @@ export function getTabSize(): number {

export function getEditorState(editor: vscode.TextEditor, fileContext: codewhispererClient.FileContext): any {
try {
const cursorPosition = editor.selection.active
const cursorOffset = editor.document.offsetAt(cursorPosition)
const documentText = editor.document.getText()

// Truncate if document content is too large (defined in constants.ts)
let fileText = documentText
if (documentText.length > editorStateMaxLength) {
const startOffset = Math.max(0, cursorOffset - Math.floor(editorStateMaxLength / 2))
const endOffset = Math.min(documentText.length, cursorOffset + Math.floor(editorStateMaxLength / 2))

fileText = documentText.substring(startOffset, endOffset)
}

return {
document: {
programmingLanguage: {
languageName: fileContext.programmingLanguage.languageName,
},
relativeFilePath: fileContext.filename,
text: editor.document.getText(),
text: fileText,
},
cursorState: {
position: {
Expand Down
Loading