diff --git a/src/vs/workbench/api/node/mainThreadDocuments.ts b/src/vs/workbench/api/node/mainThreadDocuments.ts index 398941992ac..35d4871b8e6 100644 --- a/src/vs/workbench/api/node/mainThreadDocuments.ts +++ b/src/vs/workbench/api/node/mainThreadDocuments.ts @@ -12,8 +12,6 @@ import { IThreadService } from 'vs/workbench/services/thread/common/threadServic import URI from 'vs/base/common/uri'; import { IDisposable, dispose } from 'vs/base/common/lifecycle'; import { IEventService } from 'vs/platform/event/common/event'; -import { getResource } from 'vs/workbench/common/editor'; -import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; import { TextFileModelChangeEvent, ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; import { TPromise } from 'vs/base/common/winjs.base'; import { IFileService } from 'vs/platform/files/common/files'; @@ -29,7 +27,6 @@ export class MainThreadDocuments extends MainThreadDocumentsShape { private _textModelResolverService: ITextModelResolverService; private _textFileService: ITextFileService; private _codeEditorService: ICodeEditorService; - private _editorService: IWorkbenchEditorService; private _fileService: IFileService; private _untitledEditorService: IUntitledEditorService; private _toDispose: IDisposable[]; @@ -37,7 +34,6 @@ export class MainThreadDocuments extends MainThreadDocumentsShape { private _proxy: ExtHostDocumentsShape; private _modelIsSynced: { [modelId: string]: boolean; }; private _resourceContentProvider: { [handle: number]: IDisposable }; - private _virtualDocumentSet: { [resource: string]: boolean }; constructor( @IThreadService threadService: IThreadService, @@ -46,7 +42,6 @@ export class MainThreadDocuments extends MainThreadDocumentsShape { @IEventService eventService: IEventService, @ITextFileService textFileService: ITextFileService, @ICodeEditorService codeEditorService: ICodeEditorService, - @IWorkbenchEditorService editorService: IWorkbenchEditorService, @IFileService fileService: IFileService, @ITextModelResolverService textModelResolverService: ITextModelResolverService, @IUntitledEditorService untitledEditorService: IUntitledEditorService @@ -57,7 +52,6 @@ export class MainThreadDocuments extends MainThreadDocumentsShape { this._textModelResolverService = textModelResolverService; this._textFileService = textFileService; this._codeEditorService = codeEditorService; - this._editorService = editorService; this._fileService = fileService; this._untitledEditorService = untitledEditorService; this._proxy = threadService.get(ExtHostContext.ExtHostDocuments); @@ -84,12 +78,8 @@ export class MainThreadDocuments extends MainThreadDocumentsShape { } })); - const handle = setInterval(() => this._runDocumentCleanup(), 1000 * 60 * 3); - this._toDispose.push({ dispose() { clearInterval(handle); } }); - this._modelToDisposeMap = Object.create(null); this._resourceContentProvider = Object.create(null); - this._virtualDocumentSet = Object.create(null); } public dispose(): void { @@ -229,7 +219,6 @@ export class MainThreadDocuments extends MainThreadDocumentsShape { provideTextContent: (uri: URI): TPromise => { return this._proxy.$provideTextDocumentContent(handle, uri).then(value => { if (typeof value === 'string') { - this._virtualDocumentSet[uri.toString()] = true; const firstLineText = value.substr(0, 1 + value.search(/\r?\n/)); const mode = this._modeService.getOrCreateModeByFilenameOrFirstLine(uri.fsPath, firstLineText); return this._modelService.createModel(value, mode, uri); @@ -253,37 +242,4 @@ export class MainThreadDocuments extends MainThreadDocumentsShape { model.setValue(value); } } - - private _runDocumentCleanup(): void { - - const toBeDisposed: URI[] = []; - - // list of uris used in editors - const activeResources: { [uri: string]: boolean } = Object.create(null); - for (const editor of this._codeEditorService.listCodeEditors()) { - if (editor.getModel()) { - activeResources[editor.getModel().uri.toString()] = true; - } - } - - for (const workbenchEditor of this._editorService.getVisibleEditors()) { - const uri = getResource(workbenchEditor.input); - if (uri) { - activeResources[uri.toString()] = true; - } - } - - // intersect with virtual documents - for (let uri in this._virtualDocumentSet) { - if (!activeResources[uri]) { - toBeDisposed.push(URI.parse(uri)); - } - } - - // dispose unused virtual documents - for (let resource of toBeDisposed) { - this._modelService.destroyModel(resource); - delete this._virtualDocumentSet[resource.toString()]; - } - } } diff --git a/src/vs/workbench/parts/html/browser/htmlPreviewPart.ts b/src/vs/workbench/parts/html/browser/htmlPreviewPart.ts index 3e5f39fb59e..54d75d84b4d 100644 --- a/src/vs/workbench/parts/html/browser/htmlPreviewPart.ts +++ b/src/vs/workbench/parts/html/browser/htmlPreviewPart.ts @@ -66,9 +66,9 @@ export class HtmlPreviewPart extends BaseEditor { // unhook listeners this._themeChangeSubscription.dispose(); this._modelChangeSubscription.dispose(); - if (this._modelRef) { - this._modelRef.dispose(); - } + + // dipose model ref + dispose(this._modelRef); super.dispose(); } @@ -138,9 +138,15 @@ export class HtmlPreviewPart extends BaseEditor { this.webview.focus(); } + public clearInput(): void { + dispose(this._modelRef); + this._modelRef = undefined; + super.clearInput(); + } + public setInput(input: EditorInput, options?: EditorOptions): TPromise { - if (this.input === input && this._hasValidModel()) { + if (this.input && this.input.matches(input) && this._hasValidModel()) { return TPromise.as(undefined); }