From 05b6d1d83f90e9d543803b08292dc5213d41f8d8 Mon Sep 17 00:00:00 2001 From: Jason Dent Date: Sat, 7 Oct 2023 18:01:27 +0200 Subject: [PATCH] Add openTextDocument endpoint --- packages/client/src/webview/api/api.ts | 8 +++++++- .../webview-api/src/__snapshots__/api.test.ts.snap | 2 ++ packages/webview-api/src/api.test.ts | 1 + packages/webview-api/src/api.ts | 1 + packages/webview-ui/src/api.ts | 1 + packages/webview-ui/src/views/CSpellInfo.svelte | 12 +++++++++++- 6 files changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/client/src/webview/api/api.ts b/packages/client/src/webview/api/api.ts index a29ce69b04..fcf8e2228d 100644 --- a/packages/client/src/webview/api/api.ts +++ b/packages/client/src/webview/api/api.ts @@ -1,6 +1,6 @@ import { createDisposableList, type DisposableLike, disposeOf, injectDisposable, makeDisposable } from 'utils-disposables'; import { createLogger, LogLevel } from 'utils-logger'; -import { window } from 'vscode'; +import { Uri, window } from 'vscode'; import { type MessageConnection } from 'vscode-jsonrpc/node'; import type { RequestResult, SetValueRequest, SetValueResult, WatchFieldList, WatchFields } from 'webview-api'; import { createServerSideSpellInfoWebviewApi } from 'webview-api'; @@ -49,6 +49,12 @@ export function bindApiAndStore(connection: MessageConnection, store: Storage): async showInformationMessage(message) { await window.showInformationMessage('Show Message: ' + message); }, + async openTextDocument(url) { + if (!url) return; + const uri = Uri.parse(url); + // console.error('Open %o, %o', url, uri.toJSON()); + await window.showTextDocument(uri); + }, }, clientRequests: {}, clientNotifications: { onStateChange: true }, diff --git a/packages/webview-api/src/__snapshots__/api.test.ts.snap b/packages/webview-api/src/__snapshots__/api.test.ts.snap index 4439eadd77..e370efabb3 100644 --- a/packages/webview-api/src/__snapshots__/api.test.ts.snap +++ b/packages/webview-api/src/__snapshots__/api.test.ts.snap @@ -3,6 +3,7 @@ exports[`api > Creating a Server API 1`] = ` [ "clientNotification.onStateChange", + "serverNotification.openTextDocument", "serverNotification.showInformationMessage", "serverRequest.getCurrentDocument", "serverRequest.getDocSettings", @@ -28,6 +29,7 @@ exports[`api > Creating a Server API 2`] = ` "function", "function", "function", + "function", "object", ] `; diff --git a/packages/webview-api/src/api.test.ts b/packages/webview-api/src/api.test.ts index eca0448484..a065f2c117 100644 --- a/packages/webview-api/src/api.test.ts +++ b/packages/webview-api/src/api.test.ts @@ -19,6 +19,7 @@ describe('api', () => { clientRequests: {}, serverNotifications: { showInformationMessage: true, + openTextDocument: true, }, serverRequests: { getCurrentDocument: true, diff --git a/packages/webview-api/src/api.ts b/packages/webview-api/src/api.ts index 950f4c0002..52bf226424 100644 --- a/packages/webview-api/src/api.ts +++ b/packages/webview-api/src/api.ts @@ -29,6 +29,7 @@ export interface ServerRequestsAPI { /** Notifications that can be sent to the extension */ export interface ServerNotificationsAPI { showInformationMessage(message: string): void; + openTextDocument(url: string): void; } /** diff --git a/packages/webview-ui/src/api.ts b/packages/webview-ui/src/api.ts index 82823389e7..cc01a0f899 100644 --- a/packages/webview-ui/src/api.ts +++ b/packages/webview-ui/src/api.ts @@ -43,6 +43,7 @@ function createApi(): API { { serverNotifications: { showInformationMessage: true, + openTextDocument: true, }, serverRequests: { getCurrentDocument: true, diff --git a/packages/webview-ui/src/views/CSpellInfo.svelte b/packages/webview-ui/src/views/CSpellInfo.svelte index 275ae998e0..1192becc49 100644 --- a/packages/webview-ui/src/views/CSpellInfo.svelte +++ b/packages/webview-ui/src/views/CSpellInfo.svelte @@ -41,7 +41,17 @@
{dictionary.name} {dictionary.locales.join(', ')}
{dictionary.description || ''}
{#if dictionary.uriName} -
{dictionary.uriName}
+
+ {#if dictionary.uri} + dictionary.uri && getClientApi().serverNotification.openTextDocument(dictionary.uri)} + >{dictionary.uriName} + {:else} + {dictionary.uriName} + {/if} +
{/if}