提交 4cc289a8 编写于 作者: B Benjamin Pasero

make text model resolver available in platform

上级 712147af
......@@ -6,6 +6,7 @@
import { Schemas } from 'vs/base/common/network';
import Severity from 'vs/base/common/severity';
import URI from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { IConfigurationService, IConfigurationServiceEvent, IConfigurationValue, getConfigurationValue, IConfigurationKeys } from 'vs/platform/configuration/common/configuration';
import { IEditor, IEditorInput, IEditorOptions, IEditorService, IResourceInput, ITextEditorModel, Position } from 'vs/platform/editor/common/editor';
......@@ -25,6 +26,8 @@ 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 { IDisposable } from 'vs/base/common/lifecycle';
export class SimpleEditor implements IEditor {
......@@ -176,6 +179,46 @@ export class SimpleEditorService implements IEditorService {
}
}
export class SimpleEditorModelResolverService implements ITextModelResolverService {
public _serviceBrand: any;
private editor: SimpleEditor;
public setEditor(editor: editorCommon.IEditor): void {
this.editor = new SimpleEditor(editor);
}
public resolve(resource: URI, options?: IResolveOptions): TPromise<ITextEditorModel> {
let model: editorCommon.IModel;
model = this.editor.withTypedEditor(
(editor) => this.findModel(editor, resource),
(diffEditor) => this.findModel(diffEditor.getOriginalEditor(), resource) || this.findModel(diffEditor.getModifiedEditor(), resource)
);
if (!model) {
return TPromise.as(null);
}
return TPromise.as(new SimpleModel(model));
}
public registerTextModelContentProvider(scheme: string, provider: ITextModelContentProvider): IDisposable {
return {
dispose: function () { /* no op */ }
};
}
private findModel(editor: editorCommon.ICommonCodeEditor, resource: URI): editorCommon.IModel {
let model = editor.getModel();
if (model.uri.toString() !== resource.toString()) {
return null;
}
return model;
}
}
export class SimpleProgressService implements IProgressService {
_serviceBrand: any;
......
......@@ -17,7 +17,7 @@ import { OpenerService } from 'vs/platform/opener/browser/openerService';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { IModel } from 'vs/editor/common/editorCommon';
import { Colorizer, IColorizerElementOptions, IColorizerOptions } from 'vs/editor/browser/standalone/colorizer';
import { SimpleEditorService } from 'vs/editor/browser/standalone/simpleServices';
import { SimpleEditorService, SimpleEditorModelResolverService } from 'vs/editor/browser/standalone/simpleServices';
import * as modes from 'vs/editor/common/modes';
import { IWebWorkerOptions, MonacoWebWorker, createWebWorker as actualCreateWebWorker } from 'vs/editor/common/services/webWorker';
import { IMarkerData } from 'vs/platform/markers/common/markers';
......@@ -30,6 +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';
/**
* @internal
......@@ -48,6 +49,12 @@ function withAllStandaloneServices<T extends editorCommon.IEditor>(domElement: H
services.set(IEditorService, simpleEditorService);
}
let simpleEditorModelResolverService: SimpleEditorModelResolverService = null;
if (!services.has(ITextModelResolverService)) {
simpleEditorModelResolverService = new SimpleEditorModelResolverService();
services.set(ITextModelResolverService, simpleEditorModelResolverService);
}
if (!services.has(IOpenerService)) {
services.set(IOpenerService, new OpenerService(services.get(IEditorService), services.get(ICommandService)));
}
......@@ -58,6 +65,10 @@ function withAllStandaloneServices<T extends editorCommon.IEditor>(domElement: H
simpleEditorService.setEditor(result);
}
if (simpleEditorModelResolverService) {
simpleEditorModelResolverService.setEditor(result);
}
return result;
}
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { TPromise } from 'vs/base/common/winjs.base';
import URI from 'vs/base/common/uri';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IModel } from 'vs/editor/common/editorCommon';
import { ITextEditorModel } from 'vs/platform/editor/common/editor';
import { IDisposable } from 'vs/base/common/lifecycle';
export const ITextModelResolverService = createDecorator<ITextModelResolverService>('textModelResolverService');
export interface IResolveOptions {
encoding?: string;
}
export interface ITextModelResolverService {
_serviceBrand: any;
resolve(resource: URI, options?: IResolveOptions): TPromise<ITextEditorModel>;
registerTextModelContentProvider(scheme: string, provider: ITextModelContentProvider): IDisposable;
}
export interface ITextModelContentProvider {
provideTextContent(resource: URI): TPromise<IModel>;
}
\ No newline at end of file
......@@ -22,7 +22,8 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { IQuickOpenService } from 'vs/workbench/services/quickopen/common/quickOpenService';
import { IPartService } from 'vs/workbench/services/part/common/partService';
import { ITextModelResolverService, TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService';
import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService';
import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/textModelResolverService';
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';
......
......@@ -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/workbench/services/textmodelResolver/common/textModelResolverService';
import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/textModelResolverService';
export class MainThreadDocuments extends MainThreadDocumentsShape {
private _modelService: IModelService;
......
......@@ -205,7 +205,7 @@ export abstract class EditorInput implements IEditorInput {
* if the EditorModel should be refreshed before returning it. Depending on the implementation
* this could mean to refresh the editor model contents with the version from disk.
*/
public abstract resolve(refresh?: boolean): TPromise<EditorModel>;
public abstract resolve(refresh?: boolean): TPromise<IEditorModel>;
/**
* An editor that is dirty will be asked to be saved once it closes.
......
......@@ -5,10 +5,10 @@
'use strict';
import { TPromise } from 'vs/base/common/winjs.base';
import { EditorModel, EditorInput } from 'vs/workbench/common/editor';
import { ResourceEditorModel } from 'vs/workbench/common/editor/resourceEditorModel';
import { EditorInput, ITextEditorModel } from 'vs/workbench/common/editor';
import URI from 'vs/base/common/uri';
import { ITextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService';
import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/textModelResolverService';
import { ResourceEditorModel } from 'vs/workbench/common/editor/resourceEditorModel';
/**
* A read-only text editor input whos contents are made of the provided resource that points to an existing
......@@ -63,15 +63,19 @@ export class ResourceEditorInput extends EditorInput {
}
}
public resolve(refresh?: boolean): TPromise<EditorModel> {
public resolve(refresh?: boolean): TPromise<ITextEditorModel> {
// Use Cached Model
if (this.cachedModel) {
return TPromise.as<EditorModel>(this.cachedModel);
return TPromise.as<ITextEditorModel>(this.cachedModel);
}
// Otherwise Create Model and handle dispose event
return this.textModelResolverService.resolve(this.resource).then((model: ResourceEditorModel) => {
return this.textModelResolverService.resolve(this.resource).then(model => {
if (!(model instanceof ResourceEditorModel)) {
return TPromise.wrapError(`Unexpected model for ResourceInput: ${this.resource}`); // TODO@Ben eventually also files should be supported, but we guard due to the dangerous dispose of the model in dispose()
}
this.cachedModel = model;
const unbind = model.onDispose(() => {
......
......@@ -67,7 +67,8 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
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 { ITextModelResolverService, TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService';
import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService';
import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/textModelResolverService';
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/workbench/services/textmodelResolver/common/textModelResolverService';
import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/textModelResolverService';
let schemaRegistry = <JSONContributionRegistry.IJSONContributionRegistry>Registry.as(JSONContributionRegistry.Extensions.JSONContribution);
......
......@@ -12,7 +12,7 @@ import paths = require('vs/base/common/paths');
import { Action } from 'vs/base/common/actions';
import URI from 'vs/base/common/uri';
import product from 'vs/platform/product';
import { EditorModel } from 'vs/workbench/common/editor';
import { ITextEditorModel } from 'vs/workbench/common/editor';
import { EditorInputAction } from 'vs/workbench/browser/parts/editor/baseEditor';
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
......@@ -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/workbench/services/textmodelResolver/common/textModelResolverService';
import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/textModelResolverService';
// A handler for save error happening with conflict resolution actions
export class SaveErrorHandler implements ISaveErrorHandler, IWorkbenchContribution {
......@@ -198,7 +198,7 @@ export class FileOnDiskEditorInput extends ResourceEditorInput {
return this.lastModified;
}
public resolve(refresh?: boolean): TPromise<EditorModel> {
public resolve(refresh?: boolean): TPromise<ITextEditorModel> {
// Make sure our file from disk is resolved up to date
return this.textFileService.resolveTextContent(this.fileResource).then(content => {
......
......@@ -6,28 +6,16 @@
import { TPromise } from 'vs/base/common/winjs.base';
import URI from 'vs/base/common/uri';
import { createDecorator, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IModel } from 'vs/editor/common/editorCommon';
import { ITextEditorModel } 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';
export const ITextModelResolverService = createDecorator<ITextModelResolverService>('textModelResolverService');
export interface ITextModelResolverService {
_serviceBrand: any;
resolve(resource: URI): TPromise<ITextEditorModel>;
registerTextModelContentProvider(scheme: string, provider: ITextModelContentProvider): IDisposable;
}
export interface ITextModelContentProvider {
provideTextContent(resource: URI): TPromise<IModel>;
}
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';
export class TextModelResolverService implements ITextModelResolverService {
......@@ -37,12 +25,20 @@ export class TextModelResolverService implements ITextModelResolverService {
private contentProviderRegistry: { [scheme: string]: ITextModelContentProvider[] } = Object.create(null);
constructor(
@ITextFileService private textFileService: ITextFileService,
@IInstantiationService private instantiationService: IInstantiationService,
@IModelService private modelService: IModelService
) {
}
public resolve(resource: URI): TPromise<ITextEditorModel> {
public resolve(resource: URI, options?: IResolveOptions): TPromise<ITextEditorModel> {
// File Schema: use text file service
if (resource.scheme === network.Schemas.file) {
return this.textFileService.models.loadOrCreate(resource, options && options.encoding, false /* refresh */);
}
// Any other resource: use registry
return this.resolveTextModelContent(this.modelService, resource).then(() => this.instantiationService.createInstance(ResourceEditorModel, resource));
}
......
......@@ -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/workbench/services/textmodelResolver/common/textModelResolverService';
import { ITextModelResolverService } from 'vs/platform/textmodelResolver/common/textModelResolverService';
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.
先完成此消息的编辑!
想要评论请 注册