File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
packages/core/src/codewhisperer/util Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -216,13 +216,26 @@ export function getTabSize(): number {
216216
217217export 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 : {
You can’t perform that action at this time.
0 commit comments