mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 18:49:00 +01:00
Open new file buffer via API
This commit is contained in:
@@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user