mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 03:29:00 +01:00
Add ability to open untitled document with initial content (#22021)
This commit is contained in:
committed by
Benjamin Pasero
parent
1dd884a88a
commit
503f8f516e
@@ -368,10 +368,10 @@ export function createApiFactory(initData: IInitData, threadService: IThreadServ
|
||||
set textDocuments(value) {
|
||||
throw errors.readonly();
|
||||
},
|
||||
openTextDocument(uriOrFileNameOrOptions?: vscode.Uri | string | { language: string; }) {
|
||||
openTextDocument(uriOrFileNameOrOptions?: vscode.Uri | string | { language?: string; contents?: string; }) {
|
||||
let uriPromise: TPromise<URI>;
|
||||
|
||||
let options = uriOrFileNameOrOptions as { language: string; };
|
||||
let options = uriOrFileNameOrOptions as { language?: string; contents?: string; };
|
||||
if (!options || typeof options.language === 'string') {
|
||||
uriPromise = extHostDocuments.createDocumentData(options);
|
||||
} else if (typeof uriOrFileNameOrOptions === 'string') {
|
||||
|
||||
@@ -120,7 +120,7 @@ export abstract class MainThreadDiagnosticsShape {
|
||||
}
|
||||
|
||||
export abstract class MainThreadDocumentsShape {
|
||||
$tryCreateDocument(options?: { language: string; }): TPromise<any> { throw ni(); }
|
||||
$tryCreateDocument(options?: { language?: string; contents?: string; }): TPromise<any> { throw ni(); }
|
||||
$tryOpenDocument(uri: URI): TPromise<any> { throw ni(); }
|
||||
$registerTextContentProvider(handle: number, scheme: string): void { throw ni(); }
|
||||
$onVirtualDocumentChange(uri: URI, value: ITextSource): void { throw ni(); }
|
||||
|
||||
@@ -101,7 +101,7 @@ export class ExtHostDocuments extends ExtHostDocumentsShape {
|
||||
return promise;
|
||||
}
|
||||
|
||||
public createDocumentData(options?: { language: string; }): TPromise<URI> {
|
||||
public createDocumentData(options?: { language?: string; contents?: string }): TPromise<URI> {
|
||||
return this._proxy.$tryCreateDocument(options);
|
||||
}
|
||||
|
||||
|
||||
@@ -228,8 +228,8 @@ export class MainThreadDocuments extends MainThreadDocumentsShape {
|
||||
});
|
||||
}
|
||||
|
||||
$tryCreateDocument(options?: { language: string }): TPromise<URI> {
|
||||
return this._doCreateUntitled(void 0, options ? options.language : void 0);
|
||||
$tryCreateDocument(options?: { language?: string, contents?: string }): TPromise<URI> {
|
||||
return this._doCreateUntitled(void 0, options ? options.language : void 0, options ? options.contents : void 0);
|
||||
}
|
||||
|
||||
private _handleAsResourceInput(uri: URI): TPromise<boolean> {
|
||||
@@ -252,8 +252,8 @@ export class MainThreadDocuments extends MainThreadDocumentsShape {
|
||||
}, err => this._doCreateUntitled(asFileUri).then(resource => !!resource));
|
||||
}
|
||||
|
||||
private _doCreateUntitled(uri?: URI, modeId?: string): TPromise<URI> {
|
||||
let input = this._untitledEditorService.createOrGet(uri, modeId);
|
||||
private _doCreateUntitled(uri?: URI, modeId?: string, initialValue?: string): TPromise<URI> {
|
||||
let input = this._untitledEditorService.createOrGet(uri, modeId, initialValue);
|
||||
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`);
|
||||
|
||||
Reference in New Issue
Block a user