|
18 | 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
19 | 19 | // SOFTWARE. |
20 | 20 |
|
21 | | -import { useContext, useState } from "react"; |
| 21 | +import { useContext, useEffect, useState } from "react"; |
22 | 22 | import ASTContext from "./ast-context"; |
23 | 23 | import EditorContext from "./editor-context"; |
24 | 24 | import { SyntaxTree } from "./syntax-tree"; |
25 | 25 | 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"; |
26 | 28 |
|
27 | 29 | export default function AbstractSyntaxTree() { |
28 | 30 | const { parser } = useContext(ASTContext); |
29 | 31 | const { editor } = useContext(EditorContext); |
| 32 | + const { model } = useContext(ModelContext); |
| 33 | + |
30 | 34 | const [cursorPosition, setCursorPosition] = useState({ line: 1, column: 1 }); |
31 | 35 |
|
| 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 | + |
32 | 58 | useDebouncedOnDidChangeCursorPosition({ |
33 | 59 | editor, |
34 | 60 | onDidChangeCursorPosition: (editor, position) => { |
|
0 commit comments