Skip to content

Commit 83b4992

Browse files
committed
fix jetbrains
1 parent 2bc6532 commit 83b4992

File tree

8 files changed

+65
-47
lines changed

8 files changed

+65
-47
lines changed

engine/language_server/src/server/api/requests/execute_command.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ impl SyncRequestHandler for ExecuteCommand {
7575
return Ok(None);
7676
}
7777

78+
tracing::info!("Executing command: {:?}", params);
7879
match RegisteredCommands::from_execute_command(params) {
7980
Err(e) => {
8081
return Err(crate::server::api::Error {
@@ -83,27 +84,31 @@ impl SyncRequestHandler for ExecuteCommand {
8384
});
8485
}
8586
Ok(RegisteredCommands::OpenBamlPanel(args)) => {
86-
session
87+
let tx = session
8788
.playground_tx
8889
.send(PreLangServerToWasmMessage::FrontendMessage(
8990
FrontendMessage::select_function {
9091
// TODO: this can't be correct... but it looks like it is
9192
root_path: args.project_id,
9293
function_name: args.function_name,
9394
},
94-
))
95-
.unwrap();
95+
));
96+
if let Err(e) = tx {
97+
tracing::warn!("Error forwarding OpenBamlPanel to playground: {}", e);
98+
}
9699
}
97100
Ok(RegisteredCommands::RunTest(args)) => {
98-
session
101+
let tx = session
99102
.playground_tx
100103
.send(PreLangServerToWasmMessage::FrontendMessage(
101104
FrontendMessage::run_test {
102105
function_name: args.function_name,
103106
test_name: args.test_case_name,
104107
},
105-
))
106-
.unwrap();
108+
));
109+
if let Err(e) = tx {
110+
tracing::warn!("Error forwarding RunTest to playground: {}", e);
111+
}
107112
}
108113
}
109114

engine/tools/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ name = "language-server-hot-reload"
88
path = "src/bin/language-server-hot-reload.rs"
99

1010
[dependencies]
11-
notify-debouncer-full = "0.3"
12-
tokio.workspace = true
1311
anyhow.workspace = true
12+
notify-debouncer-full = "0.3"
13+
tokio = { workspace = true, features = ["full"] }
1414
tracing.workspace = true
1515
tracing-subscriber.workspace = true

