engine/playground-server/README.md
This crate provides shared playground server infrastructure for BAML, eliminating code duplication between the language server and standalone playground implementations.
playground-server)The core library provides shared infrastructure for playground servers:
playground-barebones)A standalone test/repro server for testing playground functionality:
cargo run --bin playground-barebones
This binary:
The library eliminates ~800 lines of code duplication by extracting common patterns:
Before: After:
┌─────────────────┐ ┌──────────────────┐
│ language_server │ │ playground-server│
│ playground2/ │────────────▶│ (library) │
│ - server.rs │ │ │
│ - handlers/ │ └──────────────────┘
│ - types │ ▲
└─────────────────┘ │
│
┌─────────────────┐ │
│ barebones │ ┌─────────┴────────┐
│ - server.rs │────────────▶│playground-barebones│
│ - handlers/ │ │ (binary) │
│ - types │ └──────────────────┘
└─────────────────┘
use playground_server::{
PlaygroundServer, GitHubReleaseAssetManager,
AppState, PortConfiguration, pick_ports
};
let port_picks = pick_ports(PortConfiguration {
base_port: 3700,
max_attempts: 100,
}).await?;
let server = PlaygroundServer {
app_state: AppState { /* ... */ },
asset_manager: GitHubReleaseAssetManager {
github_repo: "BoundaryML/baml",
version_env_var: "CARGO_PKG_VERSION",
},
};
server.run(port_picks.playground_listener).await?;
The server is generic over message types and asset management:
impl<T, A> PlaygroundServer<T, A>
where
T: Send + Sync + Clone + serde::Serialize + 'static,
A: AssetManager + 'static,
{
pub async fn run(self, listener: TcpListener) -> Result<(), Box<dyn Error + Send>>
}
This allows different implementations to use:
playground2 integration with LSPplayground-barebones binary provides a minimal test environment