mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-27 09:35:37 -05:00
Merge VS Code 1.31.1 (#4283)
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { first } from 'vs/base/common/async';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
@@ -18,20 +17,20 @@ import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/un
|
||||
import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textFileEditorModel';
|
||||
import { IFileService } from 'vs/platform/files/common/files';
|
||||
|
||||
class ResourceModelCollection extends ReferenceCollection<TPromise<ITextEditorModel>> {
|
||||
class ResourceModelCollection extends ReferenceCollection<Promise<ITextEditorModel>> {
|
||||
|
||||
private providers: { [scheme: string]: ITextModelContentProvider[] } = Object.create(null);
|
||||
private modelsToDispose = new Set<string>();
|
||||
|
||||
constructor(
|
||||
@IInstantiationService private instantiationService: IInstantiationService,
|
||||
@ITextFileService private textFileService: ITextFileService,
|
||||
@IFileService private fileService: IFileService
|
||||
@IInstantiationService private readonly instantiationService: IInstantiationService,
|
||||
@ITextFileService private readonly textFileService: ITextFileService,
|
||||
@IFileService private readonly fileService: IFileService
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
createReferencedObject(key: string, skipActivateProvider?: boolean): TPromise<ITextEditorModel> {
|
||||
createReferencedObject(key: string, skipActivateProvider?: boolean): Promise<ITextEditorModel> {
|
||||
this.modelsToDispose.delete(key);
|
||||
|
||||
const resource = URI.parse(key);
|
||||
@@ -51,10 +50,10 @@ class ResourceModelCollection extends ReferenceCollection<TPromise<ITextEditorMo
|
||||
return this.fileService.activateProvider(resource.scheme).then(() => this.createReferencedObject(key, true));
|
||||
}
|
||||
|
||||
return TPromise.wrapError<ITextEditorModel>(new Error('resource is not available'));
|
||||
return Promise.reject(new Error('resource is not available'));
|
||||
}
|
||||
|
||||
destroyReferencedObject(key: string, modelPromise: TPromise<ITextEditorModel>): void {
|
||||
destroyReferencedObject(key: string, modelPromise: Promise<ITextEditorModel>): void {
|
||||
this.modelsToDispose.add(key);
|
||||
|
||||
modelPromise.then(model => {
|
||||
@@ -97,14 +96,18 @@ class ResourceModelCollection extends ReferenceCollection<TPromise<ITextEditorMo
|
||||
});
|
||||
}
|
||||
|
||||
private resolveTextModelContent(key: string): TPromise<ITextModel> {
|
||||
hasTextModelContentProvider(scheme: string): boolean {
|
||||
return this.providers[scheme] !== undefined;
|
||||
}
|
||||
|
||||
private resolveTextModelContent(key: string): Promise<ITextModel> {
|
||||
const resource = URI.parse(key);
|
||||
const providers = this.providers[resource.scheme] || [];
|
||||
const factories = providers.map(p => () => TPromise.wrap(p.provideTextContent(resource)));
|
||||
const factories = providers.map(p => () => Promise.resolve(p.provideTextContent(resource)));
|
||||
|
||||
return first(factories).then(model => {
|
||||
if (!model) {
|
||||
return TPromise.wrapError<ITextModel>(new Error('resource is not available'));
|
||||
return Promise.reject(new Error('resource is not available'));
|
||||
}
|
||||
|
||||
return model;
|
||||
@@ -119,18 +122,18 @@ export class TextModelResolverService implements ITextModelService {
|
||||
private resourceModelCollection: ResourceModelCollection;
|
||||
|
||||
constructor(
|
||||
@IUntitledEditorService private untitledEditorService: IUntitledEditorService,
|
||||
@IInstantiationService private instantiationService: IInstantiationService,
|
||||
@IModelService private modelService: IModelService
|
||||
@IUntitledEditorService private readonly untitledEditorService: IUntitledEditorService,
|
||||
@IInstantiationService private readonly instantiationService: IInstantiationService,
|
||||
@IModelService private readonly modelService: IModelService
|
||||
) {
|
||||
this.resourceModelCollection = instantiationService.createInstance(ResourceModelCollection);
|
||||
}
|
||||
|
||||
createModelReference(resource: URI): TPromise<IReference<ITextEditorModel>> {
|
||||
createModelReference(resource: URI): Promise<IReference<ITextEditorModel>> {
|
||||
return this._createModelReference(resource);
|
||||
}
|
||||
|
||||
private _createModelReference(resource: URI): TPromise<IReference<ITextEditorModel>> {
|
||||
private _createModelReference(resource: URI): Promise<IReference<ITextEditorModel>> {
|
||||
|
||||
// Untitled Schema: go through cached input
|
||||
if (resource.scheme === network.Schemas.untitled) {
|
||||
@@ -142,10 +145,10 @@ export class TextModelResolverService implements ITextModelService {
|
||||
const cachedModel = this.modelService.getModel(resource);
|
||||
|
||||
if (!cachedModel) {
|
||||
return TPromise.wrapError<IReference<ITextEditorModel>>(new Error('Cant resolve inmemory resource'));
|
||||
return Promise.reject(new Error('Cant resolve inmemory resource'));
|
||||
}
|
||||
|
||||
return TPromise.as(new ImmortalReference(this.instantiationService.createInstance(ResourceEditorModel, resource)));
|
||||
return Promise.resolve(new ImmortalReference(this.instantiationService.createInstance(ResourceEditorModel, resource)));
|
||||
}
|
||||
|
||||
const ref = this.resourceModelCollection.acquire(resource.toString());
|
||||
@@ -155,7 +158,7 @@ export class TextModelResolverService implements ITextModelService {
|
||||
err => {
|
||||
ref.dispose();
|
||||
|
||||
return TPromise.wrapError<IReference<ITextEditorModel>>(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -163,4 +166,8 @@ export class TextModelResolverService implements ITextModelService {
|
||||
registerTextModelContentProvider(scheme: string, provider: ITextModelContentProvider): IDisposable {
|
||||
return this.resourceModelCollection.registerTextModelContentProvider(scheme, provider);
|
||||
}
|
||||
|
||||
hasTextModelContentProvider(scheme: string): boolean {
|
||||
return this.resourceModelCollection.hasTextModelContentProvider(scheme);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,9 @@ import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textF
|
||||
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
|
||||
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
|
||||
import { TextFileEditorModelManager } from 'vs/workbench/services/textfile/common/textFileEditorModelManager';
|
||||
import { once } from 'vs/base/common/event';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { snapshotToString } from 'vs/platform/files/common/files';
|
||||
import { timeout } from 'vs/base/common/async';
|
||||
|
||||
class ServiceAccessor {
|
||||
constructor(
|
||||
@@ -46,7 +47,7 @@ suite('Workbench - TextModelResolverService', () => {
|
||||
teardown(() => {
|
||||
if (model) {
|
||||
model.dispose();
|
||||
model = void 0;
|
||||
model = (undefined)!;
|
||||
}
|
||||
(<TextFileEditorModelManager>accessor.textFileService.models).clear();
|
||||
(<TextFileEditorModelManager>accessor.textFileService.models).dispose();
|
||||
@@ -55,18 +56,18 @@ suite('Workbench - TextModelResolverService', () => {
|
||||
|
||||
test('resolve resource', function () {
|
||||
const dispose = accessor.textModelResolverService.registerTextModelContentProvider('test', {
|
||||
provideTextContent: function (resource: URI): Thenable<ITextModel> {
|
||||
provideTextContent: function (resource: URI): Promise<ITextModel> {
|
||||
if (resource.scheme === 'test') {
|
||||
let modelContent = 'Hello Test';
|
||||
let languageSelection = accessor.modeService.create('json');
|
||||
return Promise.resolve(accessor.modelService.createModel(modelContent, languageSelection, resource));
|
||||
}
|
||||
|
||||
return Promise.resolve(null);
|
||||
return Promise.resolve(null!);
|
||||
}
|
||||
});
|
||||
|
||||
let resource = URI.from({ scheme: 'test', authority: null, path: 'thePath' });
|
||||
let resource = URI.from({ scheme: 'test', authority: null!, path: 'thePath' });
|
||||
let input: ResourceEditorInput = instantiationService.createInstance(ResourceEditorInput, 'The Name', 'The Description', resource);
|
||||
|
||||
return input.resolve().then(async model => {
|
||||
@@ -75,7 +76,7 @@ suite('Workbench - TextModelResolverService', () => {
|
||||
|
||||
let disposed = false;
|
||||
let disposedPromise = new Promise(resolve => {
|
||||
once(model.onDispose)(() => {
|
||||
Event.once(model.onDispose)(() => {
|
||||
disposed = true;
|
||||
resolve();
|
||||
});
|
||||
@@ -101,12 +102,14 @@ suite('Workbench - TextModelResolverService', () => {
|
||||
assert.equal(editorModel.getValue(), 'Hello Html');
|
||||
|
||||
let disposed = false;
|
||||
once(model.onDispose)(() => {
|
||||
Event.once(model.onDispose)(() => {
|
||||
disposed = true;
|
||||
});
|
||||
|
||||
ref.dispose();
|
||||
assert.equal(disposed, true);
|
||||
return timeout(0).then(() => { // due to the reference resolving the model first which is async
|
||||
assert.equal(disposed, true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -129,11 +132,11 @@ suite('Workbench - TextModelResolverService', () => {
|
||||
});
|
||||
|
||||
test('even loading documents should be refcounted', async () => {
|
||||
let resolveModel: Function;
|
||||
let resolveModel!: Function;
|
||||
let waitForIt = new Promise(c => resolveModel = c);
|
||||
|
||||
const disposable = accessor.textModelResolverService.registerTextModelContentProvider('test', {
|
||||
provideTextContent: (resource: URI): Thenable<ITextModel> => {
|
||||
provideTextContent: (resource: URI): Promise<ITextModel> => {
|
||||
return waitForIt.then(_ => {
|
||||
let modelContent = 'Hello Test';
|
||||
let languageSelection = accessor.modeService.create('json');
|
||||
@@ -142,7 +145,7 @@ suite('Workbench - TextModelResolverService', () => {
|
||||
}
|
||||
});
|
||||
|
||||
const uri = URI.from({ scheme: 'test', authority: null, path: 'thePath' });
|
||||
const uri = URI.from({ scheme: 'test', authority: null!, path: 'thePath' });
|
||||
|
||||
const modelRefPromise1 = accessor.textModelResolverService.createModelReference(uri);
|
||||
const modelRefPromise2 = accessor.textModelResolverService.createModelReference(uri);
|
||||
|
||||
Reference in New Issue
Block a user