engine/tools/src/bin/language-server-hot-reload.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use tokio::{
2121
use tracing::{info, warn};
2222
use tracing_subscriber::{EnvFilter, FmtSubscriber};
2323

24-
const BINARY_PATH: &str = "/Users/sam/baml4/engine/target/debug/baml-cli";
2524
const MAX_STDIN_BUFFER_SIZE: usize = 1000;
2625

2726
#[derive(Clone, Debug)]
@@ -41,7 +40,7 @@ impl HotReloader {
4140
fn new() -> Self {
4241
let (shutdown_tx, _) = watch::channel(false);
4342
Self {
44-
binary_path: BINARY_PATH.to_string(),
43+
binary_path: format!("{}/../target/debug/baml-cli", env!("CARGO_MANIFEST_DIR")),
4544
current_process: None,
4645
shutdown_tx,
4746
stdin_buffer: Arc::new(Mutex::new(VecDeque::new())),

integ-tests/baml_src/test-files/functions/input/named-args/single/named-video.baml

Lines changed: 1 addition & 29 deletions
Large diffs are not rendered by default.

jetbrains/build.gradle.kts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,31 @@ tasks {
149149
runIde {
150150
args = listOf("${layout.projectDirectory}/../integ-tests/baml_src")
151151
}
152+
153+
// Configure trusted paths to avoid security prompts in development
154+
prepareSandbox {
155+
val integTestsPath = layout.projectDirectory.dir("../integ-tests").asFile.absolutePath
156+
val bamlSrcPath = layout.projectDirectory.dir("../integ-tests/baml_src").asFile.absolutePath
157+
158+
doLast {
159+
val trustedPathsFile = sandboxConfigDirectory.file("options/trusted-paths.xml").get().asFile
160+
trustedPathsFile.parentFile.mkdirs()
161+
trustedPathsFile.writeText(
162+
"""
163+
<application>
164+
<component name="Trusted.Paths">
165+
<option name="TRUSTED_PROJECT_PATHS">
166+
<map>
167+
<entry key="$integTestsPath" value="true" />
168+
<entry key="$bamlSrcPath" value="true" />
169+
</map>
170+
</option>
171+
</component>
172+
</application>
173+
""".trimIndent()
174+
)
175+
}
176+
}
152177
}
153178

154179
intellijPlatformTesting {

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ import java.nio.file.Path
88

99
class BamlLanguageServer(private val project: Project) : OSProcessStreamConnectionProvider() {
1010

11+
private fun findBamlWorkspaceRoot(startPath: Path): Path? {
12+
var current = startPath
13+
while (current.parent != null) {
14+
if (Files.exists(current.resolve("engine/Cargo.toml"))) {
15+
return current
16+
}
17+
current = current.parent
18+
}
19+
return null
20+
}
21+
1122
init {
1223
val commandLine = if (BamlIdeConfig.isDebugMode) {
1324
// Kill any orphaned baml-cli processes before starting
@@ -17,8 +28,13 @@ class BamlLanguageServer(private val project: Project) : OSProcessStreamConnecti
1728

1829
// baml-hot-reload is implemented by recording and replaying stdin, but this may be buggy
1930
// if that happens, comment this out and just use `baml-cli` directly
20-
GeneralCommandLine("/Users/sam/baml4/engine/target/debug/baml-hot-reload", "lsp")
31+
val projectBasePath = project.basePath ?: throw RuntimeException("Project base path not found")
32+
val workspaceRoot = findBamlWorkspaceRoot(Path.of(projectBasePath)) ?: throw RuntimeException("BAML workspace root not found")
33+
val hotReloadPath = workspaceRoot.resolve("engine/target/debug/language-server-hot-reload")
34+
GeneralCommandLine(hotReloadPath.toString(), "lsp")
2135
.withEnvironment("RUST_BACKTRACE", "full")
36+
.withEnvironment("BAML_INTERNAL_LOG", "debug")
37+
.withEnvironment("RUST_LOG", "debug")
2238
.withEnvironment("VSCODE_DEBUG_MODE", "true")
2339
// Commented debug option:
2440
// GeneralCommandLine("/Users/sam/baml4/engine/target/debug/baml-cli", "lsp")

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ import com.redhat.devtools.lsp4ij.commands.LSPCommandAction
55
import org.eclipse.lsp4j.ExecuteCommandParams
66
import com.redhat.devtools.lsp4ij.commands.LSPCommand
77
import com.intellij.openapi.actionSystem.AnActionEvent
8+
import com.intellij.openapi.diagnostic.logger
89

910
class BamlPlaygroundAction : LSPCommandAction() {
1011

1112
override fun commandPerformed(command: LSPCommand, e: AnActionEvent) {
1213
val project = e.project ?: return
1314
val toolWindow = ToolWindowManager.getInstance(project)
14-
.getToolWindow("BAML Playground")
15+
.getToolWindow("BAML Playground (beta)")
1516

1617
val args: List<Any> = command.arguments
1718

18-
toolWindow?.show {
19-
val ls = getLanguageServer(e)?.server ?: return@show
20-
ls.workspaceService.executeCommand(
21-
ExecuteCommandParams(command.command, command.arguments)
22-
)
23-
}
19+
toolWindow?.show()
20+
val ls = getLanguageServer(e)?.server
21+
ls?.workspaceService?.executeCommand(
22+
ExecuteCommandParams(command.command, command.arguments)
23+
)
2424
}
2525
}

jetbrains/src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
</actions>
3131

3232
<extensions defaultExtensionNs="com.intellij">
33+
<!-- When changing toolWindow.id, also make sure to change BamlPlaygroundAction.kt -->
3334
<toolWindow
3435
id="BAML Playground (beta)"
3536
factoryClass="com.boundaryml.jetbrains_ext.BamlToolWindowFactory"

0 commit comments

Comments
 (0)