Skip to content

Commit

Permalink
Merge pull request #121 from melange-re/playground/fix-onload-error-m…
Browse files Browse the repository at this point in the history
…arkers

playground: fix onload error markers
  • Loading branch information
jchavarri authored Oct 5, 2023
2 parents 4be989a + 3e092e2 commit b66011f
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions playground/src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,21 @@ const compile = (language, code) => {
}
};

function updateMarkers(monaco, editorRef, compilation) {
if (monaco && editorRef.current) {
const owner = "playground";
if (compilation?.problems) {
monaco.editor.setModelMarkers(
editorRef.current.getModel(),
owner,
compilation.problems.map(toMonaco)
);
} else {
monaco.editor.removeAllMarkers(owner);
}
}
}

function App() {
const defaultState = {
language: languageMap.OCaml,
Expand All @@ -488,8 +503,9 @@ function App() {

const editorRef = React.useRef(null);

function handleEditorDidMount(editor, _monaco) {
function handleEditorDidMount(editor, monaco) {
editorRef.current = editor;
updateMarkers(monaco, editorRef, compilation);
}

function clearLogs() {
Expand Down Expand Up @@ -578,19 +594,7 @@ function App() {
}, [monaco, compilation?.typeHints]);

React.useEffect(() => {
// or make sure that it exists by other ways
if (monaco && editorRef.current) {
const owner = "playground";
if (compilation?.problems) {
monaco.editor.setModelMarkers(
editorRef.current.getModel(),
owner,
compilation.problems.map(toMonaco)
);
} else {
monaco.editor.removeAllMarkers(owner);
}
}
updateMarkers(monaco, editorRef, compilation)
}, [monaco, compilation?.problems]);

React.useEffect(() => {
Expand Down

0 comments on commit b66011f

Please sign in to comment.