提交 470c743a 编写于 作者: B Benjamin Pasero

debt - reduce amount of work when file events occur

上级 ea284a1f
......@@ -1307,7 +1307,7 @@ export class DebugService implements debug.IDebugService {
if (this.breakpointsToSendOnResourceSaved.delete(event.resource.toString())) {
this.sendBreakpoints(event.resource, true).done(null, errors.onUnexpectedError);
}
if (event.resource.toString().indexOf('.vscode/launch.json') >= 0) {
if (strings.endsWith(event.resource.toString(), '.vscode/launch.json')) {
this.launchJsonChanged = true;
}
});
......
......@@ -611,24 +611,21 @@ export class ExplorerView extends TreeViewsViewletPanel implements IExplorerView
}
private shouldRefreshFromEvent(e: FileChangesEvent): boolean {
// Filter to the ones we care
e = this.filterFileEvents(e);
if (!this.isCreated) {
return false;
}
if (e.gotAdded()) {
const added = e.getAdded();
// Filter to the ones we care
e = this.filterToViewRelevantEvents(e);
// Handle added files/folders
const added = e.getAdded();
if (added.length) {
// Check added: Refresh if added file/folder is not part of resolved root and parent is part of it
const ignoredPaths: { [resource: string]: boolean } = <{ [resource: string]: boolean }>{};
for (let i = 0; i < added.length; i++) {
const change = added[i];
if (!this.contextService.isInsideWorkspace(change.resource)) {
continue; // out of workspace file
}
// Find parent
const parent = resources.dirname(change.resource);
......@@ -651,15 +648,13 @@ export class ExplorerView extends TreeViewsViewletPanel implements IExplorerView
}
}
if (e.gotDeleted()) {
const deleted = e.getDeleted();
// Handle deleted files/folders
const deleted = e.getDeleted();
if (deleted.length) {
// Check deleted: Refresh if deleted file/folder part of resolved root
for (let j = 0; j < deleted.length; j++) {
const del = deleted[j];
if (!this.contextService.isInsideWorkspace(del.resource)) {
continue; // out of workspace file
}
if (this.model.findClosest(del.resource)) {
return true;
......@@ -667,15 +662,13 @@ export class ExplorerView extends TreeViewsViewletPanel implements IExplorerView
}
}
if (this.sortOrder === SortOrderConfiguration.MODIFIED && e.gotUpdated()) {
// Handle updated files/folders if we sort by modified
if (this.sortOrder === SortOrderConfiguration.MODIFIED) {
const updated = e.getUpdated();
// Check updated: Refresh if updated file/folder part of resolved root
for (let j = 0; j < updated.length; j++) {
const upd = updated[j];
if (!this.contextService.isInsideWorkspace(upd.resource)) {
continue; // out of workspace file
}
if (this.model.findClosest(upd.resource)) {
return true;
......@@ -686,8 +679,12 @@ export class ExplorerView extends TreeViewsViewletPanel implements IExplorerView
return false;
}
private filterFileEvents(e: FileChangesEvent): FileChangesEvent {
private filterToViewRelevantEvents(e: FileChangesEvent): FileChangesEvent {
return new FileChangesEvent(e.changes.filter(change => {
if (change.type === FileChangeType.UPDATED && this.sortOrder !== SortOrderConfiguration.MODIFIED) {
return false; // we only are about updated if we sort by modified time
}
if (!this.contextService.isInsideWorkspace(change.resource)) {
return false; // exclude changes for resources outside of workspace
}
......
......@@ -128,37 +128,50 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
}
private onFileChanges(e: FileChangesEvent): void {
let fileEventImpactsModel = false;
let newInOrphanModeGuess: boolean;
// If we are currently orphaned, we check if the model file was added back
if (this.inOrphanMode) {
const modelFileAdded = e.contains(this.resource, FileChangeType.ADDED);
if (modelFileAdded) {
newInOrphanModeGuess = false;
fileEventImpactsModel = true;
}
}
// Track ADD and DELETES for updates of this model to orphan-mode
const modelFileDeleted = e.contains(this.resource, FileChangeType.DELETED);
const modelFileAdded = e.contains(this.resource, FileChangeType.ADDED);
if (modelFileDeleted || modelFileAdded) {
const newInOrphanModeGuess = modelFileDeleted && !modelFileAdded;
if (this.inOrphanMode !== newInOrphanModeGuess) {
let checkOrphanedPromise: TPromise<boolean>;
if (newInOrphanModeGuess) {
// We have received reports of users seeing delete events even though the file still
// exists (network shares issue: https://github.com/Microsoft/vscode/issues/13665).
// Since we do not want to mark the model as orphaned, we have to check if the
// file is really gone and not just a faulty file event.
checkOrphanedPromise = TPromise.timeout(100).then(() => {
if (this.disposed) {
return true;
}
return this.fileService.existsFile(this.resource).then(exists => !exists);
});
} else {
checkOrphanedPromise = TPromise.as(false);
}
// Otherwise we check if the model file was deleted
else {
const modelFileDeleted = e.contains(this.resource, FileChangeType.DELETED);
if (modelFileDeleted) {
newInOrphanModeGuess = true;
fileEventImpactsModel = true;
}
}
checkOrphanedPromise.done(newInOrphanModeValidated => {
if (this.inOrphanMode !== newInOrphanModeValidated && !this.disposed) {
this.setOrphaned(newInOrphanModeValidated);
if (fileEventImpactsModel && this.inOrphanMode !== newInOrphanModeGuess) {
let checkOrphanedPromise: TPromise<boolean>;
if (newInOrphanModeGuess) {
// We have received reports of users seeing delete events even though the file still
// exists (network shares issue: https://github.com/Microsoft/vscode/issues/13665).
// Since we do not want to mark the model as orphaned, we have to check if the
// file is really gone and not just a faulty file event.
checkOrphanedPromise = TPromise.timeout(100).then(() => {
if (this.disposed) {
return true;
}
return this.fileService.existsFile(this.resource).then(exists => !exists);
});
} else {
checkOrphanedPromise = TPromise.as(false);
}
checkOrphanedPromise.done(newInOrphanModeValidated => {
if (this.inOrphanMode !== newInOrphanModeValidated && !this.disposed) {
this.setOrphaned(newInOrphanModeValidated);
}
});
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册