Skip to content

Commit 5004774

Browse files
committed
move demo
1 parent 4a64c4f commit 5004774

10 files changed

Lines changed: 16 additions & 112 deletions

File tree

CNAME

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
clangd.guyutongxue.site
1+
clangd.cpp.social

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ RUN pnpm install --frozen-lockfile --prefer-offline
2626
COPY --chown=node:node . .
2727

2828
ENV NODE_ENV=development
29-
EXPOSE 4173 4174 4175 4176
29+
EXPOSE 4173
3030

3131
USER node
3232
CMD ["pnpm", "dev", "--host", "0.0.0.0"]

README.md

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ The renderer creates text nodes and styled spans rather than injecting HTML. The
9696

9797
Status events have a `type` of `monaco-loading`, `monaco-ready`, `clangd-downloading`, `clangd-starting`, `clangd-ready`, or `clangd-error`. Download events also contain `loaded` and, when the server provides it, `total` bytes.
9898

99-
See [demo/index.html](demo/index.html), [demo/demo.js](demo/demo.js), and [demo/demo.css](demo/demo.css) for a complete framework-free highlighted fallback editor, seamless handoff, ANSI-aware Run output, and Compiler Explorer link. The demo's **Show fallback / Show Monaco** toggle recreates the fallback on demand for visual comparison; the normal one-way startup handoff still removes and cleans up the fallback.
100-
10199
## Headers
102100

103101
The host document must be cross-origin isolated for clangd's SharedArrayBuffer/pthread build:
@@ -161,29 +159,6 @@ Install an existing artifact directory or archive with:
161159

162160
The input must contain `clangd.js`, `clangd.wasm`, and any other `clangd*` files produced by Emscripten. `build.sh` remains a separate manual reference workflow and is not invoked by `pnpm build` or CI.
163161

164-
## Cross-origin demo and tests
165-
166-
Build first, then start all acceptance origins:
167-
168-
```bash
169-
pnpm build
170-
pnpm demo:origins
171-
```
172-
173-
- `http://localhost:4173` serves the demo host with COOP/COEP.
174-
- `http://localhost:4174` serves runtime assets with CORS/CORP.
175-
- `http://localhost:4175` serves the same runtime at `/assets/clangd/` for same-origin testing.
176-
- `http://localhost:4176` serves a non-isolated host for graceful-degradation testing.
177-
178-
Run the Chromium acceptance suite with:
179-
180-
```bash
181-
pnpm exec playwright install chromium
182-
pnpm test:browser
183-
```
184-
185-
The tests cover immediate fallback editing and Run, delayed runtime/WASM, edit-preserving handoff, DOM ownership, cross-origin isolation and worker startup, real clangd diagnostics, failure behavior, and same-origin extraction layout.
186-
187162
## Compiler Explorer Run UI
188163

189164
Compilation is intentionally a host concern. The demo keeps an `activeEditor.getValue()` abstraction that initially reads the textarea and later points to Monaco, then sends that source directly to the Compiler Explorer API. This makes Run independent of both Monaco and clangd readiness.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
"type": "module",
66
"scripts": {
77
"clean": "vite-node --config ./scripts/vite.node.ts ./scripts/clean.ts",
8-
"dev": "pnpm build && pnpm demo:origins",
8+
"dev": "pnpm build",
99
"watch": "tsc -w",
1010
"build": "pnpm run clean && tsc && vite build && node scripts/copy-runtime-assets.mjs",
1111
"pack:runtime": "pnpm build && bash scripts/package-runtime.sh",
12-
"demo:origins": "node scripts/serve-demo.mjs",
1312
"test:browser": "playwright test"
1413
},
1514
"devDependencies": {

playwright.config.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.
File renamed without changes.

demo/demo.js renamed to public/demo.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ const initialFallbackHost = document.querySelector("[data-fallback]");
99
const initialTextarea = initialFallbackHost.querySelector("textarea");
1010

1111
const params = new URLSearchParams(location.search);
12-
const editorUrl = params.get("runtime") ??
13-
(location.port === "4175"
14-
? "/assets/clangd/editor.js"
15-
: `http://localhost:4174/editor.js${params.get("delay") ? `?delay=${params.get("delay")}` : ""}`);
12+
const editorUrl = params.get("runtime") ?? "./editor.js";
1613
const runtimeBase = new URL(".", new URL(editorUrl, location.href));
1714
const editorModulePromise = import(editorUrl);
1815
const fallbackModulePromise = import(new URL("fallback.js", runtimeBase));
@@ -138,7 +135,11 @@ try {
138135
}
139136
if (event.type === "clangd-starting") status.textContent = "Starting clangd...";
140137
if (event.type === "clangd-ready") status.textContent = "Monaco + clangd ready";
141-
if (event.type === "clangd-error") status.textContent = "Monaco ready - clangd unavailable";
138+
if (event.type === "clangd-error"){
139+
status.textContent = "Monaco ready - clangd unavailable";
140+
console.error(event);
141+
}
142+
142143
},
143144
});
144145

demo/index.html renamed to public/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
<body>
1010
<main>
1111
<p class="eyebrow">C++ - Monaco - clangd</p>
12-
<h1>Edit and run C++ in the browser</h1>
13-
<p class="intro">The native editor is ready now. Monaco and clangd upgrade it in the background.</p>
12+
<h1>Code blocks with clangd support</h1>
13+
<p class="intro">The simple fallback editor is ready immediately. Monaco and clangd upgrade it in the background.</p>
14+
<p class="intro">This is intended to be used on <a href="https://cpp.social">cpp.social</a>, but if you find use for this please do reach out. This tool is based on Guyutongxue's excellent work in <a href="https://github.com/guyutongxue/clangd-in-browser/">guyutongxue/clangd-in-browser</a>.</p>
1415

1516
<section class="cpp-demo" aria-label="C++ editor demo">
1617
<div class="editor-shell">

scripts/copy-runtime-assets.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ for (const name of ["clangd.js", "clangd.wasm"]) {
1616
await mkdir(destination, { recursive: true });
1717
await cp(source, destination, { recursive: true, filter: (path) => !path.endsWith(".gitignore") });
1818
await cp(new URL("public/_headers", root), new URL("dist/_headers", root));
19+
20+
await cp(new URL("public/demo.css", root), new URL("dist/demo.css", root));
21+
await cp(new URL("public/demo.js", root), new URL("dist/demo.js", root));
22+
await cp(new URL("public/index.html", root), new URL("dist/index.html", root));

scripts/serve-demo.mjs

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

0 commit comments

Comments
 (0)