Skip to content

Commit 314c02d

Browse files
committed
clean up jetbrains a bit more
1 parent 3e4ae74 commit 314c02d

File tree

6 files changed

+90
-130
lines changed

6 files changed

+90
-130
lines changed

engine/playground-server/src/handlers/websocket_rpc.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,12 @@ pub async fn handle_rpc_websocket(ws: axum::extract::ws::WebSocket, state: AppSt
4242
let _ = ws_tx.send(Message::text(response.to_string())).await;
4343
}
4444
"GET_PLAYGROUND_PORT" => {
45-
let playground_port = state.playground_port;
46-
47-
tracing::info!("GET_PLAYGROUND_PORT: returning port={}", playground_port);
48-
4945
let response = serde_json::json!({
5046
"rpcMethod": "GET_PLAYGROUND_PORT",
5147
"rpcId": rpc_id,
52-
"data": { "port": playground_port }
48+
// NB(sam): even though this seems like a misnomer, it is not!!! GET_PLAYGROUND_PORT is meant to fetch
49+
// the proxy port for the playground and is just really poorly named.
50+
"data": { "port": state.proxy_port }
5351
});
5452
let _ = ws_tx.send(Message::text(response.to_string())).await;
5553
}

jetbrains/.run/Run Plugin in IDE.run.xml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
<configuration default="false" name="Run Plugin in IDE" type="GradleRunConfiguration" factoryName="Gradle">
33
<log_file alias="IDE logs" path="$PROJECT_DIR$/build/idea-sandbox/*/log/idea.log" show_all="true" />
44
<ExternalSystemSettings>
5+
<option name="env">
6+
<map>
7+
<entry key="VSCODE_DEBUG_MODE" value="true" />
8+
</map>
9+
</option>
510
<option name="executionName" />
611
<option name="externalProjectPath" value="$PROJECT_DIR$" />
712
<option name="externalSystemIdString" value="GRADLE" />
@@ -15,12 +20,6 @@
1520
</list>
1621
</option>
1722
<option name="vmOptions" value="-Didea.log.console.stdout.level=DEBUG" />
18-
<option name="envs">
19-
<map>
20-
<!-- NB(sam): ideally I'd set this in build.gradle.kts but couldn't figure out how -->
21-
<entry key="VSCODE_DEBUG_MODE" value="true" />
22-
</map>
23-
</option>
2423
</ExternalSystemSettings>
2524
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
2625
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.boundaryml.jetbrains_ext
2+
3+
object BamlIdeConfig {
4+
val isDebugMode: Boolean
5+
6+
init {
7+
val debugModeEnv = System.getenv("VSCODE_DEBUG_MODE")
8+
isDebugMode = debugModeEnv == "true"
9+
println("BamlIdeConfig: VSCODE_DEBUG_MODE=${debugModeEnv ?: "(unset)"}, isDebugMode=$isDebugMode")
10+
}
11+
12+
fun getPlaygroundUrl(port: Int): String {
13+
return "http://localhost:$port/"
14+
}
15+
}

