提交 f8c96d72 编写于 作者: B Benjamin Pasero

untitled - clean up interfaces

上级 1a19cd4d
......@@ -610,13 +610,21 @@ export class EditorService extends Disposable implements EditorServiceImpl {
// Untitled file support
const untitledInput = input as IUntitledTextResourceInput;
if (untitledInput.forceUntitled || !untitledInput.resource || (untitledInput.resource && untitledInput.resource.scheme === Schemas.untitled)) {
return this.untitledTextEditorService.create({
untitledResource: untitledInput.resource?.scheme === Schemas.untitled ? untitledInput.resource : undefined,
associatedResource: untitledInput.resource?.scheme !== Schemas.untitled ? untitledInput.resource : undefined,
const untitledOptions = {
mode: untitledInput.mode,
initialValue: untitledInput.contents,
encoding: untitledInput.encoding
});
};
// Untitled resource: use as hint for an existing untitled editor
if (untitledInput.resource?.scheme === Schemas.untitled) {
return this.untitledTextEditorService.create({ untitledResource: untitledInput.resource, ...untitledOptions });
}
// Other resource: use as hint for associated filepath
else {
return this.untitledTextEditorService.create({ associatedResource: untitledInput.resource, ...untitledOptions });
}
}
// Resource Editor Support
......
......@@ -18,25 +18,7 @@ import { IResolvedTextEditorModel } from 'vs/editor/common/services/resolverServ
export const IUntitledTextEditorService = createDecorator<IUntitledTextEditorService>('untitledTextEditorService');
export interface IUntitledTextEditorOptions {
/**
* An optional resource to identify the untitled resource to create or return
* if already existing.
*
* Note: the resource will not be used unless the scheme is `untitled`.
*/
untitledResource?: URI;
/**
* Optional resource components to associate with the untitled file. When saving
* the untitled file, the associated components will be used and the user
* is not being asked to provide a file path.
*
* Note: currently it is not possible to specify the `scheme` to use. The
* untitled file will saved to the default local or remote resource.
*/
associatedResource?: { authority: string; path: string; query: string; fragment: string; }
export interface INewUntitledTextEditorOptions {
/**
* Initial value of the untitled file. An untitled file with initial
......@@ -55,6 +37,32 @@ export interface IUntitledTextEditorOptions {
encoding?: string;
}
export interface IExistingUntitledTextEditorOptions extends INewUntitledTextEditorOptions {
/**
* A resource to identify the untitled resource to create or return
* if already existing.
*
* Note: the resource will not be used unless the scheme is `untitled`.
*/
untitledResource?: URI;
}
export interface INewUntitledTextEditorWithAssociatedResourceOptions extends INewUntitledTextEditorOptions {
/**
* Resource components to associate with the untitled file. When saving
* the untitled file, the associated components will be used and the user
* is not being asked to provide a file path.
*
* Note: currently it is not possible to specify the `scheme` to use. The
* untitled file will saved to the default local or remote resource.
*/
associatedResource?: { authority: string; path: string; query: string; fragment: string; }
}
type IInternalUntitledTextEditorOptions = IExistingUntitledTextEditorOptions & INewUntitledTextEditorWithAssociatedResourceOptions;
export interface IUntitledTextEditorModelManager {
/**
......@@ -87,14 +95,18 @@ export interface IUntitledTextEditorModelManager {
* property is provided and the untitled input exists, it will return that existing
* instance instead of creating a new one.
*/
create(options?: IUntitledTextEditorOptions): UntitledTextEditorInput;
create(options?: INewUntitledTextEditorOptions): UntitledTextEditorInput;
create(options?: INewUntitledTextEditorWithAssociatedResourceOptions): UntitledTextEditorInput;
create(options?: IExistingUntitledTextEditorOptions): UntitledTextEditorInput;
/**
* Resolves an untitled editor model from the provided options. If the `untitledResource`
* property is provided and the untitled input exists, it will return that existing
* instance instead of creating a new one.
*/
resolve(options?: IUntitledTextEditorOptions): Promise<IUntitledTextEditorModel & IResolvedTextEditorModel>;
resolve(options?: INewUntitledTextEditorOptions): Promise<IUntitledTextEditorModel & IResolvedTextEditorModel>;
resolve(options?: INewUntitledTextEditorWithAssociatedResourceOptions): Promise<IUntitledTextEditorModel & IResolvedTextEditorModel>;
resolve(options?: IExistingUntitledTextEditorOptions): Promise<IUntitledTextEditorModel & IResolvedTextEditorModel>;
/**
* A check to find out if a untitled resource has a file path associated or not.
......@@ -138,15 +150,15 @@ export class UntitledTextEditorService extends Disposable implements IUntitledTe
return this.mapResourceToInput.get(resource);
}
resolve(options?: IUntitledTextEditorOptions): Promise<UntitledTextEditorModel & IResolvedTextEditorModel> {
resolve(options?: IInternalUntitledTextEditorOptions): Promise<UntitledTextEditorModel & IResolvedTextEditorModel> {
return this.doCreateOrGet(options).resolve();
}
create(options?: IUntitledTextEditorOptions): UntitledTextEditorInput {
create(options?: IInternalUntitledTextEditorOptions): UntitledTextEditorInput {
return this.doCreateOrGet(options);
}
private doCreateOrGet(options: IUntitledTextEditorOptions = Object.create(null)): UntitledTextEditorInput {
private doCreateOrGet(options: IInternalUntitledTextEditorOptions = Object.create(null)): UntitledTextEditorInput {
const massagedOptions = this.massageOptions(options);
// Return existing instance if asked for it
......@@ -158,8 +170,8 @@ export class UntitledTextEditorService extends Disposable implements IUntitledTe
return this.doCreate(massagedOptions);
}
private massageOptions(options: IUntitledTextEditorOptions): IUntitledTextEditorOptions {
const massagedOptions: IUntitledTextEditorOptions = Object.create(null);
private massageOptions(options: IInternalUntitledTextEditorOptions): IInternalUntitledTextEditorOptions {
const massagedOptions: IInternalUntitledTextEditorOptions = Object.create(null);
// Figure out associated and untitled resource
if (options.associatedResource) {
......@@ -194,7 +206,7 @@ export class UntitledTextEditorService extends Disposable implements IUntitledTe
return massagedOptions;
}
private doCreate(options: IUntitledTextEditorOptions): UntitledTextEditorInput {
private doCreate(options: IInternalUntitledTextEditorOptions): UntitledTextEditorInput {
// Create a new untitled resource if none is provided
let untitledResource = options.untitledResource;
......
......@@ -19,7 +19,7 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
class ServiceAccessor {
constructor(
@IUntitledTextEditorService public readonly untitledTextEditorService: UntitledTextEditorService,
@IUntitledTextEditorService public readonly untitledTextEditorService: IUntitledTextEditorService,
@IEditorService public readonly editorService: TestEditorService,
@IWorkingCopyService public readonly workingCopyService: IWorkingCopyService,
@IModeService public readonly modeService: ModeServiceImpl,
......@@ -38,7 +38,7 @@ suite('Workbench untitled text editors', () => {
});
teardown(() => {
accessor.untitledTextEditorService.dispose();
(accessor.untitledTextEditorService as UntitledTextEditorService).dispose();
});
test('Untitled Text Editor Service', async (done) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册