diff --git a/src/vs/editor/browser/standalone/simpleServices.ts b/src/vs/editor/browser/standalone/simpleServices.ts index d2023e12743..8b20b6e0c09 100644 --- a/src/vs/editor/browser/standalone/simpleServices.ts +++ b/src/vs/editor/browser/standalone/simpleServices.ts @@ -26,7 +26,7 @@ import { getDefaultValues as getDefaultConfiguration } from 'vs/platform/configu import { CommandService } from 'vs/platform/commands/common/commandService'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IProgressService, IProgressRunner } from 'vs/platform/progress/common/progress'; -import { ITextModelResolverService, IResolveOptions, ITextModelContentProvider } from 'vs/platform/textmodelResolver/common/textModelResolverService'; +import { ITextModelResolverService, IResolveOptions, ITextModelContentProvider } from 'vs/platform/textmodelResolver/common/resolver'; import { IDisposable } from 'vs/base/common/lifecycle'; export class SimpleEditor implements IEditor { diff --git a/src/vs/editor/browser/standalone/standaloneEditor.ts b/src/vs/editor/browser/standalone/standaloneEditor.ts index e0149773923..32e25f36ab7 100644 --- a/src/vs/editor/browser/standalone/standaloneEditor.ts +++ b/src/vs/editor/browser/standalone/standaloneEditor.ts @@ -30,7 +30,7 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { ICodeEditorService } from 'vs/editor/common/services/codeEditorService'; import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService'; -import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/textModelResolverService'; +import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/resolver'; /** * @internal diff --git a/src/vs/editor/common/services/bulkEdit.ts b/src/vs/editor/common/services/bulkEdit.ts index e2e08216d8c..bb19d42bfcd 100644 --- a/src/vs/editor/common/services/bulkEdit.ts +++ b/src/vs/editor/common/services/bulkEdit.ts @@ -9,7 +9,7 @@ import { merge } from 'vs/base/common/arrays'; import { IStringDictionary, forEach, values } from 'vs/base/common/collections'; import URI from 'vs/base/common/uri'; import { TPromise } from 'vs/base/common/winjs.base'; -import { IEditorService } from 'vs/platform/editor/common/editor'; +import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/resolver'; import { IEventService } from 'vs/platform/event/common/event'; import { EventType as FileEventType, FileChangesEvent, IFileChange } from 'vs/platform/files/common/files'; import { EditOperation } from 'vs/editor/common/core/editOperation'; @@ -157,7 +157,7 @@ class SourceModelEditTask extends EditTask { class BulkEditModel { - private _editorService: IEditorService; + private _textModelResolverService: ITextModelResolverService; private _numberOfResourcesToModify: number = 0; private _numberOfChanges: number = 0; private _edits: IStringDictionary = Object.create(null); @@ -166,8 +166,8 @@ class BulkEditModel { private _sourceSelections: Selection[]; private _sourceModelTask: SourceModelEditTask; - constructor(editorService: IEditorService, sourceModel: URI, sourceSelections: Selection[], edits: IResourceEdit[], private progress: IProgressRunner = null) { - this._editorService = editorService; + constructor(textModelResolverService: ITextModelResolverService, sourceModel: URI, sourceSelections: Selection[], edits: IResourceEdit[], private progress: IProgressRunner = null) { + this._textModelResolverService = textModelResolverService; this._sourceModel = sourceModel; this._sourceSelections = sourceSelections; this._sourceModelTask = null; @@ -209,7 +209,7 @@ class BulkEditModel { } forEach(this._edits, entry => { - var promise = this._editorService.resolveEditorModel({ resource: URI.parse(entry.key) }).then(model => { + var promise = this._textModelResolverService.resolve(URI.parse(entry.key)).then(model => { if (!model || !model.textEditorModel) { throw new Error(`Cannot load file ${entry.key}`); } @@ -260,14 +260,14 @@ export interface BulkEdit { finish(): TPromise; } -export function bulkEdit(eventService: IEventService, editorService: IEditorService, editor: ICommonCodeEditor, edits: IResourceEdit[], progress: IProgressRunner = null): TPromise { - let bulk = createBulkEdit(eventService, editorService, editor); +export function bulkEdit(eventService: IEventService, textModelResolverService: ITextModelResolverService, editor: ICommonCodeEditor, edits: IResourceEdit[], progress: IProgressRunner = null): TPromise { + let bulk = createBulkEdit(eventService, textModelResolverService, editor); bulk.add(edits); bulk.progress(progress); return bulk.finish(); } -export function createBulkEdit(eventService: IEventService, editorService: IEditorService, editor: ICommonCodeEditor): BulkEdit { +export function createBulkEdit(eventService: IEventService, textModelResolverService: ITextModelResolverService, editor: ICommonCodeEditor): BulkEdit { let all: IResourceEdit[] = []; let recording = new ChangeRecorder(eventService).start(); @@ -315,7 +315,7 @@ export function createBulkEdit(eventService: IEventService, editorService: IEdit selections = editor.getSelections(); } - let model = new BulkEditModel(editorService, uri, selections, all, progressRunner); + let model = new BulkEditModel(textModelResolverService, uri, selections, all, progressRunner); return model.prepare().then(_ => { diff --git a/src/vs/editor/contrib/goToDeclaration/browser/goToDeclaration.ts b/src/vs/editor/contrib/goToDeclaration/browser/goToDeclaration.ts index 2c33ea87f67..cd71f592581 100644 --- a/src/vs/editor/contrib/goToDeclaration/browser/goToDeclaration.ts +++ b/src/vs/editor/contrib/goToDeclaration/browser/goToDeclaration.ts @@ -32,6 +32,7 @@ import { ReferencesModel } from 'vs/editor/contrib/referenceSearch/browser/refer import { IDisposable, dispose } from 'vs/base/common/lifecycle'; import { PeekContext } from 'vs/editor/contrib/zoneWidget/browser/peekViewWidget'; import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; +import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/resolver'; import ModeContextKeys = editorCommon.ModeContextKeys; import EditorContextKeys = editorCommon.EditorContextKeys; @@ -233,7 +234,7 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC constructor( editor: ICodeEditor, - @IEditorService private editorService: IEditorService, + @ITextModelResolverService private textModelResolverService: ITextModelResolverService, @IModeService private modeService: IModeService ) { this.toUnhook = []; @@ -318,7 +319,7 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC // Single result else { let result = results[0]; - this.editorService.resolveEditorModel({ resource: result.uri }).then(model => { + this.textModelResolverService.resolve(result.uri).then(model => { let hoverMessage: MarkedString; if (model && model.textEditorModel) { const editorModel = model.textEditorModel; diff --git a/src/vs/editor/contrib/referenceSearch/browser/referencesController.ts b/src/vs/editor/contrib/referenceSearch/browser/referencesController.ts index d66c428b668..173ff1ed5e7 100644 --- a/src/vs/editor/contrib/referenceSearch/browser/referencesController.ts +++ b/src/vs/editor/contrib/referenceSearch/browser/referencesController.ts @@ -25,6 +25,7 @@ import { IPeekViewService } from 'vs/editor/contrib/zoneWidget/browser/peekViewW import { ReferencesModel, OneReference } from './referencesModel'; import { ReferenceWidget, LayoutData } from './referencesWidget'; import { Range } from 'vs/editor/common/core/range'; +import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/resolver'; export const ctxReferenceSearchVisible = new RawContextKey('referenceSearchVisible', false); @@ -55,6 +56,7 @@ export class ReferencesController implements editorCommon.IEditorContribution { editor: ICodeEditor, @IContextKeyService contextKeyService: IContextKeyService, @IEditorService private _editorService: IEditorService, + @ITextModelResolverService private _textModelResolverService, @ITelemetryService private _telemetryService: ITelemetryService, @IMessageService private _messageService: IMessageService, @IInstantiationService private _instantiationService: IInstantiationService, @@ -102,7 +104,7 @@ export class ReferencesController implements editorCommon.IEditorContribution { })); const storageKey = 'peekViewLayout'; const data = JSON.parse(this._storageService.get(storageKey, undefined, '{}')); - this._widget = new ReferenceWidget(this._editor, data, this._editorService, this._contextService, this._instantiationService); + this._widget = new ReferenceWidget(this._editor, data, this._textModelResolverService, this._contextService, this._instantiationService); this._widget.setTitle(nls.localize('labelLoading', "Loading...")); this._widget.show(range); this._disposables.push(this._widget.onDidClose(() => { diff --git a/src/vs/editor/contrib/referenceSearch/browser/referencesModel.ts b/src/vs/editor/contrib/referenceSearch/browser/referencesModel.ts index 453b72c5183..08bdb6ba950 100644 --- a/src/vs/editor/contrib/referenceSearch/browser/referencesModel.ts +++ b/src/vs/editor/contrib/referenceSearch/browser/referencesModel.ts @@ -11,10 +11,10 @@ import * as strings from 'vs/base/common/strings'; import URI from 'vs/base/common/uri'; import { defaultGenerator } from 'vs/base/common/idGenerator'; import { TPromise } from 'vs/base/common/winjs.base'; -import { IEditorService } from 'vs/platform/editor/common/editor'; import { Range } from 'vs/editor/common/core/range'; import { IModel, IPosition, IRange } from 'vs/editor/common/editorCommon'; import { Location } from 'vs/editor/common/modes'; +import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/resolver'; export class OneReference { @@ -128,13 +128,13 @@ export class FileReferences { return this._loadFailure; } - public resolve(editorService: IEditorService): TPromise { + public resolve(textModelResolverService: ITextModelResolverService): TPromise { if (this._resolved) { return TPromise.as(this); } - return editorService.resolveEditorModel({ resource: this._uri }).then(model => { + return textModelResolverService.resolve(this._uri).then(model => { if (!model) { throw new Error(); } diff --git a/src/vs/editor/contrib/referenceSearch/browser/referencesWidget.ts b/src/vs/editor/contrib/referenceSearch/browser/referencesWidget.ts index f409b0614a2..8e06439ef2e 100644 --- a/src/vs/editor/contrib/referenceSearch/browser/referencesWidget.ts +++ b/src/vs/editor/contrib/referenceSearch/browser/referencesWidget.ts @@ -26,7 +26,6 @@ import { LeftRightWidget } from 'vs/base/browser/ui/leftRightWidget/leftRightWid import * as tree from 'vs/base/parts/tree/browser/tree'; import { DefaultController, LegacyRenderer } from 'vs/base/parts/tree/browser/treeDefaults'; import { Tree } from 'vs/base/parts/tree/browser/treeImpl'; -import { IEditorService } from 'vs/platform/editor/common/editor'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; @@ -38,6 +37,7 @@ import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { EmbeddedCodeEditorWidget } from 'vs/editor/browser/widget/embeddedCodeEditorWidget'; import { PeekViewWidget, IPeekViewService } from 'vs/editor/contrib/zoneWidget/browser/peekViewWidget'; import { FileReferences, OneReference, ReferencesModel } from './referencesModel'; +import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/resolver'; class DecorationsManager implements IDisposable { @@ -165,7 +165,7 @@ class DecorationsManager implements IDisposable { class DataSource implements tree.IDataSource { constructor( - @IEditorService private _editorService: IEditorService + @ITextModelResolverService private _textModelResolverService: ITextModelResolverService ) { // } @@ -193,7 +193,7 @@ class DataSource implements tree.IDataSource { if (element instanceof ReferencesModel) { return TPromise.as(element.groups); } else if (element instanceof FileReferences) { - return element.resolve(this._editorService).then(val => { + return element.resolve(this._textModelResolverService).then(val => { if (element.failure) { // refresh the element on failure so that // we can update its rendering @@ -501,7 +501,7 @@ export class ReferenceWidget extends PeekViewWidget { constructor( editor: ICodeEditor, public layoutData: LayoutData, - private _editorService: IEditorService, + private _textModelResolverService: ITextModelResolverService, private _contextService: IWorkspaceContextService, private _instantiationService: IInstantiationService ) { @@ -716,7 +716,7 @@ export class ReferenceWidget extends PeekViewWidget { } return TPromise.join([ - this._editorService.resolveEditorModel({ resource: reference.uri }), + this._textModelResolverService.resolve(reference.uri), this._tree.reveal(reference) ]).then(values => { if (!this._model) { diff --git a/src/vs/editor/contrib/rename/browser/rename.ts b/src/vs/editor/contrib/rename/browser/rename.ts index 444f24f59bc..3ac12299540 100644 --- a/src/vs/editor/contrib/rename/browser/rename.ts +++ b/src/vs/editor/contrib/rename/browser/rename.ts @@ -10,7 +10,6 @@ import { isPromiseCanceledError } from 'vs/base/common/errors'; import { KeyMod, KeyCode } from 'vs/base/common/keyCodes'; import Severity from 'vs/base/common/severity'; import { TPromise } from 'vs/base/common/winjs.base'; -import { IEditorService } from 'vs/platform/editor/common/editor'; import { IEventService } from 'vs/platform/event/common/event'; import { RawContextKey, IContextKey, IContextKeyService, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { IMessageService } from 'vs/platform/message/common/message'; @@ -22,6 +21,7 @@ import { BulkEdit, createBulkEdit } from 'vs/editor/common/services/bulkEdit'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { rename } from '../common/rename'; import RenameInputField from './renameInputField'; +import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/resolver'; // --- register actions and commands @@ -43,7 +43,7 @@ class RenameController implements IEditorContribution { private editor: ICodeEditor, @IMessageService private _messageService: IMessageService, @IEventService private _eventService: IEventService, - @IEditorService private _editorService: IEditorService, + @ITextModelResolverService private _textModelResolverService: ITextModelResolverService, @IProgressService private _progressService: IProgressService, @IContextKeyService contextKeyService: IContextKeyService ) { @@ -132,7 +132,7 @@ class RenameController implements IEditorContribution { // start recording of file changes so that we can figure out if a file that // is to be renamed conflicts with another (concurrent) modification - let edit = createBulkEdit(this._eventService, this._editorService, this.editor); + let edit = createBulkEdit(this._eventService, this._textModelResolverService, this.editor); return rename(this.editor.getModel(), this.editor.getPosition(), newName).then(result => { if (result.rejectReason) { diff --git a/src/vs/platform/textmodelResolver/common/textModelResolverService.ts b/src/vs/platform/textmodelResolver/common/resolver.ts similarity index 100% rename from src/vs/platform/textmodelResolver/common/textModelResolverService.ts rename to src/vs/platform/textmodelResolver/common/resolver.ts diff --git a/src/vs/test/utils/servicesTestUtils.ts b/src/vs/test/utils/servicesTestUtils.ts index e5a59182b72..605b33ad900 100644 --- a/src/vs/test/utils/servicesTestUtils.ts +++ b/src/vs/test/utils/servicesTestUtils.ts @@ -23,7 +23,7 @@ import { IStorageService, StorageScope } from 'vs/platform/storage/common/storag import { IQuickOpenService } from 'vs/workbench/services/quickopen/common/quickOpenService'; import { IPartService } from 'vs/workbench/services/part/common/partService'; import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService'; -import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/textModelResolverService'; +import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/resolver'; import { IEditorInput, IEditorOptions, IEditorModel, Position, Direction, IEditor, IResourceInput, ITextEditorModel } from 'vs/platform/editor/common/editor'; import { IEventService } from 'vs/platform/event/common/event'; import { IUntitledEditorService, UntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService'; @@ -116,7 +116,7 @@ export class TestTextFileService extends TextFileService { @IUntitledEditorService untitledEditorService: IUntitledEditorService, @IInstantiationService instantiationService: IInstantiationService ) { - super(lifecycleService, contextService, configurationService, telemetryService, editorGroupService, editorService, fileService, untitledEditorService, instantiationService); + super(lifecycleService, contextService, configurationService, telemetryService, editorGroupService, fileService, untitledEditorService, instantiationService); } public setPromptPath(path: string): void { diff --git a/src/vs/workbench/api/node/mainThreadDocuments.ts b/src/vs/workbench/api/node/mainThreadDocuments.ts index 38f3a1eae8a..17f6e3f9f6c 100644 --- a/src/vs/workbench/api/node/mainThreadDocuments.ts +++ b/src/vs/workbench/api/node/mainThreadDocuments.ts @@ -20,7 +20,7 @@ import { IFileService } from 'vs/platform/files/common/files'; import { IModeService } from 'vs/editor/common/services/modeService'; import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService'; import { ExtHostContext, MainThreadDocumentsShape, ExtHostDocumentsShape } from './extHost.protocol'; -import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/textModelResolverService'; +import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/resolver'; export class MainThreadDocuments extends MainThreadDocumentsShape { private _modelService: IModelService; @@ -187,7 +187,7 @@ export class MainThreadDocuments extends MainThreadDocumentsShape { } private _handleAsResourceInput(uri: URI): TPromise { - return this._editorService.resolveEditorModel({ resource: uri }).then(model => { + return this._textModelResolverService.resolve(uri).then(model => { return !!model; }); } diff --git a/src/vs/workbench/api/node/mainThreadWorkspace.ts b/src/vs/workbench/api/node/mainThreadWorkspace.ts index e7ed8276620..ca48df3618e 100644 --- a/src/vs/workbench/api/node/mainThreadWorkspace.ts +++ b/src/vs/workbench/api/node/mainThreadWorkspace.ts @@ -15,6 +15,7 @@ import { bulkEdit, IResourceEdit } from 'vs/editor/common/services/bulkEdit'; import { TPromise } from 'vs/base/common/winjs.base'; import { Uri } from 'vscode'; import { MainThreadWorkspaceShape } from './extHost.protocol'; +import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/resolver'; export class MainThreadWorkspace extends MainThreadWorkspaceShape { @@ -23,6 +24,7 @@ export class MainThreadWorkspace extends MainThreadWorkspaceShape { private _workspace: IWorkspace; private _textFileService: ITextFileService; private _editorService: IWorkbenchEditorService; + private _textModelResolverService: ITextModelResolverService; private _eventService: IEventService; constructor( @@ -30,6 +32,7 @@ export class MainThreadWorkspace extends MainThreadWorkspaceShape { @IWorkspaceContextService contextService: IWorkspaceContextService, @ITextFileService textFileService, @IWorkbenchEditorService editorService, + @ITextModelResolverService textModelResolverService, @IEventService eventService ) { super(); @@ -39,6 +42,7 @@ export class MainThreadWorkspace extends MainThreadWorkspaceShape { this._textFileService = textFileService; this._editorService = editorService; this._eventService = eventService; + this._textModelResolverService = textModelResolverService; } $startSearch(include: string, exclude: string, maxResults: number, requestId: number): Thenable { @@ -95,7 +99,7 @@ export class MainThreadWorkspace extends MainThreadWorkspaceShape { } } - return bulkEdit(this._eventService, this._editorService, codeEditor, edits) + return bulkEdit(this._eventService, this._textModelResolverService, codeEditor, edits) .then(() => true); } } diff --git a/src/vs/workbench/common/editor/resourceEditorInput.ts b/src/vs/workbench/common/editor/resourceEditorInput.ts index 578cb5dcf27..0af33cf092b 100644 --- a/src/vs/workbench/common/editor/resourceEditorInput.ts +++ b/src/vs/workbench/common/editor/resourceEditorInput.ts @@ -7,7 +7,7 @@ import { TPromise } from 'vs/base/common/winjs.base'; import { EditorInput, ITextEditorModel } from 'vs/workbench/common/editor'; import URI from 'vs/base/common/uri'; -import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/textModelResolverService'; +import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/resolver'; import { ResourceEditorModel } from 'vs/workbench/common/editor/resourceEditorModel'; /** diff --git a/src/vs/workbench/electron-browser/workbench.ts b/src/vs/workbench/electron-browser/workbench.ts index 379c7d1e7c0..c72513feb3b 100644 --- a/src/vs/workbench/electron-browser/workbench.ts +++ b/src/vs/workbench/electron-browser/workbench.ts @@ -68,7 +68,7 @@ import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; import { TextFileService } from 'vs/workbench/services/textfile/electron-browser/textFileService'; import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService'; -import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/textModelResolverService'; +import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/resolver'; import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle'; import { IMessageService } from 'vs/platform/message/common/message'; diff --git a/src/vs/workbench/parts/contentprovider/common/contentprovider.contribution.ts b/src/vs/workbench/parts/contentprovider/common/contentprovider.contribution.ts index 77e6a7ecd0e..3f343a8741d 100644 --- a/src/vs/workbench/parts/contentprovider/common/contentprovider.contribution.ts +++ b/src/vs/workbench/parts/contentprovider/common/contentprovider.contribution.ts @@ -13,7 +13,7 @@ import JSONContributionRegistry = require('vs/platform/jsonschemas/common/jsonCo import { Registry } from 'vs/platform/platform'; import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions'; -import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/textModelResolverService'; +import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/resolver'; let schemaRegistry = Registry.as(JSONContributionRegistry.Extensions.JSONContribution); diff --git a/src/vs/workbench/parts/files/browser/saveErrorHandler.ts b/src/vs/workbench/parts/files/browser/saveErrorHandler.ts index 44f9079cfd1..50d18741538 100644 --- a/src/vs/workbench/parts/files/browser/saveErrorHandler.ts +++ b/src/vs/workbench/parts/files/browser/saveErrorHandler.ts @@ -29,7 +29,7 @@ import { IModelService } from 'vs/editor/common/services/modelService'; import { IDisposable, dispose } from 'vs/base/common/lifecycle'; import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textFileEditorModel'; -import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/textModelResolverService'; +import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/resolver'; // A handler for save error happening with conflict resolution actions export class SaveErrorHandler implements ISaveErrorHandler, IWorkbenchContribution { diff --git a/src/vs/workbench/parts/html/browser/html.contribution.ts b/src/vs/workbench/parts/html/browser/html.contribution.ts index 9bd1b592194..b4bc3c3113f 100644 --- a/src/vs/workbench/parts/html/browser/html.contribution.ts +++ b/src/vs/workbench/parts/html/browser/html.contribution.ts @@ -19,6 +19,7 @@ import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService'; import { isCommonCodeEditor, ICommonCodeEditor, IModel } from 'vs/editor/common/editorCommon'; import { HtmlZoneController } from './htmlEditorZone'; +import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/resolver'; // --- Register Editor (Registry.as(EditorExtensions.Editors)).registerEditor(new EditorDescriptor(HtmlPreviewPart.ID, @@ -59,7 +60,7 @@ CommandsRegistry.registerCommand('_workbench.htmlZone', function (accessor: Serv return; } - return accessor.get(IWorkbenchEditorService).resolveEditorModel({ resource: params.resource }).then(model => { + return accessor.get(ITextModelResolverService).resolve(params.resource).then(model => { const contents = (model.textEditorModel).getValue(); HtmlZoneController.getInstance(codeEditor).addZone(params.lineNumber, contents); }); diff --git a/src/vs/workbench/parts/html/browser/htmlPreviewPart.ts b/src/vs/workbench/parts/html/browser/htmlPreviewPart.ts index 545211aa7dd..ffea4d6a337 100644 --- a/src/vs/workbench/parts/html/browser/htmlPreviewPart.ts +++ b/src/vs/workbench/parts/html/browser/htmlPreviewPart.ts @@ -16,11 +16,11 @@ import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor'; import { Position } from 'vs/platform/editor/common/editor'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; -import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; import { BaseTextEditorModel } from 'vs/workbench/common/editor/textEditorModel'; import { HtmlInput } from 'vs/workbench/parts/html/common/htmlInput'; import { IThemeService } from 'vs/workbench/services/themes/common/themeService'; import { IOpenerService } from 'vs/platform/opener/common/opener'; +import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/resolver'; import Webview from './webview'; /** @@ -30,7 +30,7 @@ export class HtmlPreviewPart extends BaseEditor { static ID: string = 'workbench.editor.htmlPreviewPart'; - private _editorService: IWorkbenchEditorService; + private _textModelResolverService: ITextModelResolverService; private _themeService: IThemeService; private _openerService: IOpenerService; private _webview: Webview; @@ -45,14 +45,14 @@ export class HtmlPreviewPart extends BaseEditor { constructor( @ITelemetryService telemetryService: ITelemetryService, - @IWorkbenchEditorService editorService: IWorkbenchEditorService, + @ITextModelResolverService textModelResolverService: ITextModelResolverService, @IThemeService themeService: IThemeService, @IOpenerService openerService: IOpenerService, @IWorkspaceContextService contextService: IWorkspaceContextService ) { super(HtmlPreviewPart.ID, telemetryService); - this._editorService = editorService; + this._textModelResolverService = textModelResolverService; this._themeService = themeService; this._openerService = openerService; this._baseUrl = contextService.toResource('/'); @@ -150,7 +150,7 @@ export class HtmlPreviewPart extends BaseEditor { return super.setInput(input, options).then(() => { let resourceUri = (input).getResource(); - return this._editorService.resolveEditorModel({ resource: resourceUri }).then(model => { + return this._textModelResolverService.resolve(resourceUri).then(model => { if (model instanceof BaseTextEditorModel) { this._model = model.textEditorModel; } diff --git a/src/vs/workbench/parts/search/browser/replaceService.ts b/src/vs/workbench/parts/search/browser/replaceService.ts index af14b817175..98e6ecb583c 100644 --- a/src/vs/workbench/parts/search/browser/replaceService.ts +++ b/src/vs/workbench/parts/search/browser/replaceService.ts @@ -21,13 +21,18 @@ import { IProgressRunner } from 'vs/platform/progress/common/progress'; import { IDiffEditor } from 'vs/editor/browser/editorBrowser'; import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; +import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/resolver'; class EditorInputCache { private cache: Map.LinkedMap>; - constructor(private replaceService: ReplaceService, private editorService: IWorkbenchEditorService, - private modelService: IModelService) { + constructor( + private replaceService: ReplaceService, + private editorService: IWorkbenchEditorService, + private modelService: IModelService, + private textModelResolverService: ITextModelResolverService + ) { this.cache = new Map.LinkedMap>(); } @@ -52,7 +57,7 @@ class EditorInputCache { if (editorInputPromise) { editorInputPromise.done(() => { if (reloadFromSource) { - this.editorService.resolveEditorModel({ resource: fileMatch.resource() }).then(editorModel => { + this.textModelResolverService.resolve(fileMatch.resource()).then(editorModel => { if (editorModel.textEditorModel) { let replaceResource = this.getReplaceResource(fileMatch.resource()); this.modelService.getModel(replaceResource).setValue(editorModel.textEditorModel.getValue()); @@ -103,7 +108,7 @@ class EditorInputCache { private createRightInput(element: FileMatch): TPromise { return new TPromise((c, e, p) => { - this.editorService.resolveEditorModel({ resource: element.resource() }).then(value => { + this.textModelResolverService.resolve(element.resource()).then(value => { let model = value.textEditorModel; let replaceResource = this.getReplaceResource(element.resource()); this.modelService.createModel(model.getValue(), model.getMode(), replaceResource); @@ -128,8 +133,14 @@ export class ReplaceService implements IReplaceService { private cache: EditorInputCache; - constructor( @ITelemetryService private telemetryService: ITelemetryService, @IEventService private eventService: IEventService, @IEditorService private editorService, @IModelService private modelService: IModelService) { - this.cache = new EditorInputCache(this, editorService, modelService); + constructor( + @ITelemetryService private telemetryService: ITelemetryService, + @IEventService private eventService: IEventService, + @IEditorService private editorService, + @IModelService private modelService: IModelService, + @ITextModelResolverService private textModelResolverService: ITextModelResolverService + ) { + this.cache = new EditorInputCache(this, editorService, modelService, textModelResolverService); } public replace(match: Match): TPromise diff --git a/src/vs/workbench/services/textfile/browser/textFileService.ts b/src/vs/workbench/services/textfile/browser/textFileService.ts index d8195b636e8..d660d9594e4 100644 --- a/src/vs/workbench/services/textfile/browser/textFileService.ts +++ b/src/vs/workbench/services/textfile/browser/textFileService.ts @@ -19,11 +19,9 @@ import { IFileService, IResolveContentOptions, IFilesConfiguration, IFileOperati import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IDisposable, dispose } from 'vs/base/common/lifecycle'; -import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService'; import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService'; import { UntitledEditorModel } from 'vs/workbench/common/editor/untitledEditorModel'; -import { BinaryEditorModel } from 'vs/workbench/common/editor/binaryEditorModel'; import { TextFileEditorModelManager } from 'vs/workbench/services/textfile/common/textFileEditorModelManager'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; @@ -53,7 +51,6 @@ export abstract class TextFileService implements ITextFileService { @IConfigurationService private configurationService: IConfigurationService, @ITelemetryService private telemetryService: ITelemetryService, @IEditorGroupService private editorGroupService: IEditorGroupService, - @IWorkbenchEditorService private editorService: IWorkbenchEditorService, @IFileService protected fileService: IFileService, @IUntitledEditorService private untitledEditorService: IUntitledEditorService, @IInstantiationService private instantiationService: IInstantiationService @@ -441,21 +438,27 @@ export abstract class TextFileService implements ITextFileService { } private doSaveTextFileAs(sourceModel: ITextFileEditorModel | UntitledEditorModel, resource: URI, target: URI): TPromise { + // create the target file empty if it does not exist already return this.fileService.resolveFile(target).then(stat => stat, () => null).then(stat => stat || this.fileService.createFile(target)).then(stat => { - // resolve a model for the file (which can be binary if the file is not a text file) - return this.editorService.resolveEditorModel({ resource: target }).then((targetModel: ITextFileEditorModel) => { - // binary model: delete the file and run the operation again - if (targetModel instanceof BinaryEditorModel) { - return this.fileService.del(target).then(() => this.doSaveTextFileAs(sourceModel, resource, target)); - } - // text model: take over encoding and model value from source model + // resolve a model for the file (which can be binary if the file is not a text file) + return this.models.loadOrCreate(target).then((targetModel: ITextFileEditorModel) => { + + // take over encoding and model value from source model targetModel.updatePreferredEncoding(sourceModel.getEncoding()); targetModel.textEditorModel.setValue(sourceModel.getValue()); // save model return targetModel.save(); + }, error => { + + // binary model: delete the file and run the operation again + if ((error).fileOperationResult === FileOperationResult.FILE_IS_BINARY || (error).fileOperationResult === FileOperationResult.FILE_TOO_LARGE) { + return this.fileService.del(target).then(() => this.doSaveTextFileAs(sourceModel, resource, target)); + } + + return TPromise.wrapError(error); }); }); } diff --git a/src/vs/workbench/services/textfile/common/textFileEditorModelManager.ts b/src/vs/workbench/services/textfile/common/textFileEditorModelManager.ts index 605772ca838..1f4d3bd7af5 100644 --- a/src/vs/workbench/services/textfile/common/textFileEditorModelManager.ts +++ b/src/vs/workbench/services/textfile/common/textFileEditorModelManager.ts @@ -171,7 +171,7 @@ export class TextFileEditorModelManager implements ITextFileEditorModelManager { return this.mapResourceToModel[resource.toString()]; } - public loadOrCreate(resource: URI, encoding: string, refresh?: boolean): TPromise { + public loadOrCreate(resource: URI, encoding?: string, refresh?: boolean): TPromise { // Return early if model is currently being loaded const pendingLoad = this.mapResourceToPendingModelLoaders[resource.toString()]; diff --git a/src/vs/workbench/services/textfile/common/textfiles.ts b/src/vs/workbench/services/textfile/common/textfiles.ts index 52389b16b68..76f7a93fab9 100644 --- a/src/vs/workbench/services/textfile/common/textfiles.ts +++ b/src/vs/workbench/services/textfile/common/textfiles.ts @@ -192,7 +192,7 @@ export interface ITextFileEditorModelManager { getAll(resource?: URI): ITextFileEditorModel[]; - loadOrCreate(resource: URI, preferredEncoding: string, refresh?: boolean): TPromise; + loadOrCreate(resource: URI, preferredEncoding?: string, refresh?: boolean): TPromise; } export interface IModelSaveOptions { diff --git a/src/vs/workbench/services/textfile/electron-browser/textFileService.ts b/src/vs/workbench/services/textfile/electron-browser/textFileService.ts index 980c1bbd88a..e746c770d26 100644 --- a/src/vs/workbench/services/textfile/electron-browser/textFileService.ts +++ b/src/vs/workbench/services/textfile/electron-browser/textFileService.ts @@ -21,7 +21,6 @@ import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IModeService } from 'vs/editor/common/services/modeService'; -import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IWindowIPCService } from 'vs/workbench/services/window/electron-browser/windowService'; import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService'; import { IModelService } from 'vs/editor/common/services/modelService'; @@ -43,13 +42,12 @@ export class TextFileService extends AbstractTextFileService { @ITelemetryService telemetryService: ITelemetryService, @IConfigurationService configurationService: IConfigurationService, @IModeService private modeService: IModeService, - @IWorkbenchEditorService editorService: IWorkbenchEditorService, @IEditorGroupService editorGroupService: IEditorGroupService, @IWindowIPCService private windowService: IWindowIPCService, @IModelService private modelService: IModelService, @IEnvironmentService private environmentService: IEnvironmentService ) { - super(lifecycleService, contextService, configurationService, telemetryService, editorGroupService, editorService, fileService, untitledEditorService, instantiationService); + super(lifecycleService, contextService, configurationService, telemetryService, editorGroupService, fileService, untitledEditorService, instantiationService); } public resolveTextContent(resource: URI, options?: IResolveContentOptions): TPromise { diff --git a/src/vs/workbench/services/textmodelResolver/common/textModelResolverService.ts b/src/vs/workbench/services/textmodelResolver/common/textModelResolverService.ts index b825af0fc21..d66f6b57382 100644 --- a/src/vs/workbench/services/textmodelResolver/common/textModelResolverService.ts +++ b/src/vs/workbench/services/textmodelResolver/common/textModelResolverService.ts @@ -7,15 +7,22 @@ import { TPromise } from 'vs/base/common/winjs.base'; import URI from 'vs/base/common/uri'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; -import { IModel } from 'vs/editor/common/editorCommon'; -import { ITextEditorModel } from 'vs/platform/editor/common/editor'; +import { ICommonCodeEditor, IModel, EditorType, IEditor as ICommonEditor } from 'vs/editor/common/editorCommon'; +import { IDiffEditor, ICodeEditor } from 'vs/editor/browser/editorBrowser'; +import { ITextEditorModel, IEditorInput } from 'vs/platform/editor/common/editor'; import { IDisposable } from 'vs/base/common/lifecycle'; import { IModelService } from 'vs/editor/common/services/modelService'; import { sequence } from 'vs/base/common/async'; import { ResourceEditorModel } from 'vs/workbench/common/editor/resourceEditorModel'; import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; import network = require('vs/base/common/network'); -import { ITextModelResolverService, ITextModelContentProvider, IResolveOptions } from 'vs/platform/textmodelResolver/common/textModelResolverService'; +import { ITextModelResolverService, ITextModelContentProvider, IResolveOptions } from 'vs/platform/textmodelResolver/common/resolver'; +import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService'; +import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorInput'; +import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; +import types = require('vs/base/common/types'); +import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput'; +import { EditorInput } from 'vs/workbench/common/editor'; export class TextModelResolverService implements ITextModelResolverService { @@ -26,6 +33,8 @@ export class TextModelResolverService implements ITextModelResolverService { constructor( @ITextFileService private textFileService: ITextFileService, + @IUntitledEditorService private untitledEditorService: IUntitledEditorService, + @IWorkbenchEditorService private editorService: IWorkbenchEditorService, @IInstantiationService private instantiationService: IInstantiationService, @IModelService private modelService: IModelService ) { @@ -38,10 +47,77 @@ export class TextModelResolverService implements ITextModelResolverService { return this.textFileService.models.loadOrCreate(resource, options && options.encoding, false /* refresh */); } + // Untitled Schema: go through cached input + if (resource.scheme === UntitledEditorInput.SCHEMA) { + return this.untitledEditorService.createOrGet(resource).resolve(); + } + + // In Memory: only works on the active editor + if (resource.scheme === network.Schemas.inMemory) { + return this.resolveInMemory(resource); + } + // Any other resource: use registry return this.resolveTextModelContent(this.modelService, resource).then(() => this.instantiationService.createInstance(ResourceEditorModel, resource)); } + private resolveInMemory(resource: URI): TPromise { + + // For in-memory resources we only support to resolve the input from the current active editor + // because the workbench does not track editor models by in memory URL. This concept is only + // being used in the code editor. + const activeEditor = this.editorService.getActiveEditor(); + if (activeEditor) { + const control = activeEditor.getControl(); + if (types.isFunction(control.getEditorType)) { + + // Single Editor: If code editor model matches, return input from editor + if (control.getEditorType() === EditorType.ICodeEditor) { + const codeEditor = control; + const model = this.findModel(codeEditor, resource); + if (model) { + return this.resolveFromInput(activeEditor.input); + } + } + + // Diff Editor: If left or right code editor model matches, return associated input + else if (control.getEditorType() === EditorType.IDiffEditor) { + const diffInput = activeEditor.input; + const diffCodeEditor = control; + + const originalModel = this.findModel(diffCodeEditor.getOriginalEditor(), resource); + if (originalModel) { + return this.resolveFromInput(diffInput.originalInput); + } + + const modifiedModel = this.findModel(diffCodeEditor.getModifiedEditor(), resource); + if (modifiedModel) { + return this.resolveFromInput(diffInput.modifiedInput); + } + } + } + } + + return TPromise.as(null); + } + + private resolveFromInput(input: IEditorInput): TPromise { + if (input instanceof EditorInput) { + return input.resolve(); + } + + return TPromise.as(null); + } + + private findModel(editor: ICommonCodeEditor, resource: URI): IModel { + const model = editor.getModel(); + if (!model) { + return null; + } + + return model.uri.toString() === resource.toString() ? model : null; + } + public registerTextModelContentProvider(scheme: string, provider: ITextModelContentProvider): IDisposable { let array = this.contentProviderRegistry[scheme]; if (!array) { diff --git a/src/vs/workbench/services/textmodelResolver/test/textModelResolverService.test.ts b/src/vs/workbench/services/textmodelResolver/test/textModelResolverService.test.ts index c52823d53dc..4460c30d117 100644 --- a/src/vs/workbench/services/textmodelResolver/test/textModelResolverService.test.ts +++ b/src/vs/workbench/services/textmodelResolver/test/textModelResolverService.test.ts @@ -13,7 +13,7 @@ import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorIn import { ResourceEditorModel } from 'vs/workbench/common/editor/resourceEditorModel'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { workbenchInstantiationService } from 'vs/test/utils/servicesTestUtils'; -import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/textModelResolverService'; +import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/resolver'; import { IModelService } from 'vs/editor/common/services/modelService'; import { IModeService } from 'vs/editor/common/services/modeService';