66import { IWorkbenchContribution } from 'vs/workbench/common/contributions' ;
77import { URI } from 'vs/base/common/uri' ;
88import { IEditorViewState } from 'vs/editor/common/editorCommon' ;
9- import { toResource , SideBySideEditorInput , IWorkbenchEditorConfiguration , SideBySideEditor as SideBySideEditorChoice } from 'vs/workbench/common/editor' ;
9+ import { toResource , SideBySideEditor as SideBySideEditorChoice } from 'vs/workbench/common/editor' ;
1010import { ITextFileService , TextFileEditorModelState } from 'vs/workbench/services/textfile/common/textfiles' ;
11- import { FileOperationEvent , FileOperation , IFileService , FileChangeType , FileChangesEvent , FileSystemProviderCapabilities } from 'vs/platform/files/common/files' ;
11+ import { FileOperationEvent , FileOperation , IFileService , FileSystemProviderCapabilities } from 'vs/platform/files/common/files' ;
1212import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput' ;
1313import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle' ;
1414import { Disposable , IDisposable , dispose } from 'vs/base/common/lifecycle' ;
1515import { distinct , coalesce } from 'vs/base/common/arrays' ;
16- import { IEnvironmentService } from 'vs/platform/environment/common/environment' ;
17- import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
1816import { ResourceMap } from 'vs/base/common/map' ;
1917import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace' ;
2018import { isCodeEditor } from 'vs/editor/browser/editorBrowser' ;
2119import { IHostService } from 'vs/workbench/services/host/browser/host' ;
2220import { IEditorService } from 'vs/workbench/services/editor/common/editorService' ;
2321import { IEditorGroupsService , IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService' ;
24- import { timeout , RunOnceWorker } from 'vs/base/common/async' ;
22+ import { RunOnceWorker } from 'vs/base/common/async' ;
2523import { withNullAsUndefined } from 'vs/base/common/types' ;
2624import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService' ;
2725import { isEqualOrParent , joinPath } from 'vs/base/common/resources' ;
@@ -37,26 +35,19 @@ export class FileEditorTracker extends Disposable implements IWorkbenchContribut
3735 @ILifecycleService private readonly lifecycleService : ILifecycleService ,
3836 @IEditorGroupsService private readonly editorGroupService : IEditorGroupsService ,
3937 @IFileService private readonly fileService : IFileService ,
40- @IEnvironmentService private readonly environmentService : IEnvironmentService ,
41- @IConfigurationService private readonly configurationService : IConfigurationService ,
4238 @IWorkspaceContextService private readonly contextService : IWorkspaceContextService ,
4339 @IHostService private readonly hostService : IHostService ,
4440 @ICodeEditorService private readonly codeEditorService : ICodeEditorService
4541 ) {
4642 super ( ) ;
4743
48- this . onConfigurationUpdated ( configurationService . getValue < IWorkbenchEditorConfiguration > ( ) ) ;
49-
5044 this . registerListeners ( ) ;
5145 }
5246
5347 private registerListeners ( ) : void {
5448
5549 // Update editors from operation changes
56- this . _register ( this . fileService . onDidRunOperation ( e => this . onFileOperation ( e ) ) ) ;
57-
58- // Update editors from disk changes
59- this . _register ( this . fileService . onDidFilesChange ( e => this . onDidFilesChange ( e ) ) ) ;
50+ this . _register ( this . fileService . onDidRunOperation ( e => this . onDidRunFileOperation ( e ) ) ) ;
6051
6152 // Ensure dirty text file and untitled models are always opened as editors
6253 this . _register ( this . textFileService . files . onDidChangeDirty ( model => this . ensureDirtyFilesAreOpenedWorker . work ( model . resource ) ) ) ;
@@ -69,9 +60,6 @@ export class FileEditorTracker extends Disposable implements IWorkbenchContribut
6960 // Update visible editors when focus is gained
7061 this . _register ( this . hostService . onDidChangeFocus ( e => this . onWindowFocusChange ( e ) ) ) ;
7162
72- // Configuration
73- this . _register ( this . configurationService . onDidChangeConfiguration ( e => this . onConfigurationUpdated ( this . configurationService . getValue < IWorkbenchEditorConfiguration > ( ) ) ) ) ;
74-
7563 // Lifecycle
7664 this . lifecycleService . onShutdown ( this . dispose , this ) ;
7765 }
@@ -82,17 +70,12 @@ export class FileEditorTracker extends Disposable implements IWorkbenchContribut
8270 // carrying all necessary data in all environments, we also use the file operation events to make sure operations are handled.
8371 // In any case there is no guarantee if the local event is fired first or the disk one. Thus, code must handle the case
8472 // that the event ordering is random as well as might not carry all information needed.
85- private onFileOperation ( e : FileOperationEvent ) : void {
73+ private onDidRunFileOperation ( e : FileOperationEvent ) : void {
8674
8775 // Handle moves specially when file is opened
8876 if ( e . isOperation ( FileOperation . MOVE ) ) {
8977 this . handleMovedFileInOpenedFileEditors ( e . resource , e . target . resource ) ;
9078 }
91-
92- // Handle deletes
93- if ( e . isOperation ( FileOperation . DELETE ) || e . isOperation ( FileOperation . MOVE ) ) {
94- this . handleDeletes ( e . resource , false , e . target ? e . target . resource : undefined ) ;
95- }
9679 }
9780
9881 private handleMovedFileInOpenedFileEditors ( oldResource : URI , newResource : URI ) : void {
@@ -175,110 +158,11 @@ export class FileEditorTracker extends Disposable implements IWorkbenchContribut
175158
176159 //#endregion
177160
178- //#region File Changes: Close editors of deleted files unless configured otherwise
179-
180- private closeOnFileDelete : boolean = false ;
181-
182- private onConfigurationUpdated ( configuration : IWorkbenchEditorConfiguration ) : void {
183- if ( typeof configuration . workbench ?. editor ?. closeOnFileDelete === 'boolean' ) {
184- this . closeOnFileDelete = configuration . workbench . editor . closeOnFileDelete ;
185- } else {
186- this . closeOnFileDelete = false ; // default
187- }
188- }
189-
190- private onDidFilesChange ( e : FileChangesEvent ) : void {
191- if ( e . gotDeleted ( ) ) {
192- this . handleDeletes ( e , true ) ;
193- }
194- }
195-
196- private handleDeletes ( arg1 : URI | FileChangesEvent , isExternal : boolean , movedTo ?: URI ) : void {
197- const nonDirtyFileEditors = this . getNonDirtyFileEditors ( ) ;
198- nonDirtyFileEditors . forEach ( async editor => {
199- const resource = editor . resource ;
200-
201- // Handle deletes in opened editors depending on:
202- // - the user has not disabled the setting closeOnFileDelete
203- // - the file change is local or external
204- // - the input is not resolved (we need to dispose because we cannot restore otherwise since we do not have the contents)
205- if ( this . closeOnFileDelete || ! isExternal || ! editor . isResolved ( ) ) {
206-
207- // Do NOT close any opened editor that matches the resource path (either equal or being parent) of the
208- // resource we move to (movedTo). Otherwise we would close a resource that has been renamed to the same
209- // path but different casing.
210- if ( movedTo && isEqualOrParent ( resource , movedTo ) ) {
211- return ;
212- }
213-
214- let matches = false ;
215- if ( arg1 instanceof FileChangesEvent ) {
216- matches = arg1 . contains ( resource , FileChangeType . DELETED ) ;
217- } else {
218- matches = isEqualOrParent ( resource , arg1 ) ;
219- }
220-
221- if ( ! matches ) {
222- return ;
223- }
224-
225- // We have received reports of users seeing delete events even though the file still
226- // exists (network shares issue: https://github.com/Microsoft/vscode/issues/13665).
227- // Since we do not want to close an editor without reason, we have to check if the
228- // file is really gone and not just a faulty file event.
229- // This only applies to external file events, so we need to check for the isExternal
230- // flag.
231- let exists = false ;
232- if ( isExternal ) {
233- await timeout ( 100 ) ;
234- exists = await this . fileService . exists ( resource ) ;
235- }
236-
237- if ( ! exists && ! editor . isDisposed ( ) ) {
238- editor . dispose ( ) ;
239- } else if ( this . environmentService . verbose ) {
240- console . warn ( `File exists even though we received a delete event: ${ resource . toString ( ) } ` ) ;
241- }
242- }
243- } ) ;
244- }
245-
246- private getNonDirtyFileEditors ( ) : FileEditorInput [ ] {
247- const editors : FileEditorInput [ ] = [ ] ;
248-
249- this . editorService . editors . forEach ( editor => {
250- if ( editor instanceof FileEditorInput ) {
251- if ( ! editor . isDirty ( ) ) {
252- editors . push ( editor ) ;
253- }
254- } else if ( editor instanceof SideBySideEditorInput ) {
255- const master = editor . master ;
256- const details = editor . details ;
257-
258- if ( master instanceof FileEditorInput ) {
259- if ( ! master . isDirty ( ) ) {
260- editors . push ( master ) ;
261- }
262- }
263-
264- if ( details instanceof FileEditorInput ) {
265- if ( ! details . isDirty ( ) ) {
266- editors . push ( details ) ;
267- }
268- }
269- }
270- } ) ;
271-
272- return editors ;
273- }
274-
275- //#endregion
276-
277161 //#region Text File: Ensure every dirty text and untitled file is opened in an editor
278162
279- private readonly ensureDirtyFilesAreOpenedWorker = this . _register ( new RunOnceWorker < URI > ( units => this . ensureDirtyFilesAreOpened ( units ) , 250 ) ) ;
163+ private readonly ensureDirtyFilesAreOpenedWorker = this . _register ( new RunOnceWorker < URI > ( units => this . ensureDirtyTextFilesAreOpened ( units ) , 250 ) ) ;
280164
281- private ensureDirtyFilesAreOpened ( resources : URI [ ] ) : void {
165+ private ensureDirtyTextFilesAreOpened ( resources : URI [ ] ) : void {
282166 this . doEnsureDirtyFilesAreOpened ( distinct ( resources . filter ( resource => {
283167 if ( ! this . textFileService . isDirty ( resource ) ) {
284168 return false ; // resource must be dirty
@@ -347,7 +231,7 @@ export class FileEditorTracker extends Disposable implements IWorkbenchContribut
347231
348232 //#endregion
349233
350- //#region Window Focus Change: Update visible code editors when focus is gained
234+ //#region Window Focus Change: Update visible code editors when focus is gained that have a known text file model
351235
352236 private onWindowFocusChange ( focused : boolean ) : void {
353237 if ( focused ) {
0 commit comments