Skip to content

Commit 9bf6fa7

Browse files
committed
truncate editor state with character limits
1 parent bb11bd9 commit 9bf6fa7

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

packages/core/src/codewhisperer/util/editorContext.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,26 @@ export function getTabSize(): number {
216216

217217
export function getEditorState(editor: vscode.TextEditor, fileContext: codewhispererClient.FileContext): any {
218218
try {
219+
const cursorPosition = editor.selection.active
220+
const cursorOffset = editor.document.offsetAt(cursorPosition)
221+
const documentText = editor.document.getText()
222+
223+
// Check if text needs truncation (longer than 40000 characters)
224+
let fileText = documentText
225+
if (documentText.length > 40000) {
226+
const startOffset = Math.max(0, cursorOffset - 20000)
227+
const endOffset = Math.min(documentText.length, cursorOffset + 20000)
228+
229+
fileText = documentText.substring(startOffset, endOffset)
230+
}
231+
219232
return {
220233
document: {
221234
programmingLanguage: {
222235
languageName: fileContext.programmingLanguage.languageName,
223236
},
224237
relativeFilePath: fileContext.filename,
225-
text: editor.document.getText(),
238+
text: fileText,
226239
},
227240
cursorState: {
228241
position: {

0 commit comments

Comments
 (0)