1515import * as vscode from "vscode" ;
1616import * as fs from "fs/promises" ;
1717import * as path from "path" ;
18- import { RenderNode , WebviewMessage } from "./webview/WebviewMessage" ;
18+ import { RenderNode , WebviewContent , WebviewMessage } from "./webview/WebviewMessage" ;
1919import { WorkspaceContext } from "../WorkspaceContext" ;
20- import { RenderDocumentationRequest } from "../sourcekit-lsp/extensions/RenderDocumentationRequest " ;
20+ import { ConvertDocumentationRequest } from "../sourcekit-lsp/extensions/ConvertDocumentationRequest " ;
2121
2222export enum PreviewEditorConstant {
2323 VIEW_TYPE = "swift.previewDocumentationEditor" ,
@@ -30,7 +30,7 @@ export class DocumentationPreviewEditor implements vscode.Disposable {
3030
3131 private disposeEmitter = new vscode . EventEmitter < void > ( ) ;
3232 private renderEmitter = new vscode . EventEmitter < void > ( ) ;
33- private updateContentEmitter = new vscode . EventEmitter < RenderNode > ( ) ;
33+ private updateContentEmitter = new vscode . EventEmitter < WebviewContent > ( ) ;
3434
3535 constructor (
3636 private readonly extension : vscode . ExtensionContext ,
@@ -66,10 +66,10 @@ export class DocumentationPreviewEditor implements vscode.Disposable {
6666 this . subscriptions . push (
6767 this . webviewPanel . webview . onDidReceiveMessage ( this . receiveMessage . bind ( this ) ) ,
6868 vscode . window . onDidChangeActiveTextEditor ( editor => {
69- this . renderDocumentation ( editor ) ;
69+ this . convertDocumentation ( editor ) ;
7070 } ) ,
7171 vscode . window . onDidChangeTextEditorSelection ( event => {
72- this . renderDocumentation ( event . textEditor ) ;
72+ this . convertDocumentation ( event . textEditor ) ;
7373 } ) ,
7474 this . webviewPanel . onDidDispose ( this . dispose . bind ( this ) )
7575 ) ;
@@ -109,36 +109,46 @@ export class DocumentationPreviewEditor implements vscode.Disposable {
109109 private receiveMessage ( message : WebviewMessage ) {
110110 switch ( message . type ) {
111111 case "loaded" :
112- this . renderDocumentation ( vscode . window . activeTextEditor ) ;
112+ this . convertDocumentation ( vscode . window . activeTextEditor ) ;
113113 break ;
114114 case "rendered" :
115115 this . renderEmitter . fire ( ) ;
116116 break ;
117117 }
118118 }
119119
120- private async renderDocumentation ( editor : vscode . TextEditor | undefined ) : Promise < void > {
120+ private async convertDocumentation ( editor : vscode . TextEditor | undefined ) : Promise < void > {
121121 const document = editor ?. document ;
122122 if ( ! document || document . uri . scheme !== "file" ) {
123123 return undefined ;
124124 }
125125
126126 const response = await this . context . languageClientManager . useLanguageClient (
127127 async client => {
128- return await client . sendRequest ( RenderDocumentationRequest . type , {
128+ return await client . sendRequest ( ConvertDocumentationRequest . type , {
129129 textDocument : {
130130 uri : document . uri . toString ( ) ,
131131 } ,
132132 position : editor . selection . start ,
133133 } ) ;
134134 }
135135 ) ;
136- if ( ! response . content ) {
136+ if ( response . type === "error" ) {
137+ this . postMessage ( {
138+ type : "update-content" ,
139+ content : {
140+ type : "error" ,
141+ errorMessage : response . error . message ,
142+ } ,
143+ } ) ;
137144 return ;
138145 }
139146 this . postMessage ( {
140147 type : "update-content" ,
141- content : this . parseRenderNode ( response . content ) ,
148+ content : {
149+ type : "render-node" ,
150+ renderNode : this . parseRenderNode ( response . renderNode ) ,
151+ } ,
142152 } ) ;
143153 }
144154
0 commit comments