Skip to content

Commit f938a40

Browse files
Mazyodclaude
andcommitted
feat: add GitHub Pages playground with Monaco editor and multi-backend support
Interactive playground supporting Pyright (CDN), Pyrefly (WASM), and ty (WASM) backends with diagnostics and hover. Includes GitHub Pages deployment workflow. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3de62b5 commit f938a40

17 files changed

Lines changed: 2367 additions & 0 deletions

.github/workflows/playground.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Deploy Playground
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "playground/**"
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: read
13+
pages: write
14+
id-token: write
15+
16+
concurrency:
17+
group: "pages"
18+
cancel-in-progress: true
19+
20+
jobs:
21+
build:
22+
runs-on: ubuntu-latest
23+
defaults:
24+
run:
25+
working-directory: playground
26+
steps:
27+
- uses: actions/checkout@v4
28+
29+
- uses: actions/setup-node@v4
30+
with:
31+
node-version: 20
32+
cache: npm
33+
cache-dependency-path: playground/package-lock.json
34+
35+
- run: npm ci
36+
- run: npm run build
37+
38+
- uses: actions/upload-pages-artifact@v3
39+
with:
40+
path: playground/dist
41+
42+
deploy:
43+
needs: build
44+
runs-on: ubuntu-latest
45+
environment:
46+
name: github-pages
47+
url: ${{ steps.deployment.outputs.page_url }}
48+
steps:
49+
- id: deployment
50+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,8 @@ pyrightconfig.json
244244
.ionide
245245

246246
# End of https://www.toptal.com/developers/gitignore/api/linux,macos,python,visualstudiocode
247+
248+
# Playground
249+
playground/node_modules/
250+
playground/dist/
251+
playground/wasm/

playground/fetch-wasm.sh

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env bash
2+
# Fetches pre-built WASM modules for Pyrefly and ty from their GitHub releases.
3+
# Run this before `npm run dev` if you want Pyrefly or ty backends.
4+
set -euo pipefail
5+
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
WASM_DIR="${SCRIPT_DIR}/wasm"
8+
9+
# --- Pyrefly ---
10+
# Build from source using wasm-pack (requires Rust toolchain)
11+
fetch_pyrefly() {
12+
local dir="${WASM_DIR}/pyrefly"
13+
mkdir -p "$dir"
14+
15+
if [ -f "$dir/pyrefly_wasm_bg.wasm" ]; then
16+
echo "Pyrefly WASM already exists, skipping."
17+
return
18+
fi
19+
20+
echo "Building Pyrefly WASM from source..."
21+
local tmpdir
22+
tmpdir=$(mktemp -d)
23+
trap 'rm -rf "$tmpdir"' RETURN
24+
25+
git clone --depth=1 https://github.com/facebook/pyrefly.git "$tmpdir/pyrefly"
26+
cd "$tmpdir/pyrefly/pyrefly_wasm"
27+
28+
if ! command -v wasm-pack &>/dev/null; then
29+
echo "Installing wasm-pack..."
30+
cargo install wasm-pack
31+
fi
32+
33+
wasm-pack build --target web --out-dir "$dir" --no-typescript
34+
echo "Pyrefly WASM built successfully."
35+
}
36+
37+
# --- ty ---
38+
# Build from source using wasm-pack (requires Rust toolchain)
39+
fetch_ty() {
40+
local dir="${WASM_DIR}/ty"
41+
mkdir -p "$dir"
42+
43+
if [ -f "$dir/ty_wasm_bg.wasm" ]; then
44+
echo "ty WASM already exists, skipping."
45+
return
46+
fi
47+
48+
echo "Building ty WASM from source..."
49+
local tmpdir
50+
tmpdir=$(mktemp -d)
51+
trap 'rm -rf "$tmpdir"' RETURN
52+
53+
git clone --depth=1 https://github.com/astral-sh/ruff.git "$tmpdir/ruff"
54+
cd "$tmpdir/ruff"
55+
56+
if ! command -v wasm-pack &>/dev/null; then
57+
echo "Installing wasm-pack..."
58+
cargo install wasm-pack
59+
fi
60+
61+
wasm-pack build --target web crates/ty_wasm --out-dir "$dir" --no-typescript
62+
echo "ty WASM built successfully."
63+
}
64+
65+
echo "=== Fetching WASM modules ==="
66+
echo ""
67+
68+
case "${1:-all}" in
69+
pyrefly)
70+
fetch_pyrefly
71+
;;
72+
ty)
73+
fetch_ty
74+
;;
75+
all)
76+
fetch_pyrefly
77+
fetch_ty
78+
;;
79+
*)
80+
echo "Usage: $0 [pyrefly|ty|all]"
81+
exit 1
82+
;;
83+
esac
84+
85+
echo ""
86+
echo "Done! WASM modules are in ${WASM_DIR}/"

playground/index.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>LSP Python Types — Playground</title>
7+
<link rel="stylesheet" href="/src/style.css" />
8+
</head>
9+
<body>
10+
<div id="app">
11+
<header id="header">
12+
<h1>LSP Python Types</h1>
13+
<div id="backend-selector"></div>
14+
<div id="status"></div>
15+
</header>
16+
<div id="editor-container"></div>
17+
</div>
18+
<script type="module" src="/src/main.ts"></script>
19+
</body>
20+
</html>

0 commit comments

Comments
 (0)