Skip to content

Commit

Permalink
add trace
Browse files Browse the repository at this point in the history
  • Loading branch information
Bao Zhiyuan committed Jan 2, 2025
1 parent 7c90cdb commit 01f13a9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 22 deletions.
2 changes: 1 addition & 1 deletion moonbit-tour/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"vite": "^6.0.1"
},
"dependencies": {
"@moonbit/moonpad-monaco": "^0.1.202412160",
"@moonbit/moonpad-monaco": "^0.1.202501023",
"monaco-editor-core": "^0.52.0"
}
}
19 changes: 15 additions & 4 deletions moonbit-tour/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const moon = moonbitMode.init({
onigWasmUrl: wasmUrl,
lspWorker: new lspWorker(),
mooncWorkerFactory: () => new mooncWorker(),
codeLensFilter(l) {
return !(l.command?.command === "moonbit-lsp/run-main");
},
});

// @ts-ignore
Expand Down Expand Up @@ -78,9 +81,12 @@ const model = monaco.editor.createModel(codePre.textContent ?? "", "moonbit");

const output = document.querySelector<HTMLPreElement>("#output")!;

async function run() {
async function run(debug: boolean) {
const content = model.getValue();
const result = await moon.compile({ libContents: [content] });
const result = await moon.compile({
libContents: [content],
debugMain: debug,
});
switch (result.kind) {
case "success": {
const js = result.js;
Expand All @@ -102,7 +108,7 @@ async function run() {
}
}

model.onDidChangeContent(debounce(run, 100));
model.onDidChangeContent(debounce(() => run(false), 100));

monaco.editor.onDidCreateEditor(() => {
codePre.remove();
Expand All @@ -125,6 +131,11 @@ monaco.editor.create(editor, {
alwaysConsumeMouseWheel: false,
},
fontFamily: "monospace",
theme: theme === "light" ? "light-plus" : "dark-plus",
});

monaco.editor.registerCommand("moonbit-lsp/debug-main", () => {
run(true);
});

run();
run(false);
5 changes: 5 additions & 0 deletions moonbit-tour/src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@
font-weight: 700;
src: url("../assets/fonts/inter-v18-latin-700italic.woff2") format("woff2"); /* Chrome 36+, Opera 23+, Firefox 39+, Safari 12+, iOS 10+ */
}

.moonbit-trace {
margin-left: 1rem;
color: #dc1894 !important;
}
34 changes: 17 additions & 17 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 01f13a9

Please sign in to comment.