Open new file buffer via API

This commit is contained in:
Benjamin Pasero
2017-01-18 19:13:26 +01:00
parent dbef8f1afe
commit 8b7756063b
6 changed files with 61 additions and 23 deletions

View File

@@ -178,6 +178,10 @@ export class MainThreadDocuments extends MainThreadDocumentsShape {
});
}
$tryCreateDocument(options?: { language: string }): TPromise<URI> {
return this._doCreateUntitled(void 0, options ? options.language : void 0);
}
private _handleAsResourceInput(uri: URI): TPromise<boolean> {
return this._textModelResolverService.createModelReference(uri).then(ref => {
const result = !!ref.object;
@@ -194,19 +198,18 @@ export class MainThreadDocuments extends MainThreadDocumentsShape {
return this._fileService.resolveFile(asFileUri).then(stats => {
// don't create a new file ontop of an existing file
return TPromise.wrapError<boolean>('file already exists on disk');
}, err => {
let input = this._untitledEditorService.createOrGet(asFileUri);
return input.resolve(true).then(model => {
if (input.getResource().toString() !== uri.toString()) {
throw new Error(`expected URI ${uri.toString()} BUT GOT ${input.getResource().toString()}`);
}
if (!this._modelIsSynced[uri.toString()]) {
throw new Error(`expected URI ${uri.toString()} to have come to LIFE`);
}
return this._proxy.$acceptModelDirty(uri.toString()); // mark as dirty
}).then(() => {
return true;
});
}, err => this._doCreateUntitled(asFileUri).then(resource => !!resource));
}
private _doCreateUntitled(uri?: URI, modeId?: string): TPromise<URI> {
let input = this._untitledEditorService.createOrGet(uri, modeId);
return input.resolve(true).then(model => {
if (!this._modelIsSynced[input.getResource().toString()]) {
throw new Error(`expected URI ${input.getResource().toString()} to have come to LIFE`);
}
return this._proxy.$acceptModelDirty(input.getResource().toString()); // mark as dirty
}).then(() => {
return input.getResource();
});
}