Skip to content

Commit 0efb169

Browse files
authored
feat(jetbrains): get closer to feature parity with vscode (#2447)
We're not stable yet, but this lands enough functionality that I want to checkpoint the work done before going more invasive. See https://www.notion.so/gloochat/shipping-jetbrains-248bb2d26216808dac33caafd344a676?source=copy_link. - set up patterns for webview->IDE and IDE->webview communication - rudimentary aws/gcp cred loading implementations - upgrade js-sys, web-sys, etc because google-cloud-auth exists (as of last week!) and requires it - jumpToFile now goes via controlled interface that separates its implementation from its contract
1 parent 11a131f commit 0efb169

42 files changed

Lines changed: 1365 additions & 407 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎engine/Cargo.lock‎

Lines changed: 279 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎engine/Cargo.toml‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ eventsource-stream = "0.2.3"
8484
expect-test = "1.5.0"
8585
filetime = "0.2.25"
8686
futures = { version = "0.3.30", features = ["executor"] }
87+
google-cloud-auth = "1.0.0"
8788
http = "1.1.0"
8889
http-body = "1.0.0"
8990
indexmap = { version = "2.1.0", features = ["serde"] }
@@ -161,13 +162,28 @@ pin-project-lite = "0.2.14"
161162
url = "2.5.2"
162163
uuid = { version = "1.8.0", features = ["v4", "v7", "serde"] }
163164
walkdir = "2.5.0"
164-
wasm-bindgen-test = "0.3.45"
165-
web-time = "1.1.0"
166165
tokio = { version = "1", default-features = false, features = [
167166
"macros",
168167
"time",
169168
] }
170169

170+
js-sys = "=0.3.78"
171+
wasm-bindgen = "=0.2.101"
172+
wasm-bindgen-futures = "0.4.42"
173+
wasm-bindgen-test = "0.3.45"
174+
web-sys = { version = "0.3.78", features = [
175+
"Crypto",
176+
"CryptoKey",
177+
"Headers",
178+
"Request",
179+
"RequestInit",
180+
"Response",
181+
"RequestMode",
182+
"SubtleCrypto",
183+
"Window",
184+
] }
185+
web-time = "1.1.0"
186+
171187
[workspace.package]
172188
version = "0.207.1"
173189
authors = ["Boundary <contact@boundaryml.com>"]

‎engine/baml-lsp-types/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal-baml-codegen.workspace = true
2121
internal-baml-core.workspace = true
2222
jsonish = { path = "../baml-lib/jsonish" }
2323
internal-llm-client = { path = "../baml-lib/llm-client" }
24-
js-sys = "=0.3.69"
24+
js-sys.workspace = true
2525
log.workspace = true
2626
serde.workspace = true
2727
serde_json.workspace = true

‎engine/baml-runtime/Cargo.toml‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ colored = { workspace = true, default-features = false, features = [
142142
"no-color",
143143
] }
144144
futures-timer = { version = "3.0.3", features = ["wasm-bindgen"] }
145-
js-sys = "=0.3.69"
145+
js-sys.workspace = true
146146
reqwest = { version = "0.12.12", features = [
147147
"stream",
148148
"json",
@@ -157,17 +157,7 @@ uuid = { workspace = true, features = ["v4", "serde", "js"] }
157157
# It may produce a dependency cycle in projects that use wasm and import baml.
158158
wasm-bindgen = "^0.2.74"
159159
wasm-bindgen-futures = "0.4"
160-
web-sys = { version = "0.3.69", features = [
161-
"Crypto",
162-
"CryptoKey",
163-
"Headers",
164-
"Request",
165-
"RequestInit",
166-
"Response",
167-
"RequestMode",
168-
"SubtleCrypto",
169-
"Window",
170-
] }
160+
web-sys.workspace = true
171161
wasmtimer = "0.4.1"
172162
tokio = { version = "1", features = ["rt", "sync"] }
173163

‎engine/baml-schema-wasm/Cargo.toml‎

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ internal-baml-codegen.workspace = true
3939
internal-baml-core.workspace = true
4040
jsonish = { path = "../baml-lib/jsonish" }
4141
internal-llm-client = { path = "../baml-lib/llm-client" }
42-
js-sys = "=0.3.69"
42+
js-sys.workspace = true
4343
log.workspace = true
4444
serde.workspace = true
4545
serde_json.workspace = true
@@ -48,28 +48,15 @@ time.workspace = true
4848
tokio = { workspace = true, features = ["sync"] }
4949
url.workspace = true
5050
uuid = { workspace = true, features = ["v4", "js"] }
51-
wasm-bindgen = "=0.2.92"
52-
wasm-bindgen-futures = "0.4.42"
51+
wasm-bindgen.workspace = true
52+
wasm-bindgen-futures.workspace = true
5353
wasm-logger = { version = "0.2.0" }
54+
web-sys.workspace = true
5455
web-time.workspace = true
5556
either = "1.8.1"
5657
itertools = "0.13.0"
5758
once_cell.workspace = true
5859
stream-cancel = "0.8"
59-
[dependencies.web-sys]
60-
version = "0.3.69"
61-
features = [
62-
'console',
63-
'Headers',
64-
'Request',
65-
'RequestInit',
66-
'RequestMode',
67-
'Response',
68-
'Window',
69-
'AbortSignal',
70-
'EventTarget',
71-
'Event',
72-
]
7360

7461
[dev-dependencies]
7562
dissimilar = "1.0.4"

‎engine/language_server/src/lib.rs‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::num::NonZeroUsize;
22

33
use anyhow::Context;
44
pub use edit::{DocumentKey, PositionEncoding, TextDocument};
5-
use playground_server::{LangServerToWasmMessage, PreLangServerToWasmMessage};
5+
use playground_server::{WebviewNotification, WebviewRouterMessage};
66
pub use session::{ClientSettings, DocumentQuery, DocumentSnapshot, Session};
77
use tokio::sync::broadcast;
88

@@ -34,8 +34,8 @@ pub(crate) fn version() -> &'static str {
3434
pub fn run_server() -> anyhow::Result<()> {
3535
let tokio_runtime = tokio::runtime::Runtime::new()?;
3636

37-
let (broadcast_tx, broadcast_rx) = broadcast::channel(1000);
38-
let (playground_tx, playground_rx) = broadcast::channel(1000);
37+
let (webview_router_to_websocket_tx, webview_router_to_websocket_rx) = broadcast::channel(1000);
38+
let (to_webview_router_tx, to_webview_router_rx) = broadcast::channel(1000);
3939

4040
let port_config = playground_server::PortConfiguration {
4141
base_port: 3700,
@@ -44,16 +44,24 @@ pub fn run_server() -> anyhow::Result<()> {
4444
let port_picks = tokio_runtime.block_on(playground_server::pick_ports(port_config))?;
4545

4646
{
47-
let playground_tx = playground_tx.clone();
47+
let webview_router_to_websocket_tx = webview_router_to_websocket_tx.clone();
48+
let to_webview_router_tx = to_webview_router_tx.clone();
4849
tokio_runtime.spawn(futures::future::join(
4950
async move {
5051
eprintln!("Playground server started");
5152
let server = playground_server::PlaygroundServer {
5253
app_state: playground_server::AppState {
53-
broadcast_rx,
54-
playground_tx: playground_tx.clone(),
54+
webview_router_to_websocket_rx,
55+
to_webview_router_tx: to_webview_router_tx.clone(),
5556
playground_port: port_picks.playground_port,
5657
proxy_port: port_picks.proxy_port,
58+
editor_config: std::sync::Arc::new(std::sync::RwLock::new(
59+
playground_server::config::EditorConfig::default(),
60+
)),
61+
file_access: playground_server::fs::WorkspaceFileAccess::new(vec![
62+
std::env::current_dir()
63+
.unwrap_or_else(|_| std::path::PathBuf::from(".")),
64+
]),
5765
},
5866
};
5967
let fut = server.run(port_picks.playground_listener).await;
@@ -84,9 +92,9 @@ pub fn run_server() -> anyhow::Result<()> {
8492
worker_threads,
8593
ServerArgs {
8694
tokio_runtime,
87-
broadcast_tx,
88-
playground_rx,
89-
playground_tx: playground_tx.clone(),
95+
webview_router_to_websocket_tx,
96+
to_webview_router_rx,
97+
to_webview_router_tx: to_webview_router_tx.clone(),
9098
playground_port: port_picks.playground_port,
9199
proxy_port: port_picks.proxy_port,
92100
},

‎engine/language_server/src/server.rs‎

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ use lsp_types::{
1919
TextDocumentSyncKind, TextDocumentSyncOptions, TextDocumentSyncSaveOptions, Url,
2020
WorkspaceClientCapabilities, WorkspaceFoldersServerCapabilities, WorkspaceServerCapabilities,
2121
};
22-
use playground_server::{FrontendMessage, LangServerToWasmMessage, PreLangServerToWasmMessage};
22+
use playground_server::{FrontendMessage, WebviewNotification, WebviewRouterMessage};
2323
use schedule::Task;
2424
use serde::{Deserialize, Serialize};
25+
use serde_json::json;
2526
use tokio::sync::{broadcast, RwLock};
2627

2728
use self::{
@@ -48,9 +49,9 @@ pub type Result<T> = std::result::Result<T, api::Error>;
4849

4950
pub(crate) struct ServerArgs {
5051
pub tokio_runtime: tokio::runtime::Runtime,
51-
pub broadcast_tx: broadcast::Sender<LangServerToWasmMessage>,
52-
pub playground_rx: broadcast::Receiver<PreLangServerToWasmMessage>,
53-
pub playground_tx: broadcast::Sender<PreLangServerToWasmMessage>,
52+
pub webview_router_to_websocket_tx: broadcast::Sender<WebviewNotification>,
53+
pub to_webview_router_rx: broadcast::Receiver<WebviewRouterMessage>,
54+
pub to_webview_router_tx: broadcast::Sender<WebviewRouterMessage>,
5455
pub playground_port: u16,
5556
pub proxy_port: u16,
5657
}
@@ -175,7 +176,7 @@ impl Server {
175176
global_settings,
176177
&workspaces,
177178
args.playground_port,
178-
args.playground_tx.clone(),
179+
args.to_webview_router_tx.clone(),
179180
client_version,
180181
)?;
181182

@@ -194,7 +195,6 @@ impl Server {
194195

195196
{
196197
let lsp_sender = server.connection.make_sender();
197-
let playground_tx = server.session.playground_tx.clone();
198198
server.args.tokio_runtime.spawn(async move {
199199
lsp_sender
200200
.send(Message::Notification(lsp_server::Notification::new(
@@ -208,15 +208,32 @@ impl Server {
208208
});
209209
}
210210
{
211-
let mut playground_rx = server.args.playground_rx.resubscribe();
212-
let broadcast_tx = server.args.broadcast_tx.clone();
211+
// Start the webview router loop
212+
//
213+
// This is the communication bridge between the webview and IDE in non-VSCode environments
214+
// and allows the webview to send messages to Jetbrains and allows Jetbrains to send messages
215+
// to the webview.
216+
//
217+
// webview->IDE is generally backed by the webview POSTing to /webview/SEND_LSP_NOTIFICATION_TO_IDE,
218+
// and the language server will then forward that to the IDE
219+
// IDE->webview is generally backed by the IDE calling POST /webview/SEND_LSP_NOTIFICATION_TO_WEBVIEW,
220+
// and the language server will then forward that to the webview
221+
//
222+
// (Note that although the language-server pretends to offer a request-response API, it does not
223+
// block on either the IDE or webview responding before responding to its caller.)
224+
//
225+
// Incoming messages are received via to_webview_router_tx, which the router will then decide to
226+
// dispatch to either the webview (via its websocket) or the IDE (via its LSP connection).
227+
let lsp_sender = server.connection.make_sender();
228+
let mut to_webview_router_rx = server.args.to_webview_router_rx.resubscribe();
229+
let webview_router_to_websocket_tx = server.args.webview_router_to_websocket_tx.clone();
213230
let session = server.session.clone();
214231
server.args.tokio_runtime.spawn(async move {
215232
tracing::info!("Starting playground rx loop");
216-
while let Ok(msg) = playground_rx.recv().await {
233+
while let Ok(msg) = to_webview_router_rx.recv().await {
217234
tracing::info!("playground rx loop: {:?}", msg);
218235
match msg {
219-
PreLangServerToWasmMessage::WasmIsInitialized => {
236+
WebviewRouterMessage::WasmIsInitialized => {
220237
tracing::info!("Received playground INITIALIZED request");
221238
let projects = session.baml_src_projects.lock();
222239
for (_, project) in projects.iter() {
@@ -237,8 +254,8 @@ impl Server {
237254
(key, contents)
238255
})
239256
.collect();
240-
broadcast_tx
241-
.send(LangServerToWasmMessage::PlaygroundMessage(
257+
let _ = webview_router_to_websocket_tx
258+
.send(WebviewNotification::PlaygroundMessage(
242259
FrontendMessage::add_project {
243260
root_path: project
244261
.root_path()
@@ -247,13 +264,38 @@ impl Server {
247264
files: files_map,
248265
},
249266
))
250-
.unwrap();
267+
.inspect_err(|e| {
268+
tracing::error!("Failed to forward add_project to playground: {e}");
269+
});
251270
}
252271
}
253-
PreLangServerToWasmMessage::FrontendMessage(msg) => {
254-
broadcast_tx
255-
.send(LangServerToWasmMessage::PlaygroundMessage(msg))
256-
.unwrap();
272+
WebviewRouterMessage::SendLspNotificationToIde(notification) => {
273+
tracing::info!("Received playground SEND_LSP_NOTIFICATION request: {:?}", notification);
274+
let _ = lsp_sender
275+
.send(Message::Notification(notification))
276+
.inspect_err(|e| {
277+
tracing::error!("Failed to forward SEND_LSP_NOTIFICATION message to language-server: {e}");
278+
});
279+
}
280+
WebviewRouterMessage::SendLspNotificationToWebview(notification) => {
281+
tracing::info!("Received playground SEND_LSP_NOTIFICATION_TO_WEBVIEW request: {:?}", notification);
282+
let _ = webview_router_to_websocket_tx
283+
.send(WebviewNotification::PlaygroundMessage(
284+
FrontendMessage::lsp_message {
285+
method: notification.method,
286+
params: notification.params,
287+
},
288+
))
289+
.inspect_err(|e| {
290+
tracing::error!("Failed to forward SEND_LSP_NOTIFICATION_TO_WEBVIEW message to webview: {e}");
291+
});
292+
}
293+
WebviewRouterMessage::CustomNotificationToWebview(msg) => {
294+
let _ = webview_router_to_websocket_tx
295+
.send(WebviewNotification::PlaygroundMessage(msg))
296+
.inspect_err(|e| {
297+
tracing::error!("Failed to forward FrontendMessage to playground: {e}");
298+
});
257299
}
258300
}
259301
}
@@ -339,7 +381,7 @@ impl Server {
339381
&self.client_capabilities,
340382
self.session,
341383
self.worker_threads,
342-
self.args.broadcast_tx,
384+
self.args.webview_router_to_websocket_tx,
343385
)?;
344386
self.connection.close()?;
345387
Ok(())
@@ -355,7 +397,7 @@ impl Server {
355397
_client_capabilities: &ClientCapabilities,
356398
mut session: Session,
357399
worker_threads: NonZeroUsize,
358-
broadcast_tx: broadcast::Sender<LangServerToWasmMessage>,
400+
webview_router_to_websocket_tx: broadcast::Sender<WebviewNotification>,
359401
) -> anyhow::Result<()> {
360402
// Ensure we have a notifier for reload operations
361403
let client = client::Client::new(connection.make_sender());
@@ -371,7 +413,7 @@ impl Server {
371413
if connection.handle_shutdown(&msg)? {
372414
break;
373415
}
374-
// broadcast_tx.send(LangServerToWasmMessage::LspMessage(msg.clone()))?;
416+
// webview_router_to_websocket_tx.send(LangServerToWasmMessage::LspMessage(msg.clone()))?;
375417
let tasks = match msg {
376418
Message::Request(req) => vec![api::request(req)],
377419
Message::Notification(notification) => api::notification(notification),

‎engine/language_server/src/server/api/notifications/did_change.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{collections::HashMap, time::Instant};
33
use lsp_types::{
44
notification::DidChangeTextDocument, DidChangeTextDocumentParams, PublishDiagnosticsParams,
55
};
6-
use playground_server::{FrontendMessage, PreLangServerToWasmMessage};
6+
use playground_server::{FrontendMessage, WebviewRouterMessage};
77

88
use crate::{
99
server::{
@@ -84,8 +84,8 @@ impl SyncNotificationHandler for DidChangeTextDocumentHandler {
8484
})
8585
.collect();
8686
session
87-
.playground_tx
88-
.send(PreLangServerToWasmMessage::FrontendMessage(
87+
.to_webview_router_tx
88+
.send(WebviewRouterMessage::CustomNotificationToWebview(
8989
FrontendMessage::add_project {
9090
root_path: project.root_path().to_string_lossy().to_string(),
9191
files: files_map,

‎engine/language_server/src/server/api/requests/code_action.rs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ impl SyncRequestHandler for CodeActionHandler {
3030
_requester: &mut Requester,
3131
params: CodeActionParams,
3232
) -> Result<Option<Vec<CodeActionOrCommand>>> {
33+
// TODO: this is the only way to do this in zed i think
34+
// tracing::info!("CodeActionHandler running");
35+
// let _ = session
36+
// .webview_router_to_websocket_tx
37+
// .send(
38+
// playground_server::LangServerToWasmMessage::PlaygroundMessage(
39+
// playground_server::FrontendMessage::lsp_message {
40+
// method: "textDocument/codeAction".to_string(),
41+
// params: serde_json::to_value(&params).unwrap(),
42+
// },
43+
// ),
44+
// )
45+
// .inspect_err(|e| {
46+
// tracing::error!("Failed to send codeAction notification to playground: {e}");
47+
// });
48+
3349
let mut actions = vec![];
3450

3551
let uri = params.text_document.uri.clone();

0 commit comments

Comments
 (0)