Skip to content

Commit fd81edc

Browse files
committed
Add error markers to the editor
1 parent 97f3158 commit fd81edc

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

packages/cxx-playground/src/abstract-syntax-tree.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,43 @@
1818
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
// SOFTWARE.
2020

21-
import { useContext, useState } from "react";
21+
import { useContext, useEffect, useState } from "react";
2222
import ASTContext from "./ast-context";
2323
import EditorContext from "./editor-context";
2424
import { SyntaxTree } from "./syntax-tree";
2525
import useDebouncedOnDidChangeCursorPosition from "./hooks/use-debounced-on-did-change-cursor-position";
26+
import * as monaco from "monaco-editor";
27+
import ModelContext from "./editor-model-context";
2628

2729
export default function AbstractSyntaxTree() {
2830
const { parser } = useContext(ASTContext);
2931
const { editor } = useContext(EditorContext);
32+
const { model } = useContext(ModelContext);
33+
3034
const [cursorPosition, setCursorPosition] = useState({ line: 1, column: 1 });
3135

36+
useEffect(() => {
37+
const markers: monaco.editor.IMarkerData[] = [];
38+
39+
const diagnostics = parser?.getDiagnostics() ?? [];
40+
41+
diagnostics.forEach(
42+
({ startLine, startColumn, endLine, endColumn, message }) => {
43+
markers.push({
44+
severity: monaco.MarkerSeverity.Error,
45+
startLineNumber: startLine,
46+
startColumn: startColumn,
47+
endLineNumber: endLine,
48+
endColumn: endColumn,
49+
message: message,
50+
source: "C++",
51+
});
52+
}
53+
);
54+
55+
monaco.editor.setModelMarkers(model, "cxx", markers);
56+
}, [model, parser]);
57+
3258
useDebouncedOnDidChangeCursorPosition({
3359
editor,
3460
onDidChangeCursorPosition: (editor, position) => {

0 commit comments

Comments
 (0)