mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-08 01:28:26 -05:00
* Merge from vscode a348d103d1256a06a2c9b3f9b406298a9fef6898 * Fixes and cleanup * Distro * Fix hygiene yarn * delete no yarn lock changes file * Fix hygiene * Fix layer check * Fix CI * Skip lib checks * Remove tests deleted in vs code * Fix tests * Distro * Fix tests and add removed extension point * Skip failing notebook tests for now * Disable broken tests and cleanup build folder * Update yarn.lock and fix smoke tests * Bump sqlite * fix contributed actions and file spacing * Fix user data path * Update yarn.locks Co-authored-by: ADS Merger <karlb@microsoft.com>
143 lines
5.0 KiB
TypeScript
143 lines
5.0 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import { DisposableStore } from 'vs/base/common/lifecycle';
|
|
import { isEqual } from 'vs/base/common/resources';
|
|
import { URI, UriComponents } from 'vs/base/common/uri';
|
|
import { IActiveCodeEditor, IViewZone } from 'vs/editor/browser/editorBrowser';
|
|
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
|
|
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
|
|
import { reviveWebviewContentOptions } from 'vs/workbench/api/browser/mainThreadWebviews';
|
|
import { ExtHostContext, ExtHostEditorInsetsShape, IExtHostContext, IWebviewOptions, MainContext, MainThreadEditorInsetsShape } from 'vs/workbench/api/common/extHost.protocol';
|
|
import { IWebviewService, WebviewElement } from 'vs/workbench/contrib/webview/browser/webview';
|
|
import { extHostNamedCustomer } from '../common/extHostCustomers';
|
|
|
|
// todo@jrieken move these things back into something like contrib/insets
|
|
class EditorWebviewZone implements IViewZone {
|
|
|
|
readonly domNode: HTMLElement;
|
|
readonly afterLineNumber: number;
|
|
readonly afterColumn: number;
|
|
readonly heightInLines: number;
|
|
|
|
private _id?: string;
|
|
// suppressMouseDown?: boolean | undefined;
|
|
// heightInPx?: number | undefined;
|
|
// minWidthInPx?: number | undefined;
|
|
// marginDomNode?: HTMLElement | null | undefined;
|
|
// onDomNodeTop?: ((top: number) => void) | undefined;
|
|
// onComputedHeight?: ((height: number) => void) | undefined;
|
|
|
|
constructor(
|
|
readonly editor: IActiveCodeEditor,
|
|
readonly line: number,
|
|
readonly height: number,
|
|
readonly webview: WebviewElement,
|
|
) {
|
|
this.domNode = document.createElement('div');
|
|
this.domNode.style.zIndex = '10'; // without this, the webview is not interactive
|
|
this.afterLineNumber = line;
|
|
this.afterColumn = 1;
|
|
this.heightInLines = height;
|
|
|
|
editor.changeViewZones(accessor => this._id = accessor.addZone(this));
|
|
webview.mountTo(this.domNode);
|
|
}
|
|
|
|
dispose(): void {
|
|
this.editor.changeViewZones(accessor => this._id && accessor.removeZone(this._id));
|
|
}
|
|
}
|
|
|
|
@extHostNamedCustomer(MainContext.MainThreadEditorInsets)
|
|
export class MainThreadEditorInsets implements MainThreadEditorInsetsShape {
|
|
|
|
private readonly _proxy: ExtHostEditorInsetsShape;
|
|
private readonly _disposables = new DisposableStore();
|
|
private readonly _insets = new Map<number, EditorWebviewZone>();
|
|
|
|
constructor(
|
|
context: IExtHostContext,
|
|
@ICodeEditorService private readonly _editorService: ICodeEditorService,
|
|
@IWebviewService private readonly _webviewService: IWebviewService,
|
|
) {
|
|
this._proxy = context.getProxy(ExtHostContext.ExtHostEditorInsets);
|
|
}
|
|
|
|
dispose(): void {
|
|
this._disposables.dispose();
|
|
}
|
|
|
|
async $createEditorInset(handle: number, id: string, uri: UriComponents, line: number, height: number, options: IWebviewOptions, extensionId: ExtensionIdentifier, extensionLocation: UriComponents): Promise<void> {
|
|
|
|
let editor: IActiveCodeEditor | undefined;
|
|
id = id.substr(0, id.indexOf(',')); //todo@jrieken HACK
|
|
|
|
for (const candidate of this._editorService.listCodeEditors()) {
|
|
if (candidate.getId() === id && candidate.hasModel() && isEqual(candidate.getModel().uri, URI.revive(uri))) {
|
|
editor = candidate;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!editor) {
|
|
setTimeout(() => this._proxy.$onDidDispose(handle));
|
|
return;
|
|
}
|
|
|
|
const disposables = new DisposableStore();
|
|
|
|
const webview = this._webviewService.createWebviewElement('' + handle, {
|
|
enableFindWidget: false,
|
|
}, reviveWebviewContentOptions(options), { id: extensionId, location: URI.revive(extensionLocation) });
|
|
|
|
const webviewZone = new EditorWebviewZone(editor, line, height, webview);
|
|
|
|
const remove = () => {
|
|
disposables.dispose();
|
|
this._proxy.$onDidDispose(handle);
|
|
this._insets.delete(handle);
|
|
};
|
|
|
|
disposables.add(editor.onDidChangeModel(remove));
|
|
disposables.add(editor.onDidDispose(remove));
|
|
disposables.add(webviewZone);
|
|
disposables.add(webview);
|
|
disposables.add(webview.onMessage(msg => this._proxy.$onDidReceiveMessage(handle, msg.message)));
|
|
|
|
this._insets.set(handle, webviewZone);
|
|
}
|
|
|
|
$disposeEditorInset(handle: number): void {
|
|
const inset = this.getInset(handle);
|
|
this._insets.delete(handle);
|
|
inset.dispose();
|
|
}
|
|
|
|
$setHtml(handle: number, value: string): void {
|
|
const inset = this.getInset(handle);
|
|
inset.webview.html = value;
|
|
}
|
|
|
|
$setOptions(handle: number, options: IWebviewOptions): void {
|
|
const inset = this.getInset(handle);
|
|
inset.webview.contentOptions = reviveWebviewContentOptions(options);
|
|
}
|
|
|
|
async $postMessage(handle: number, value: any): Promise<boolean> {
|
|
const inset = this.getInset(handle);
|
|
inset.webview.postMessage(value);
|
|
return true;
|
|
}
|
|
|
|
private getInset(handle: number): EditorWebviewZone {
|
|
const inset = this._insets.get(handle);
|
|
if (!inset) {
|
|
throw new Error('Unknown inset');
|
|
}
|
|
return inset;
|
|
}
|
|
}
|