@@ -47,13 +47,16 @@ export class PredictionKeyStrokeHandler {
4747
4848 /**
4949 * Registers listeners for visibility events to maintain shadow copies of document content
50+ * Only store and update shadow copies for currently visible editors
51+ * And remove shadow copies for files that are no longer visible
52+ * And edits are processed only if a shadow copy exists
53+ * This avoids the memory problem if hidden files are bulk edited, i.e. with global find/replace
5054 */
5155 private registerVisibleDocumentListener ( ) : void {
5256 // Track when documents become visible (switched to)
5357 const visibleDisposable = vscode . window . onDidChangeVisibleTextEditors ( ( editors ) => {
5458 const currentVisibleFiles = new Set < string > ( )
5559
56- // Update shadow copies for currently visible editors
5760 for ( const editor of editors ) {
5861 if ( editor . document . uri . scheme === 'file' ) {
5962 const filePath = editor . document . uri . fsPath
@@ -62,7 +65,6 @@ export class PredictionKeyStrokeHandler {
6265 }
6366 }
6467
65- // Remove shadow copies for files that are no longer visible
6668 for ( const filePath of this . shadowCopies . keys ( ) ) {
6769 if ( ! currentVisibleFiles . has ( filePath ) ) {
6870 this . shadowCopies . delete ( filePath )
@@ -76,7 +78,7 @@ export class PredictionKeyStrokeHandler {
7678 private updateShadowCopy ( document : vscode . TextDocument ) : void {
7779 if ( document . uri . scheme === 'file' ) {
7880 this . shadowCopies . set ( document . uri . fsPath , document . getText ( ) )
79- getLogger ( ) . debug ( `Updated shadow copy for ${ document . uri . fsPath } ` )
81+ getLogger ( 'nextEditPrediction' ) . debug ( `Updated shadow copy for ${ document . uri . fsPath } ` )
8082 }
8183 }
8284
@@ -85,7 +87,7 @@ export class PredictionKeyStrokeHandler {
8587 */
8688 private registerTextDocumentChangeListener ( ) : void {
8789 // Listen for document changes
88- const changeDisposable = vscode . workspace . onDidChangeTextDocument ( ( event ) => {
90+ const changeDisposable = vscode . workspace . onDidChangeTextDocument ( async ( event ) => {
8991 const filePath = event . document . uri . fsPath
9092 const prevContent = this . shadowCopies . get ( filePath )
9193
@@ -99,7 +101,7 @@ export class PredictionKeyStrokeHandler {
99101 return
100102 }
101103
102- this . tracker . processEdit ( event . document , prevContent )
104+ await this . tracker . processEdit ( event . document , prevContent )
103105 this . updateShadowCopy ( event . document )
104106 } )
105107
0 commit comments