From 4a9962a7fc46da10f64a5e8d816be8af8c243173 Mon Sep 17 00:00:00 2001 From: mp Date: Thu, 31 Oct 2024 19:24:44 -0700 Subject: [PATCH] add native updateEditorInset() function --- extensions/void/src/extension/extension.ts | 6 ++++ .../workbench/api/common/extHost.api.impl.ts | 4 +++ .../workbench/api/common/extHostCodeInsets.ts | 30 ++++++++++++++++++- .../vscode.proposed.editorInsets.d.ts | 2 ++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/extensions/void/src/extension/extension.ts b/extensions/void/src/extension/extension.ts index cc7cbed6..2ae59eeb 100644 --- a/extensions/void/src/extension/extension.ts +++ b/extensions/void/src/extension/extension.ts @@ -12,19 +12,25 @@ import { CtrlKWebviewProvider } from './providers/CtrlKWebviewProvider'; // this comes from vscode.proposed.editorInsets.d.ts declare module 'vscode' { + export interface WebviewEditorInset { readonly editor: vscode.TextEditor; readonly line: number; readonly height: number; readonly webview: vscode.Webview; + readonly handle: number; readonly onDidDispose: Event; dispose(): void; } + export namespace window { export function createWebviewTextEditorInset(editor: vscode.TextEditor, line: number, height: number, options?: vscode.WebviewOptions): WebviewEditorInset; + export function updateWebviewTextEditorInset(handle: number, line: number, height: number): WebviewEditorInset; } } + + const roundRangeToLines = (selection: vscode.Selection) => { let endLine = selection.end.character === 0 ? selection.end.line - 1 : selection.end.line // e.g. if the user triple clicks, it selects column=0, line=line -> column=0, line=line+1 return new vscode.Range(selection.start.line, 0, endLine, Number.MAX_SAFE_INTEGER) diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index 3635e182..a8bab36b 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -826,6 +826,10 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I // checkProposedApiEnabled(extension, 'editorInsets'); // Void commented this out return extHostEditorInsets.createWebviewEditorInset(editor, line, height, options, extension); }, + // Void created this function: + updateWebviewTextEditorInset(handle: number, line: number, height: number): vscode.WebviewEditorInset { + return extHostEditorInsets.updateEditorInset(handle, line, height); + }, createTerminal(nameOrOptions?: vscode.TerminalOptions | vscode.ExtensionTerminalOptions | string, shellPath?: string, shellArgs?: readonly string[] | string): vscode.Terminal { if (typeof nameOrOptions === 'object') { if ('pty' in nameOrOptions) { diff --git a/src/vs/workbench/api/common/extHostCodeInsets.ts b/src/vs/workbench/api/common/extHostCodeInsets.ts index 01cc0023..220618a5 100644 --- a/src/vs/workbench/api/common/extHostCodeInsets.ts +++ b/src/vs/workbench/api/common/extHostCodeInsets.ts @@ -99,11 +99,11 @@ export class ExtHostEditorInsets implements ExtHostEditorInsetsShape { }; const inset = new class implements vscode.WebviewEditorInset { - readonly editor: vscode.TextEditor = editor; readonly line: number = line; readonly height: number = height; readonly webview: vscode.Webview = webview; + readonly handle: number = handle; readonly onDidDispose: vscode.Event = onDidDispose.event; dispose(): void { @@ -125,6 +125,34 @@ export class ExtHostEditorInsets implements ExtHostEditorInsetsShape { return inset; } + + updateEditorInset(handle: number, line: number, height: number): vscode.WebviewEditorInset { + const _inset = this._insets.get(handle); + + if (!_inset) { + throw new Error(`Inset with handle ${handle} not found`); + } + + const { editor, onDidReceiveMessage, inset: { webview, onDidDispose, dispose } } = _inset + + const inset = new class implements vscode.WebviewEditorInset { + readonly editor: vscode.TextEditor = editor; + readonly line: number = line; + readonly height: number = height; + readonly webview: vscode.Webview = webview; + readonly handle: number = handle; + readonly onDidDispose: vscode.Event = onDidDispose; + dispose = dispose + }; + + this._insets.set(handle, { editor, inset: inset, onDidReceiveMessage }); + // _inset?.onDidReceiveMessage.fire({}); + + return inset + } + + + $onDidDispose(handle: number): void { const value = this._insets.get(handle); if (value) { diff --git a/src/vscode-dts/vscode.proposed.editorInsets.d.ts b/src/vscode-dts/vscode.proposed.editorInsets.d.ts index c13b4208..beac670c 100644 --- a/src/vscode-dts/vscode.proposed.editorInsets.d.ts +++ b/src/vscode-dts/vscode.proposed.editorInsets.d.ts @@ -12,11 +12,13 @@ declare module 'vscode' { readonly line: number; readonly height: number; readonly webview: Webview; + readonly handle: number; readonly onDidDispose: Event; dispose(): void; } export namespace window { export function createWebviewTextEditorInset(editor: TextEditor, line: number, height: number, options?: WebviewOptions): WebviewEditorInset; + export function updateWebviewTextEditorInset(handle: number, line: number, height: number): WebviewEditorInset; } }