提交 62c66c72 编写于 作者: B Benjamin Pasero

Investigate to reduce working files watcher to only the ones opened (fixes #3617)

上级 49ed473d
...@@ -6,11 +6,13 @@ ...@@ -6,11 +6,13 @@
'use strict'; 'use strict';
import {IWorkbenchContribution} from 'vs/workbench/common/contributions'; import {IWorkbenchContribution} from 'vs/workbench/common/contributions';
import {LocalFileChangeEvent, IWorkingFileModelChangeEvent, EventType as FileEventType, ITextFileService, AutoSaveMode} from 'vs/workbench/parts/files/common/files'; import {LocalFileChangeEvent, EventType as FileEventType, ITextFileService, AutoSaveMode} from 'vs/workbench/parts/files/common/files';
import {IFileService} from 'vs/platform/files/common/files'; import {IFileService} from 'vs/platform/files/common/files';
import {OpenResourcesAction} from 'vs/workbench/parts/files/browser/fileActions'; import {OpenResourcesAction} from 'vs/workbench/parts/files/browser/fileActions';
import plat = require('vs/base/common/platform'); import plat = require('vs/base/common/platform');
import {asFileEditorInput} from 'vs/workbench/common/editor';
import errors = require('vs/base/common/errors'); import errors = require('vs/base/common/errors');
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import URI from 'vs/base/common/uri'; import URI from 'vs/base/common/uri';
import {EventType as WorkbenchEventType} from 'vs/workbench/common/events'; import {EventType as WorkbenchEventType} from 'vs/workbench/common/events';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService'; import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
...@@ -46,6 +48,7 @@ export class FileTracker implements IWorkbenchContribution { ...@@ -46,6 +48,7 @@ export class FileTracker implements IWorkbenchContribution {
@IPartService private partService: IPartService, @IPartService private partService: IPartService,
@IFileService private fileService: IFileService, @IFileService private fileService: IFileService,
@ITextFileService private textFileService: ITextFileService, @ITextFileService private textFileService: ITextFileService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IInstantiationService private instantiationService: IInstantiationService, @IInstantiationService private instantiationService: IInstantiationService,
@IUntitledEditorService private untitledEditorService: IUntitledEditorService, @IUntitledEditorService private untitledEditorService: IUntitledEditorService,
@ILifecycleService private lifecycleService: ILifecycleService @ILifecycleService private lifecycleService: ILifecycleService
...@@ -61,9 +64,6 @@ export class FileTracker implements IWorkbenchContribution { ...@@ -61,9 +64,6 @@ export class FileTracker implements IWorkbenchContribution {
} }
this.registerListeners(); this.registerListeners();
// Listen to out of workspace file changes
this.updateOutOfWorkspaceFileListeners({ added: this.textFileService.getWorkingFilesModel().getEntries() });
} }
private registerListeners(): void { private registerListeners(): void {
...@@ -76,10 +76,6 @@ export class FileTracker implements IWorkbenchContribution { ...@@ -76,10 +76,6 @@ export class FileTracker implements IWorkbenchContribution {
this.toUnbind.push(this.eventService.addListener(FileEventType.FILE_SAVE_ERROR, (e: LocalFileChangeEvent) => this.onTextFileSaveError(e))); this.toUnbind.push(this.eventService.addListener(FileEventType.FILE_SAVE_ERROR, (e: LocalFileChangeEvent) => this.onTextFileSaveError(e)));
this.toUnbind.push(this.eventService.addListener(FileEventType.FILE_REVERTED, (e: LocalFileChangeEvent) => this.onTextFileReverted(e))); this.toUnbind.push(this.eventService.addListener(FileEventType.FILE_REVERTED, (e: LocalFileChangeEvent) => this.onTextFileReverted(e)));
// Working Files Model Change
const disposable = this.textFileService.getWorkingFilesModel().onModelChange(this.onWorkingFilesModelChange, this);
this.toUnbind.push(() => disposable.dispose());
// Support openFiles event for existing and new files // Support openFiles event for existing and new files
ipc.on('vscode:openFiles', (event, request: IOpenFileRequest) => { ipc.on('vscode:openFiles', (event, request: IOpenFileRequest) => {
let inputs: IResourceInput[] = []; let inputs: IResourceInput[] = [];
...@@ -99,6 +95,10 @@ export class FileTracker implements IWorkbenchContribution { ...@@ -99,6 +95,10 @@ export class FileTracker implements IWorkbenchContribution {
} }
}); });
// Editor input changes
this.toUnbind.push(this.eventService.addListener(WorkbenchEventType.EDITOR_INPUT_CHANGED, () => this.onEditorInputChanged()));
// Lifecycle
this.lifecycleService.onShutdown(this.dispose, this); this.lifecycleService.onShutdown(this.dispose, this);
} }
...@@ -121,31 +121,32 @@ export class FileTracker implements IWorkbenchContribution { ...@@ -121,31 +121,32 @@ export class FileTracker implements IWorkbenchContribution {
}); });
} }
private updateOutOfWorkspaceFileListeners(event: IWorkingFileModelChangeEvent): void { private onEditorInputChanged(): void {
let added = event.added ? event.added.map((e) => e.resource).filter((r) => r.scheme === 'file' && !this.contextService.isInsideWorkspace(r)) : []; let visibleOutOfWorkspaceResources = this.editorService.getVisibleEditors().map((editor) => {
let removed = event.removed ? event.removed.map((e) => e.resource).filter((r) => r.scheme === 'file' && !this.contextService.isInsideWorkspace(r)) : []; return asFileEditorInput(editor.input, true);
}).filter((input) => {
return !!input && !this.contextService.isInsideWorkspace(input.getResource());
}).map((input) => {
return input.getResource().toString();
});
// Handle added // Handle no longer visible out of workspace resources
added.forEach((resource) => { Object.keys(this.activeOutOfWorkspaceWatchers).forEach((watchedResource) => {
if (!this.activeOutOfWorkspaceWatchers[resource.toString()]) { if (visibleOutOfWorkspaceResources.indexOf(watchedResource) < 0) {
this.fileService.watchFileChanges(resource); this.fileService.unwatchFileChanges(watchedResource);
this.activeOutOfWorkspaceWatchers[resource.toString()] = true; delete this.activeOutOfWorkspaceWatchers[watchedResource];
} }
}); });
// Handle removed // Handle newly visible out of workspace resources
removed.forEach((resource) => { visibleOutOfWorkspaceResources.forEach((resourceToWatch) => {
if (this.activeOutOfWorkspaceWatchers[resource.toString()]) { if (!this.activeOutOfWorkspaceWatchers[resourceToWatch]) {
this.fileService.unwatchFileChanges(resource); this.fileService.watchFileChanges(URI.parse(resourceToWatch));
delete this.activeOutOfWorkspaceWatchers[resource.toString()]; this.activeOutOfWorkspaceWatchers[resourceToWatch] = true;
} }
}); });
} }
private onWorkingFilesModelChange(event: IWorkingFileModelChangeEvent): void {
this.updateOutOfWorkspaceFileListeners(event);
}
private onUntitledDirtyEvent(): void { private onUntitledDirtyEvent(): void {
if (!this.isDocumentedEdited) { if (!this.isDocumentedEdited) {
this.updateDocumentEdited(); this.updateDocumentEdited();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册