Skip to content

Commit

Permalink
Add openTextDocument endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed Oct 7, 2023
1 parent 9785bb9 commit 05b6d1d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
8 changes: 7 additions & 1 deletion packages/client/src/webview/api/api.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 },
Expand Down
2 changes: 2 additions & 0 deletions packages/webview-api/src/__snapshots__/api.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`api > Creating a Server API 1`] = `
[
"clientNotification.onStateChange",
"serverNotification.openTextDocument",
"serverNotification.showInformationMessage",
"serverRequest.getCurrentDocument",
"serverRequest.getDocSettings",
Expand All @@ -28,6 +29,7 @@ exports[`api > Creating a Server API 2`] = `
"function",
"function",
"function",
"function",
"object",
]
`;
Expand Down
1 change: 1 addition & 0 deletions packages/webview-api/src/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('api', () => {
clientRequests: {},
serverNotifications: {
showInformationMessage: true,
openTextDocument: true,
},
serverRequests: {
getCurrentDocument: true,
Expand Down
1 change: 1 addition & 0 deletions packages/webview-api/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/webview-ui/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function createApi(): API {
{
serverNotifications: {
showInformationMessage: true,
openTextDocument: true,
},
serverRequests: {
getCurrentDocument: true,
Expand Down
12 changes: 11 additions & 1 deletion packages/webview-ui/src/views/CSpellInfo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,17 @@
<dt>{dictionary.name} <sup>{dictionary.locales.join(', ')}</sup></dt>
<dd>{dictionary.description || ''}</dd>
{#if dictionary.uriName}
<dd><a href={dictionary.uri}>{dictionary.uriName}</a></dd>
<dd>
{#if dictionary.uri}
<a
href={dictionary.uri}
on:click={() => dictionary.uri && getClientApi().serverNotification.openTextDocument(dictionary.uri)}
>{dictionary.uriName}</a
>
{:else}
{dictionary.uriName}
{/if}
</dd>
{/if}
</dl>
</li>
Expand Down

0 comments on commit 05b6d1d

Please sign in to comment.