mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Merge from vscode 708b019bb4e20f07cf89df9f1d943af3d38d7a70 (#9657)
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { CancelablePromise, createCancelablePromise } from 'vs/base/common/async';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { Emitter, Event } from 'vs/base/common/event';
|
||||
import { Disposable, DisposableStore, dispose, IDisposable, IReference } from 'vs/base/common/lifecycle';
|
||||
@@ -305,16 +306,20 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma
|
||||
canResolve: (webviewInput) => {
|
||||
return webviewInput instanceof CustomEditorInput && webviewInput.viewType === viewType;
|
||||
},
|
||||
resolveWebview: async (webviewInput: CustomEditorInput) => {
|
||||
resolveWebview: async (webviewInput: CustomEditorInput, cancellation: CancellationToken) => {
|
||||
const handle = webviewInput.id;
|
||||
this._webviewInputs.add(handle, webviewInput);
|
||||
const resource = webviewInput.resource;
|
||||
|
||||
this._webviewInputs.add(handle, webviewInput);
|
||||
this.hookupWebviewEventDelegate(handle, webviewInput);
|
||||
webviewInput.webview.options = options;
|
||||
webviewInput.webview.extension = extension;
|
||||
|
||||
const resource = webviewInput.resource;
|
||||
let modelRef = await this.getOrCreateCustomEditorModel(modelType, resource, viewType);
|
||||
let modelRef = await this.getOrCreateCustomEditorModel(modelType, resource, viewType, cancellation);
|
||||
if (cancellation.isCancellationRequested) {
|
||||
modelRef.dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
webviewInput.webview.onDispose(() => {
|
||||
modelRef.dispose();
|
||||
@@ -323,14 +328,14 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma
|
||||
if (capabilities.supportsMove) {
|
||||
webviewInput.onMove(async (newResource: URI) => {
|
||||
const oldModel = modelRef;
|
||||
modelRef = await this.getOrCreateCustomEditorModel(modelType, newResource, viewType);
|
||||
modelRef = await this.getOrCreateCustomEditorModel(modelType, newResource, viewType, CancellationToken.None);
|
||||
this._proxy.$onMoveCustomEditor(handle, newResource, viewType);
|
||||
oldModel.dispose();
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
await this._proxy.$resolveWebviewEditor(resource, handle, viewType, webviewInput.getTitle(), editorGroupToViewColumn(this._editorGroupService, webviewInput.group || 0), webviewInput.webview.options);
|
||||
await this._proxy.$resolveWebviewEditor(resource, handle, viewType, webviewInput.getTitle(), editorGroupToViewColumn(this._editorGroupService, webviewInput.group || 0), webviewInput.webview.options, cancellation);
|
||||
} catch (error) {
|
||||
onUnexpectedError(error);
|
||||
webviewInput.webview.html = MainThreadWebviews.getDeserializationFailedContents(viewType);
|
||||
@@ -360,6 +365,7 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma
|
||||
modelType: ModelType,
|
||||
resource: URI,
|
||||
viewType: string,
|
||||
cancellation: CancellationToken,
|
||||
): Promise<IReference<ICustomEditorModel>> {
|
||||
const existingModel = this._customEditorService.models.tryRetain(resource, viewType);
|
||||
if (existingModel) {
|
||||
@@ -368,7 +374,7 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma
|
||||
|
||||
const model = modelType === ModelType.Text
|
||||
? CustomTextEditorModel.create(this._instantiationService, viewType, resource)
|
||||
: MainThreadCustomEditorModel.create(this._instantiationService, this._proxy, viewType, resource);
|
||||
: MainThreadCustomEditorModel.create(this._instantiationService, this._proxy, viewType, resource, cancellation);
|
||||
|
||||
return this._customEditorService.models.add(resource, viewType, model);
|
||||
}
|
||||
@@ -555,9 +561,10 @@ class MainThreadCustomEditorModel extends Disposable implements ICustomEditorMod
|
||||
instantiationService: IInstantiationService,
|
||||
proxy: extHostProtocol.ExtHostWebviewsShape,
|
||||
viewType: string,
|
||||
resource: URI
|
||||
resource: URI,
|
||||
cancellation: CancellationToken,
|
||||
) {
|
||||
const { editable } = await proxy.$createWebviewCustomEditorDocument(resource, viewType);
|
||||
const { editable } = await proxy.$createWebviewCustomEditorDocument(resource, viewType, cancellation);
|
||||
return instantiationService.createInstance(MainThreadCustomEditorModel, proxy, viewType, resource, editable);
|
||||
}
|
||||
|
||||
|
||||
@@ -622,8 +622,8 @@ export interface ExtHostWebviewsShape {
|
||||
|
||||
$deserializeWebviewPanel(newWebviewHandle: WebviewPanelHandle, viewType: string, title: string, state: any, position: EditorViewColumn, options: modes.IWebviewOptions & modes.IWebviewPanelOptions): Promise<void>;
|
||||
|
||||
$resolveWebviewEditor(resource: UriComponents, newWebviewHandle: WebviewPanelHandle, viewType: string, title: string, position: EditorViewColumn, options: modes.IWebviewOptions & modes.IWebviewPanelOptions): Promise<void>;
|
||||
$createWebviewCustomEditorDocument(resource: UriComponents, viewType: string): Promise<{ editable: boolean }>;
|
||||
$resolveWebviewEditor(resource: UriComponents, newWebviewHandle: WebviewPanelHandle, viewType: string, title: string, position: EditorViewColumn, options: modes.IWebviewOptions & modes.IWebviewPanelOptions, cancellation: CancellationToken): Promise<void>;
|
||||
$createWebviewCustomEditorDocument(resource: UriComponents, viewType: string, cancellation: CancellationToken): Promise<{ editable: boolean }>;
|
||||
$disposeWebviewCustomEditorDocument(resource: UriComponents, viewType: string): Promise<void>;
|
||||
|
||||
$undo(resource: UriComponents, viewType: string, editId: number): Promise<void>;
|
||||
|
||||
@@ -588,7 +588,7 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
|
||||
await serializer.deserializeWebviewPanel(revivedPanel, state);
|
||||
}
|
||||
|
||||
async $createWebviewCustomEditorDocument(resource: UriComponents, viewType: string) {
|
||||
async $createWebviewCustomEditorDocument(resource: UriComponents, viewType: string, cancellation: CancellationToken) {
|
||||
const entry = this._editorProviders.get(viewType);
|
||||
if (!entry) {
|
||||
throw new Error(`No provider found for '${viewType}'`);
|
||||
@@ -600,7 +600,7 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
|
||||
|
||||
const revivedResource = URI.revive(resource);
|
||||
const document = CustomDocument.create(viewType, revivedResource, entry.provider.editingDelegate);
|
||||
await entry.provider.resolveCustomDocument(document);
|
||||
await entry.provider.resolveCustomDocument(document, cancellation);
|
||||
this._documents.add(document);
|
||||
return {
|
||||
editable: !!entry.provider.editingDelegate,
|
||||
@@ -629,7 +629,8 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
|
||||
viewType: string,
|
||||
title: string,
|
||||
position: EditorViewColumn,
|
||||
options: modes.IWebviewOptions & modes.IWebviewPanelOptions
|
||||
options: modes.IWebviewOptions & modes.IWebviewPanelOptions,
|
||||
cancellation: CancellationToken,
|
||||
): Promise<void> {
|
||||
const entry = this._editorProviders.get(viewType);
|
||||
if (!entry) {
|
||||
@@ -646,12 +647,12 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
|
||||
case WebviewEditorType.Custom:
|
||||
{
|
||||
const document = this.getCustomDocument(viewType, revivedResource);
|
||||
return entry.provider.resolveCustomEditor(document, revivedPanel);
|
||||
return entry.provider.resolveCustomEditor(document, revivedPanel, cancellation);
|
||||
}
|
||||
case WebviewEditorType.Text:
|
||||
{
|
||||
const document = this._extHostDocuments.getDocument(revivedResource);
|
||||
return entry.provider.resolveCustomTextEditor(document, revivedPanel);
|
||||
return entry.provider.resolveCustomTextEditor(document, revivedPanel, cancellation);
|
||||
}
|
||||
default:
|
||||
{
|
||||
@@ -682,7 +683,7 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
|
||||
|
||||
const resource = URI.revive(newResourceComponents);
|
||||
const document = this._extHostDocuments.getDocument(resource);
|
||||
await (entry.provider as vscode.CustomTextEditorProvider).moveCustomTextEditor!(document, webview);
|
||||
await (entry.provider as vscode.CustomTextEditorProvider).moveCustomTextEditor!(document, webview, CancellationToken.None);
|
||||
}
|
||||
|
||||
async $undo(resourceComponents: UriComponents, viewType: string, editId: number): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user