mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-23 18:19:12 +01:00
remove getNamedCustomer, connect MainThreadWebview with CodeInsetController
This commit is contained in:
@@ -478,7 +478,7 @@ export function createApiFactory(
|
||||
return extHostOutputService.createOutputChannel(name);
|
||||
},
|
||||
createWebviewPanel(viewType: string, title: string, showOptions: vscode.ViewColumn | { viewColumn: vscode.ViewColumn, preserveFocus?: boolean }, options: vscode.WebviewPanelOptions & vscode.WebviewOptions): vscode.WebviewPanel {
|
||||
return extHostWebviews.createWebview(extension, viewType, title, showOptions, options);
|
||||
return extHostWebviews.createWebviewPanel(extension, viewType, title, showOptions, options);
|
||||
},
|
||||
createTerminal(nameOrOptions: vscode.TerminalOptions | string, shellPath?: string, shellArgs?: string[]): vscode.Terminal {
|
||||
if (typeof nameOrOptions === 'object') {
|
||||
|
||||
@@ -469,20 +469,24 @@ export interface MainThreadTelemetryShape extends IDisposable {
|
||||
|
||||
export type WebviewPanelHandle = string;
|
||||
|
||||
export type WebviewInsetHandle = number;
|
||||
|
||||
export interface WebviewPanelShowOptions {
|
||||
readonly viewColumn?: EditorViewColumn;
|
||||
readonly preserveFocus?: boolean;
|
||||
}
|
||||
|
||||
export interface MainThreadWebviewsShape extends IDisposable {
|
||||
$createWebview(handle: WebviewPanelHandle, viewType: string, title: string, showOptions: WebviewPanelShowOptions, options: vscode.WebviewPanelOptions & vscode.WebviewOptions, extensionId: ExtensionIdentifier, extensionLocation: UriComponents): void;
|
||||
$createWebviewPanel(handle: WebviewPanelHandle, viewType: string, title: string, showOptions: WebviewPanelShowOptions, options: vscode.WebviewPanelOptions & vscode.WebviewOptions, extensionId: ExtensionIdentifier, extensionLocation: UriComponents): void;
|
||||
$createWebviewCodeInset(handle: WebviewInsetHandle, symbolId: string, options: vscode.WebviewOptions, extensionLocation: UriComponents): void;
|
||||
$disposeWebview(handle: WebviewPanelHandle): void;
|
||||
$reveal(handle: WebviewPanelHandle, showOptions: WebviewPanelShowOptions): void;
|
||||
$setTitle(handle: WebviewPanelHandle, value: string): void;
|
||||
$setIconPath(handle: WebviewPanelHandle, value: { light: UriComponents, dark: UriComponents } | undefined): void;
|
||||
$setHtml(handle: WebviewPanelHandle, value: string): void;
|
||||
$setOptions(handle: WebviewPanelHandle, options: vscode.WebviewOptions): void;
|
||||
$postMessage(handle: WebviewPanelHandle, value: any): Promise<boolean>;
|
||||
|
||||
$setHtml(handle: WebviewPanelHandle | WebviewInsetHandle, value: string): void;
|
||||
$setOptions(handle: WebviewPanelHandle | WebviewInsetHandle, options: vscode.WebviewOptions): void;
|
||||
$postMessage(handle: WebviewPanelHandle | WebviewInsetHandle, value: any): Promise<boolean>;
|
||||
|
||||
$registerSerializer(viewType: string): void;
|
||||
$unregisterSerializer(viewType: string): void;
|
||||
|
||||
@@ -15,7 +15,7 @@ import { ExtHostDocuments } from 'vs/workbench/api/node/extHostDocuments';
|
||||
import { ExtHostCommands, CommandsConverter } from 'vs/workbench/api/node/extHostCommands';
|
||||
import { ExtHostDiagnostics } from 'vs/workbench/api/node/extHostDiagnostics';
|
||||
import { asPromise } from 'vs/base/common/async';
|
||||
import { MainContext, MainThreadLanguageFeaturesShape, ExtHostLanguageFeaturesShape, ObjectIdentifier, IRawColorInfo, IMainContext, IdObject, ISerializedRegExp, ISerializedIndentationRule, ISerializedOnEnterRule, ISerializedLanguageConfiguration, WorkspaceSymbolDto, SuggestResultDto, WorkspaceSymbolsDto, SuggestionDto, CodeActionDto, ISerializedDocumentFilter, WorkspaceEditDto, ISerializedSignatureHelpProviderMetadata, LinkDto, CodeLensDto, MainThreadWebviewsShape } from './extHost.protocol';
|
||||
import { MainContext, MainThreadLanguageFeaturesShape, ExtHostLanguageFeaturesShape, ObjectIdentifier, IRawColorInfo, IMainContext, IdObject, ISerializedRegExp, ISerializedIndentationRule, ISerializedOnEnterRule, ISerializedLanguageConfiguration, WorkspaceSymbolDto, SuggestResultDto, WorkspaceSymbolsDto, SuggestionDto, CodeActionDto, ISerializedDocumentFilter, WorkspaceEditDto, ISerializedSignatureHelpProviderMetadata, LinkDto, CodeLensDto, MainThreadWebviewsShape, CodeInsetDto } from './extHost.protocol';
|
||||
import { regExpLeadsToEndlessLoop, regExpFlags } from 'vs/base/common/strings';
|
||||
import { IPosition } from 'vs/editor/common/core/position';
|
||||
import { IRange, Range as EditorRange } from 'vs/editor/common/core/range';
|
||||
@@ -28,6 +28,7 @@ import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
|
||||
import { ExtHostWebview } from 'vs/workbench/api/node/extHostWebview';
|
||||
import * as codeInset from 'vs/workbench/contrib/codeinset/codeInset';
|
||||
import { generateUuid } from 'vs/base/common/uuid';
|
||||
|
||||
// --- adapter
|
||||
|
||||
@@ -154,38 +155,33 @@ class CodeInsetAdapter {
|
||||
private readonly _provider: vscode.CodeInsetProvider
|
||||
) { }
|
||||
|
||||
provideCodeInsets(resource: URI, token: CancellationToken): Promise<codeInset.ICodeInsetSymbol[]> {
|
||||
provideCodeInsets(resource: URI, token: CancellationToken): Promise<CodeInsetDto[]> {
|
||||
const doc = this._documents.getDocumentData(resource).document;
|
||||
return asPromise(() => this._provider.provideCodeInsets(doc, token)).then(insets => {
|
||||
if (Array.isArray(insets)) {
|
||||
return insets.map(inset => {
|
||||
const id = this._heapService.keep(inset);
|
||||
return ObjectIdentifier.mixin({
|
||||
const $ident = this._heapService.keep(inset);
|
||||
const id = generateUuid();
|
||||
return {
|
||||
$ident,
|
||||
id,
|
||||
range: typeConvert.Range.from(inset.range),
|
||||
height: inset.height
|
||||
}, id);
|
||||
};
|
||||
});
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
}
|
||||
|
||||
resolveCodeInset(symbol: codeInset.ICodeInsetSymbol, webview: vscode.Webview, token: CancellationToken): Promise<codeInset.ICodeInsetSymbol> {
|
||||
resolveCodeInset(symbol: CodeInsetDto, webview: vscode.Webview, token: CancellationToken): Promise<CodeInsetDto> {
|
||||
|
||||
const inset = this._heapService.get<vscode.CodeInset>(ObjectIdentifier.of(symbol));
|
||||
if (!inset) {
|
||||
return undefined;
|
||||
return Promise.resolve(symbol);
|
||||
}
|
||||
|
||||
let resolve: Promise<vscode.CodeInset>;
|
||||
if (typeof this._provider.resolveCodeInset !== 'function') {
|
||||
resolve = Promise.resolve(inset);
|
||||
} else {
|
||||
resolve = asPromise(() => this._provider.resolveCodeInset(inset, webview, token));
|
||||
}
|
||||
|
||||
return resolve.then(newInset => {
|
||||
return asPromise(() => this._provider.resolveCodeInset(inset, webview, token)).then(newInset => {
|
||||
newInset = newInset || inset;
|
||||
return symbol;
|
||||
});
|
||||
@@ -1057,7 +1053,7 @@ export class ExtHostLanguageFeatures implements ExtHostLanguageFeaturesShape {
|
||||
return ExtHostLanguageFeatures._handlePool++;
|
||||
}
|
||||
|
||||
private _withAdapter<A, R>(handle: number, ctor: { new(...args: any[]): A }, callback: (adapter: A) => Promise<R>): Promise<R> {
|
||||
private _withAdapter<A, R>(handle: number, ctor: { new(...args: any[]): A }, callback: (adapter: A, extenson: IExtensionDescription) => Promise<R>): Promise<R> {
|
||||
const data = this._adapter.get(handle);
|
||||
if (!data) {
|
||||
return Promise.reject(new Error('no adapter found'));
|
||||
@@ -1069,7 +1065,7 @@ export class ExtHostLanguageFeatures implements ExtHostLanguageFeaturesShape {
|
||||
t1 = Date.now();
|
||||
this._logService.trace(`[${data.extension.identifier.value}] INVOKE provider '${(ctor as any).name}'`);
|
||||
}
|
||||
let p = callback(data.adapter);
|
||||
let p = callback(data.adapter, data.extension);
|
||||
const extension = data.extension;
|
||||
if (extension) {
|
||||
Promise.resolve(p).then(
|
||||
@@ -1156,14 +1152,13 @@ export class ExtHostLanguageFeatures implements ExtHostLanguageFeaturesShape {
|
||||
return this._withAdapter(handle, CodeInsetAdapter, adapter => adapter.provideCodeInsets(URI.revive(resource), token));
|
||||
}
|
||||
|
||||
$resolveCodeInset(handle: number, resource: UriComponents, symbol: codeInset.ICodeInsetSymbol, token: CancellationToken): Promise<codeInset.ICodeInsetSymbol> {
|
||||
const webview = new ExtHostWebview(symbol.webviewHandle, this._webviewProxy, { enableScripts: true });
|
||||
webview.html = '<html><body></body></html>';
|
||||
const x = this._withAdapter(handle, CodeInsetAdapter, adapter => adapter.resolveCodeInset(symbol, webview, token));
|
||||
return x;
|
||||
}
|
||||
|
||||
$createCodeInsetWebview(handle: number) {
|
||||
$resolveCodeInset(handle: number, _resource: UriComponents, symbol: codeInset.ICodeInsetSymbol, token: CancellationToken): Promise<codeInset.ICodeInsetSymbol> {
|
||||
const webviewHandle = Math.random();
|
||||
const webview = new ExtHostWebview(webviewHandle, this._webviewProxy, { enableScripts: true });
|
||||
return this._withAdapter(handle, CodeInsetAdapter, async (adapter, extension) => {
|
||||
await this._webviewProxy.$createWebviewCodeInset(webviewHandle, symbol.id, { enableCommandUris: true, enableScripts: true }, extension.extensionLocation);
|
||||
return adapter.resolveCodeInset(symbol, webview, token);
|
||||
});
|
||||
}
|
||||
|
||||
// --- declaration
|
||||
|
||||
@@ -8,14 +8,14 @@ import { URI } from 'vs/base/common/uri';
|
||||
import * as typeConverters from 'vs/workbench/api/node/extHostTypeConverters';
|
||||
import { EditorViewColumn } from 'vs/workbench/api/shared/editor';
|
||||
import * as vscode from 'vscode';
|
||||
import { ExtHostWebviewsShape, IMainContext, MainContext, MainThreadWebviewsShape, WebviewPanelHandle, WebviewPanelViewState } from './extHost.protocol';
|
||||
import { ExtHostWebviewsShape, IMainContext, MainContext, MainThreadWebviewsShape, WebviewPanelHandle, WebviewPanelViewState, WebviewInsetHandle } from './extHost.protocol';
|
||||
import { Disposable } from './extHostTypes';
|
||||
import { IExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
|
||||
|
||||
type IconPath = URI | { light: URI, dark: URI };
|
||||
|
||||
export class ExtHostWebview implements vscode.Webview {
|
||||
private readonly _handle: WebviewPanelHandle;
|
||||
private readonly _handle: WebviewPanelHandle | WebviewInsetHandle;
|
||||
private readonly _proxy: MainThreadWebviewsShape;
|
||||
private _html: string;
|
||||
private _options: vscode.WebviewOptions;
|
||||
@@ -25,7 +25,7 @@ export class ExtHostWebview implements vscode.Webview {
|
||||
public readonly onDidReceiveMessage: Event<any> = this._onMessageEmitter.event;
|
||||
|
||||
constructor(
|
||||
handle: WebviewPanelHandle,
|
||||
handle: WebviewPanelHandle | WebviewInsetHandle,
|
||||
proxy: MainThreadWebviewsShape,
|
||||
options: vscode.WebviewOptions
|
||||
) {
|
||||
@@ -243,7 +243,7 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
|
||||
this._proxy = mainContext.getProxy(MainContext.MainThreadWebviews);
|
||||
}
|
||||
|
||||
public createWebview(
|
||||
public createWebviewPanel(
|
||||
extension: IExtensionDescription,
|
||||
viewType: string,
|
||||
title: string,
|
||||
@@ -257,7 +257,7 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
|
||||
};
|
||||
|
||||
const handle = ExtHostWebviews.newHandle();
|
||||
this._proxy.$createWebview(handle, viewType, title, webviewShowOptions, options, extension.identifier, extension.extensionLocation);
|
||||
this._proxy.$createWebviewPanel(handle, viewType, title, webviewShowOptions, options, extension.identifier, extension.extensionLocation);
|
||||
|
||||
const webview = new ExtHostWebview(handle, this._proxy, options);
|
||||
const panel = new ExtHostWebviewPanel(handle, this._proxy, viewType, title, viewColumn, options, webview);
|
||||
|
||||
Reference in New Issue
Block a user