jetbrains/src/main/kotlin/com/boundaryml/jetbrains_ext/BamlLanguageServer.kt

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,29 @@ import java.nio.file.Path
99
class BamlLanguageServer(private val project: Project) : OSProcessStreamConnectionProvider() {
1010

1111
init {
12-
// Kill any orphaned baml-cli processes before starting
13-
val pkillProcess = Runtime.getRuntime().exec("pkill -f target/debug/baml-cli")
14-
pkillProcess.waitFor()
15-
System.out.println("pkill'd the old baml-cli processes")
12+
val commandLine = if (BamlIdeConfig.isDebugMode) {
13+
// Kill any orphaned baml-cli processes before starting
14+
val pkillProcess = Runtime.getRuntime().exec("pkill -f target/debug/baml-cli")
15+
pkillProcess.waitFor()
16+
println("pkill'd the old baml-cli processes")
1617

17-
// UNCOMMENT FOR DEBUGGING LOCALLY
18-
// val commandLine = GeneralCommandLine(
19-
// Path.of(System.getProperty("user.home"),
20-
// "/Documents/boundary/baml-main/baml/engine/target/debug", "baml-cli").toString(), "lsp")
21-
// val commandLine = GeneralCommandLine(
22-
// "/Users/sam/baml4/engine/target/debug/baml-cli", "lsp"
23-
// )
24-
// .withEnvironment("RUST_BACKTRACE", "full")
25-
val commandLine = GeneralCommandLine(
26-
// "/Users/sam/baml4/engine/target/debug/baml-hot-reload", "lsp"
27-
"/Users/sam/baml4/engine/target/debug/baml-cli", "lsp"
28-
)
29-
.withEnvironment("RUST_BACKTRACE", "full")
30-
.withEnvironment("VSCODE_DEBUG_MODE", "true")
18+
// baml-hot-reload is implemented by recording and replaying stdin, but this may be buggy
19+
// if that happens, comment this out and just use `baml-cli` directly
20+
GeneralCommandLine("/Users/sam/baml4/engine/target/debug/baml-hot-reload", "lsp")
21+
.withEnvironment("RUST_BACKTRACE", "full")
22+
.withEnvironment("VSCODE_DEBUG_MODE", "true")
23+
// Commented debug option:
24+
// GeneralCommandLine("/Users/sam/baml4/engine/target/debug/baml-cli", "lsp")
25+
} else {
26+
// Production mode - use installed CLI from cache
27+
val cacheDir = Path.of(System.getProperty("user.home"), ".baml/jetbrains")
28+
val version = Files.readString(cacheDir.resolve("baml-cli-installed.txt")).trim()
29+
val (arch, platform, _) = BamlLanguageServerInstaller.getPlatformTriple()
30+
val exe = if (platform == "pc-windows-msvc") "baml-cli.exe" else "baml-cli"
31+
val cli = cacheDir.resolve("baml-cli-$version-$arch-$platform").resolve(exe)
32+
GeneralCommandLine(cli.toString(), "lsp")
33+
}
3134
super.setCommandLine(commandLine)
32-
33-
//
34-
// val cacheDir = Path.of(System.getProperty("user.home"), ".baml/jetbrains")
35-
// val version = Files.readString(cacheDir.resolve("baml-cli-installed.txt")).trim()
36-
//
37-
// val (arch, platform, _) = BamlLanguageServerInstaller.getPlatformTriple()
38-
// val exe = if (platform == "pc-windows-msvc") "baml-cli.exe" else "baml-cli"
39-
// val cli = cacheDir.resolve("baml-cli-$version-$arch-$platform").resolve(exe)
40-
//
41-
// super.setCommandLine(GeneralCommandLine(cli.toString(), "lsp"))
42-
4335
}
4436

4537
}

jetbrains/src/main/kotlin/com/boundaryml/jetbrains_ext/BamlLanguageServer2.kt

Lines changed: 0 additions & 47 deletions
This file was deleted.

jetbrains/src/main/kotlin/com/boundaryml/jetbrains_ext/BamlToolWindowFactory.kt

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -63,75 +63,78 @@ class BamlToolWindowFactory : ToolWindowFactory {
6363
loadHTML(PLACEHOLDER_HTML.trimIndent())
6464
}
6565

