@@ -23,7 +23,7 @@ import { IWorkingCopySaveEvent, IWorkingCopyService } from 'vs/workbench/service
23
23
import { Schemas } from 'vs/base/common/network' ;
24
24
import { ResourceGlobMatcher } from 'vs/workbench/common/resources' ;
25
25
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace' ;
26
- import { FileOperation , FileOperationEvent , IFileService } from 'vs/platform/files/common/files' ;
26
+ import { FileOperation , FileOperationEvent , IFileOperationEventWithMetadata , IFileService , IFileStatWithMetadata } from 'vs/platform/files/common/files' ;
27
27
28
28
export class WorkingCopyHistoryTracker extends Disposable implements IWorkbenchContribution {
29
29
@@ -79,8 +79,8 @@ export class WorkingCopyHistoryTracker extends Disposable implements IWorkbenchC
79
79
}
80
80
81
81
private async onDidRunFileOperation ( e : FileOperationEvent ) : Promise < void > {
82
- if ( ! e . isOperation ( FileOperation . MOVE ) ) {
83
- return ; // only interested in move operations
82
+ if ( ! this . shouldTrackHistoryFromFileOperationEvent ( e ) ) {
83
+ return ; // return early for working copies we are not interested in
84
84
}
85
85
86
86
const source = e . resource ;
@@ -111,7 +111,7 @@ export class WorkingCopyHistoryTracker extends Disposable implements IWorkbenchC
111
111
}
112
112
113
113
private onDidSave ( e : IWorkingCopySaveEvent ) : void {
114
- if ( ! this . shouldTrackHistory ( e ) ) {
114
+ if ( ! this . shouldTrackHistoryFromSaveEvent ( e ) ) {
115
115
return ; // return early for working copies we are not interested in
116
116
}
117
117
@@ -174,28 +174,40 @@ export class WorkingCopyHistoryTracker extends Disposable implements IWorkbenchC
174
174
return undefined ;
175
175
}
176
176
177
- private shouldTrackHistory ( e : IWorkingCopySaveEvent ) : e is IStoredFileWorkingCopySaveEvent < IStoredFileWorkingCopyModel > {
177
+ private shouldTrackHistoryFromSaveEvent ( e : IWorkingCopySaveEvent ) : e is IStoredFileWorkingCopySaveEvent < IStoredFileWorkingCopyModel > {
178
+ if ( ! isStoredFileWorkingCopySaveEvent ( e ) ) {
179
+ return false ; // only support working copies that are backed by stored files
180
+ }
181
+
182
+ return this . shouldTrackHistory ( e . workingCopy . resource , e . stat ) ;
183
+ }
184
+
185
+ private shouldTrackHistoryFromFileOperationEvent ( e : FileOperationEvent ) : e is IFileOperationEventWithMetadata {
186
+ if ( ! e . isOperation ( FileOperation . MOVE ) ) {
187
+ return false ; // only interested in move operations
188
+ }
189
+
190
+ return this . shouldTrackHistory ( e . target . resource , e . target ) ;
191
+ }
192
+
193
+ private shouldTrackHistory ( resource : URI , stat : IFileStatWithMetadata ) : boolean {
178
194
if (
179
- e . workingCopy . resource . scheme !== this . pathService . defaultUriScheme && // track history for all workspace resources
180
- e . workingCopy . resource . scheme !== Schemas . vscodeUserData // track history for all settings
195
+ resource . scheme !== this . pathService . defaultUriScheme && // track history for all workspace resources
196
+ resource . scheme !== Schemas . vscodeUserData // track history for all settings
181
197
) {
182
198
return false ; // do not support unknown resources
183
199
}
184
200
185
- if ( ! isStoredFileWorkingCopySaveEvent ( e ) ) {
186
- return false ; // only support working copies that are backed by stored files
187
- }
188
-
189
- const configuredMaxFileSizeInBytes = 1024 * this . configurationService . getValue < number > ( WorkingCopyHistoryTracker . SETTINGS . SIZE_LIMIT , { resource : e . workingCopy . resource } ) ;
190
- if ( e . stat . size > configuredMaxFileSizeInBytes ) {
201
+ const configuredMaxFileSizeInBytes = 1024 * this . configurationService . getValue < number > ( WorkingCopyHistoryTracker . SETTINGS . SIZE_LIMIT , { resource } ) ;
202
+ if ( stat . size > configuredMaxFileSizeInBytes ) {
191
203
return false ; // only track files that are not too large
192
204
}
193
205
194
- if ( this . configurationService . getValue ( WorkingCopyHistoryTracker . SETTINGS . ENABLED , { resource : e . workingCopy . resource } ) === false ) {
206
+ if ( this . configurationService . getValue ( WorkingCopyHistoryTracker . SETTINGS . ENABLED , { resource } ) === false ) {
195
207
return false ; // do not track when history is disabled
196
208
}
197
209
198
210
// Finally check for exclude setting
199
- return ! this . resourceExcludeMatcher . value . matches ( e . workingCopy . resource ) ;
211
+ return ! this . resourceExcludeMatcher . value . matches ( resource ) ;
200
212
}
201
213
}
0 commit comments