提交 1741f67d 编写于 作者: B Benjamin Pasero

adopt ITextModelResolverService for resources

上级 4cc289a8
......@@ -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 {
......
......@@ -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
......
......@@ -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<IResourceEdit[]> = 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<ISelection>;
}
export function bulkEdit(eventService: IEventService, editorService: IEditorService, editor: ICommonCodeEditor, edits: IResourceEdit[], progress: IProgressRunner = null): TPromise<any> {
let bulk = createBulkEdit(eventService, editorService, editor);
export function bulkEdit(eventService: IEventService, textModelResolverService: ITextModelResolverService, editor: ICommonCodeEditor, edits: IResourceEdit[], progress: IProgressRunner = null): TPromise<any> {
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(_ => {
......
......@@ -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 = <editorCommon.IModel>model.textEditorModel;
......
......@@ -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<boolean>('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 = <LayoutData>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(() => {
......
......@@ -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<FileReferences> {
public resolve(textModelResolverService: ITextModelResolverService): TPromise<FileReferences> {
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();
}
......
......@@ -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) {
......
......@@ -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, <ICodeEditor>this.editor);
let edit = createBulkEdit(this._eventService, this._textModelResolverService, <ICodeEditor>this.editor);
return rename(this.editor.getModel(), this.editor.getPosition(), newName).then(result => {
if (result.rejectReason) {
......
......@@ -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 {
......
......@@ -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<boolean> {
return this._editorService.resolveEditorModel({ resource: uri }).then(model => {
return this._textModelResolverService.resolve(uri).then(model => {
return !!model;
});
}
......
......@@ -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<Uri[]> {
......@@ -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);
}
}
......@@ -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';
/**
......
......@@ -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';
......
......@@ -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 = <JSONContributionRegistry.IJSONContributionRegistry>Registry.as(JSONContributionRegistry.Extensions.JSONContribution);
......
......@@ -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 {
......
......@@ -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
(<IEditorRegistry>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 = (<IModel>model.textEditorModel).getValue();
HtmlZoneController.getInstance(codeEditor).addZone(params.lineNumber, contents);
});
......
......@@ -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 = (<HtmlInput>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;
}
......
......@@ -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<URI, TPromise<DiffEditorInput>>;
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<URI, TPromise<DiffEditorInput>>();
}
......@@ -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<IEditorInput> {
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<any>
......
......@@ -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<void> {
// 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));
}
return this.models.loadOrCreate(target).then((targetModel: ITextFileEditorModel) => {
// text model: take over encoding and model value from source model
// 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 ((<IFileOperationResult>error).fileOperationResult === FileOperationResult.FILE_IS_BINARY || (<IFileOperationResult>error).fileOperationResult === FileOperationResult.FILE_TOO_LARGE) {
return this.fileService.del(target).then(() => this.doSaveTextFileAs(sourceModel, resource, target));
}
return TPromise.wrapError(error);
});
});
}
......
......@@ -171,7 +171,7 @@ export class TextFileEditorModelManager implements ITextFileEditorModelManager {
return this.mapResourceToModel[resource.toString()];
}
public loadOrCreate(resource: URI, encoding: string, refresh?: boolean): TPromise<ITextFileEditorModel> {
public loadOrCreate(resource: URI, encoding?: string, refresh?: boolean): TPromise<ITextFileEditorModel> {
// Return early if model is currently being loaded
const pendingLoad = this.mapResourceToPendingModelLoaders[resource.toString()];
......
......@@ -192,7 +192,7 @@ export interface ITextFileEditorModelManager {
getAll(resource?: URI): ITextFileEditorModel[];
loadOrCreate(resource: URI, preferredEncoding: string, refresh?: boolean): TPromise<ITextEditorModel>;
loadOrCreate(resource: URI, preferredEncoding?: string, refresh?: boolean): TPromise<ITextEditorModel>;
}
export interface IModelSaveOptions {
......
......@@ -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<IRawTextContent> {
......
......@@ -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<ITextEditorModel> {
// 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 = <ICommonEditor>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 = <ICodeEditor>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 = <DiffEditorInput>activeEditor.input;
const diffCodeEditor = <IDiffEditor>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<ITextEditorModel> {
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) {
......
......@@ -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';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册