66-
// Create reload button
67-
val reloadButton = JButton("Reload").apply {
68-
addActionListener {
69-
val currentTime = java.time.LocalDateTime.now()
70-
val savedPort = project.getService(BamlGetPortService::class.java).port
71-
System.out.println("reload button clicked at ${currentTime}, port is ${savedPort}")
72-
if (savedPort != null) {
73-
browser.loadURL("http://localhost:$savedPort/")
74-
} else {
75-
browser.loadHTML("<p>Port not ready</p>")
66+
// Create control panel with conditional debug buttons
67+
val controlPanel = JPanel(FlowLayout(FlowLayout.RIGHT))
68+
69+
if (BamlIdeConfig.isDebugMode) {
70+
// Create reload button
71+
val reloadButton = JButton("Reload").apply {
72+
addActionListener {
73+
val currentTime = java.time.LocalDateTime.now()
74+
val savedPort = project.getService(BamlGetPortService::class.java).port
75+
System.out.println("reload button clicked at ${currentTime}, port is ${savedPort}")
76+
if (savedPort != null) {
77+
browser.loadURL(BamlIdeConfig.getPlaygroundUrl(savedPort))
78+
} else {
79+
browser.loadHTML("<p>Port not ready</p>")
80+
}
81+
System.out.println("finished loading")
7682
}
77-
System.out.println("finished loading")
7883
}
79-
}
8084

81-
// Create lorem ipsum button
82-
val loremButton = JButton("Lorem Ipsum").apply {
83-
addActionListener {
84-
val currentTime = java.time.LocalDateTime.now()
85-
System.out.println("lorem button clicked at ${currentTime}")
86-
browser.loadHTML("""
87-
<!DOCTYPE html>
88-
<html>
89-
<head><title>Lorem Ipsum</title></head>
90-
<body style="font-family: Arial, sans-serif; padding: 20px; color: white;">
91-
<h1>Lorem Ipsum</h1>
92-
<p><strong>Generated at:</strong> $currentTime</p>
93-
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
94-
</body>
95-
</html>
96-
""".trimIndent())
85+
// Create lorem ipsum button
86+
val loremButton = JButton("Lorem Ipsum").apply {
87+
addActionListener {
88+
val currentTime = java.time.LocalDateTime.now()
89+
System.out.println("lorem button clicked at ${currentTime}")
90+
browser.loadHTML("""
91+
<!DOCTYPE html>
92+
<html>
93+
<head><title>Lorem Ipsum</title></head>
94+
<body style="font-family: Arial, sans-serif; padding: 20px; color: white;">
95+
<h1>Lorem Ipsum</h1>
96+
<p><strong>Generated at:</strong> $currentTime</p>
97+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
98+
</body>
99+
</html>
100+
""".trimIndent())
101+
}
97102
}
98-
}
99103

100-
val openDevToolsButton = JButton("Open DevTools").apply {
101-
addActionListener {
102-
browser.openDevtools()
104+
val openDevToolsButton = JButton("Open DevTools").apply {
105+
addActionListener {
106+
browser.openDevtools()
107+
}
103108
}
104-
}
105-
// Create control panel with buttons
106-
val controlPanel = JPanel(FlowLayout(FlowLayout.RIGHT)).apply {
107-
add(reloadButton)
108-
add(loremButton)
109-
add(openDevToolsButton)
109+
110+
controlPanel.add(reloadButton)
111+
controlPanel.add(loremButton)
112+
controlPanel.add(openDevToolsButton)
110113
}
111114

112115
// Create main panel with controls and browser
113116
val mainPanel = JPanel(BorderLayout()).apply {
114-
add(controlPanel, BorderLayout.NORTH)
117+
if (BamlIdeConfig.isDebugMode) {
118+
add(controlPanel, BorderLayout.NORTH)
119+
}
115120
add(browser.component, BorderLayout.CENTER)
116121
}
117122

118123
// Create content with the main panel
119124
val content = ContentFactory.getInstance().createContent(mainPanel, null, false)
120125
toolWindow.contentManager.addContent(content)
121126

122-
System.out.println("sam asking BamlToolWindowFactory about startup");
123-
124127
val savedPort = project.getService(BamlGetPortService::class.java).port
125128
if (savedPort != null) {
126129
// LS was up before the tool-window opened
127-
browser.loadURL("http://localhost:$savedPort/")
130+
browser.loadURL(BamlIdeConfig.getPlaygroundUrl(savedPort))
128131
} else {
129132
// LS not ready yet wait for a port message
130133
val busConnection = project.messageBus.connect(toolWindow.disposable)
131134
busConnection.subscribe(
132135
BamlGetPortService.TOPIC,
133136
BamlGetPortService.Listener { port ->
134-
browser.loadURL("http://localhost:$port/")
137+
browser.loadURL(BamlIdeConfig.getPlaygroundUrl(port))
135138
busConnection.disconnect() // one-shot, avoid duplicates
136139
}
137140
)

0 commit comments

Comments
 (0)