@@ -19,7 +19,7 @@ use lsp_types::{
1919 TextDocumentSyncKind , TextDocumentSyncOptions , TextDocumentSyncSaveOptions , Url ,
2020 WorkspaceClientCapabilities , WorkspaceFoldersServerCapabilities , WorkspaceServerCapabilities ,
2121} ;
22- use playground_server:: { FrontendMessage , Orwie12Message , Reofji32Message } ;
22+ use playground_server:: { FrontendMessage , WebviewNotification , WebviewRouterMessage } ;
2323use schedule:: Task ;
2424use serde:: { Deserialize , Serialize } ;
2525use serde_json:: json;
@@ -49,9 +49,9 @@ pub type Result<T> = std::result::Result<T, api::Error>;
4949
5050pub ( crate ) struct ServerArgs {
5151 pub tokio_runtime : tokio:: runtime:: Runtime ,
52- pub reofji32_tx : broadcast:: Sender < Reofji32Message > ,
53- pub orwie12_rx : broadcast:: Receiver < Orwie12Message > ,
54- pub orwie12_tx : broadcast:: Sender < Orwie12Message > ,
52+ pub webview_router_to_websocket_tx : broadcast:: Sender < WebviewNotification > ,
53+ pub webview_router_input_rx : broadcast:: Receiver < WebviewRouterMessage > ,
54+ pub webview_router_input_tx : broadcast:: Sender < WebviewRouterMessage > ,
5555 pub playground_port : u16 ,
5656 pub proxy_port : u16 ,
5757}
@@ -176,8 +176,8 @@ impl Server {
176176 global_settings,
177177 & workspaces,
178178 args. playground_port ,
179- args. orwie12_tx . clone ( ) ,
180- args. reofji32_tx . clone ( ) ,
179+ args. webview_router_input_tx . clone ( ) ,
180+ args. webview_router_to_websocket_tx . clone ( ) ,
181181 client_version,
182182 ) ?;
183183
@@ -209,16 +209,32 @@ impl Server {
209209 } ) ;
210210 }
211211 {
212+ // Start the webview router loop
213+ //
214+ // This is the communication bridge between the webview and IDE in non-VSCode environments
215+ // and allows the webview to send messages to Jetbrains and allows Jetbrains to send messages
216+ // to the webview.
217+ //
218+ // webview->IDE is generally backed by the webview POSTing to /webview/SEND_LSP_NOTIFICATION_TO_IDE,
219+ // and the language server will then forward that to the IDE
220+ // IDE->webview is generally backed by the IDE calling POST /webview/SEND_LSP_NOTIFICATION_TO_WEBVIEW,
221+ // and the language server will then forward that to the webview
222+ //
223+ // (Note that although the language-server pretends to offer a request-response API, it does not
224+ // block on either the IDE or webview responding before responding to its caller.)
225+ //
226+ // Incoming messages are received via webview_router_input_tx, which the router will then decide to
227+ // dispatch to either the webview (via its websocket) or the IDE (via its LSP connection).
212228 let lsp_sender = server. connection . make_sender ( ) ;
213- let mut orwie12_rx = server. args . orwie12_rx . resubscribe ( ) ;
214- let reofji32_tx = server. args . reofji32_tx . clone ( ) ;
229+ let mut webview_router_input_rx = server. args . webview_router_input_rx . resubscribe ( ) ;
230+ let webview_router_to_websocket_tx = server. args . webview_router_to_websocket_tx . clone ( ) ;
215231 let session = server. session . clone ( ) ;
216232 server. args . tokio_runtime . spawn ( async move {
217233 tracing:: info!( "Starting playground rx loop" ) ;
218- while let Ok ( msg) = orwie12_rx . recv ( ) . await {
234+ while let Ok ( msg) = webview_router_input_rx . recv ( ) . await {
219235 tracing:: info!( "playground rx loop: {:?}" , msg) ;
220236 match msg {
221- Orwie12Message :: WasmIsInitialized => {
237+ WebviewRouterMessage :: WasmIsInitialized => {
222238 tracing:: info!( "Received playground INITIALIZED request" ) ;
223239 let projects = session. baml_src_projects . lock ( ) ;
224240 for ( _, project) in projects. iter ( ) {
@@ -239,8 +255,8 @@ impl Server {
239255 ( key, contents)
240256 } )
241257 . collect ( ) ;
242- let _ = reofji32_tx
243- . send ( Reofji32Message :: PlaygroundMessage (
258+ let _ = webview_router_to_websocket_tx
259+ . send ( WebviewNotification :: PlaygroundMessage (
244260 FrontendMessage :: add_project {
245261 root_path : project
246262 . root_path ( )
@@ -254,18 +270,18 @@ impl Server {
254270 } ) ;
255271 }
256272 }
257- Orwie12Message :: SendLspNotificationToIde ( notification) => {
273+ WebviewRouterMessage :: SendLspNotificationToIde ( notification) => {
258274 tracing:: info!( "Received playground SEND_LSP_NOTIFICATION request: {:?}" , notification) ;
259275 let _ = lsp_sender
260276 . send ( Message :: Notification ( notification) )
261277 . inspect_err ( |e| {
262278 tracing:: error!( "Failed to forward SEND_LSP_NOTIFICATION message to language-server: {e}" ) ;
263279 } ) ;
264280 }
265- Orwie12Message :: SendLspNotificationToWebview ( notification) => {
281+ WebviewRouterMessage :: SendLspNotificationToWebview ( notification) => {
266282 tracing:: info!( "Received playground SEND_LSP_NOTIFICATION_TO_WEBVIEW request: {:?}" , notification) ;
267- let _ = reofji32_tx
268- . send ( Reofji32Message :: PlaygroundMessage (
283+ let _ = webview_router_to_websocket_tx
284+ . send ( WebviewNotification :: PlaygroundMessage (
269285 FrontendMessage :: lsp_message {
270286 method : notification. method ,
271287 params : notification. params ,
@@ -275,9 +291,9 @@ impl Server {
275291 tracing:: error!( "Failed to forward SEND_LSP_NOTIFICATION_TO_WEBVIEW message to webview: {e}" ) ;
276292 } ) ;
277293 }
278- Orwie12Message :: FrontendMessage ( msg) => {
279- let _ = reofji32_tx
280- . send ( Reofji32Message :: PlaygroundMessage ( msg) )
294+ WebviewRouterMessage :: FrontendMessage ( msg) => {
295+ let _ = webview_router_to_websocket_tx
296+ . send ( WebviewNotification :: PlaygroundMessage ( msg) )
281297 . inspect_err ( |e| {
282298 tracing:: error!( "Failed to forward FrontendMessage to playground: {e}" ) ;
283299 } ) ;
@@ -366,7 +382,7 @@ impl Server {
366382 & self . client_capabilities ,
367383 self . session ,
368384 self . worker_threads ,
369- self . args . reofji32_tx ,
385+ self . args . webview_router_to_websocket_tx ,
370386 ) ?;
371387 self . connection . close ( ) ?;
372388 Ok ( ( ) )
@@ -382,7 +398,7 @@ impl Server {
382398 _client_capabilities : & ClientCapabilities ,
383399 mut session : Session ,
384400 worker_threads : NonZeroUsize ,
385- reofji32_tx : broadcast:: Sender < Reofji32Message > ,
401+ webview_router_to_websocket_tx : broadcast:: Sender < WebviewNotification > ,
386402 ) -> anyhow:: Result < ( ) > {
387403 // Ensure we have a notifier for reload operations
388404 let client = client:: Client :: new ( connection. make_sender ( ) ) ;
@@ -398,7 +414,7 @@ impl Server {
398414 if connection. handle_shutdown ( & msg) ? {
399415 break ;
400416 }
401- // reofji32_tx .send(LangServerToWasmMessage::LspMessage(msg.clone()))?;
417+ // webview_router_to_websocket_tx .send(LangServerToWasmMessage::LspMessage(msg.clone()))?;
402418 let tasks = match msg {
403419 Message :: Request ( req) => vec ! [ api:: request( req) ] ,
404420 Message :: Notification ( notification) => api:: notification ( notification) ,
0 commit comments