From ac8addb0314e9ac39c186d905535923fddb752cc Mon Sep 17 00:00:00 2001 From: filip mertens Date: Thu, 21 Jul 2022 17:15:12 +0200 Subject: [PATCH] add markers --- apps/remix-ide/src/app/editor/editor.js | 11 +++- .../editor/src/lib/remix-ui-editor.tsx | 61 +++++++++++++++++++ package.json | 2 +- yarn.lock | 18 +++--- 4 files changed, 81 insertions(+), 11 deletions(-) diff --git a/apps/remix-ide/src/app/editor/editor.js b/apps/remix-ide/src/app/editor/editor.js index 97dc63f988..5c770a242c 100644 --- a/apps/remix-ide/src/app/editor/editor.js +++ b/apps/remix-ide/src/app/editor/editor.js @@ -13,7 +13,7 @@ const profile = { name: 'editor', description: 'service - editor', version: packageJson.version, - methods: ['highlight', 'discardHighlight', 'clearAnnotations', 'addAnnotation', 'gotoLine', 'revealRange', 'getCursorPosition'] + methods: ['highlight', 'discardHighlight', 'clearAnnotations', 'addAnnotation', 'gotoLine', 'revealRange', 'getCursorPosition','addErrorMarker', 'clearErrorMarkers'], } class Editor extends Plugin { @@ -504,6 +504,15 @@ class Editor extends Plugin { } } + // error markers + async addErrorMarker (error){ + this.api.addErrorMarker(error) + } + + async clearErrorMarkers(sources){ + this.api.clearErrorMarkers(sources) + } + /** * Clears all the annotations for the given @arg filePath, the plugin name is retrieved from the context, if none is given, the current sesssion is used. * An annotation has the following shape: diff --git a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx index 46a5e76d9b..1b1863a4da 100644 --- a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx +++ b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx @@ -7,6 +7,8 @@ import { cairoLang, cairoConf } from './cairoSyntax' import './remix-ui-editor.css' import { loadTypes } from './web-types' +import monaco from '../types/monaco' +import { MarkerSeverity } from 'monaco-editor' type cursorPosition = { startLineNumber: number, @@ -70,6 +72,8 @@ export interface EditorUIProps { addDecoration: (marker: sourceMarker, filePath: string, typeOfDecoration: string) => DecorationsReturn clearDecorationsByPlugin: (filePath: string, plugin: string, typeOfDecoration: string, registeredDecorations: any, currentDecorations: any) => DecorationsReturn keepDecorationsFor: (filePath: string, plugin: string, typeOfDecoration: string, registeredDecorations: any, currentDecorations: any) => DecorationsReturn + addErrorMarker: (errors: []) => void + clearErrorMarkers: (sources: any) => void } } @@ -346,6 +350,63 @@ export const EditorUI = (props: EditorUIProps) => { return addDecoration(marker, filePath, typeOfDecoration) } + props.editorAPI.addErrorMarker = async (errors: []) => { + + const allMarkersPerfile: Record> = {} + console.log(errors) + for (const error of errors) { + const marker = (error as any).error + const lineColumn = (error as any).lineColumn + let filePath = marker.sourceLocation.file + + if (!filePath) return + const fileFromUrl = await props.plugin.call('fileManager', 'getPathFromUrl', filePath) + filePath = fileFromUrl.file + const model = editorModelsState[filePath]?.model + console.log(filePath) + const errorServerityMap = { + 'error': MarkerSeverity.Error, + 'warning': MarkerSeverity.Warning, + 'info': MarkerSeverity.Info + } + if (model) { + const markerData: monaco.editor.IMarkerData = { + severity: errorServerityMap[marker.severity], + startLineNumber: ((lineColumn.start && lineColumn.start.line) || 0) + 1, + startColumn: ((lineColumn.start && lineColumn.start.column) || 0) + 1, + endLineNumber: ((lineColumn.end && lineColumn.end.line) || 0) + 1, + endColumn: ((lineColumn.end && lineColumn.end.column) || 0) + 1, + message: marker.message, + } + console.log(markerData) + if (!allMarkersPerfile[filePath]) { + allMarkersPerfile[filePath] = [] + } + allMarkersPerfile[filePath].push(markerData) + } + } + console.log(allMarkersPerfile) + for (const filePath in allMarkersPerfile) { + const model = editorModelsState[filePath]?.model + if (model) { + console.log(model) + monacoRef.current.editor.setModelMarkers(model, 'remix-solidity', allMarkersPerfile[filePath]) + } + } + } + + props.editorAPI.clearErrorMarkers = async (sources: any) => { + if (sources) { + for (const source of (Array.isArray(sources) ? sources : Object.keys(sources))) { + const filePath = source + const model = editorModelsState[filePath]?.model + if (model) { + monacoRef.current.editor.setModelMarkers(model, 'remix-solidity', []) + } + } + } + } + props.editorAPI.findMatches = (uri: string, value: string) => { if (!editorRef.current) return const model = editorModelsState[uri]?.model diff --git a/package.json b/package.json index 6faf18ebd2..9bef6c44d1 100644 --- a/package.json +++ b/package.json @@ -153,7 +153,7 @@ "@ethereumjs/vm": "^5.5.3", "@ethersphere/bee-js": "^3.2.0", "@isomorphic-git/lightning-fs": "^4.4.1", - "@monaco-editor/react": "^4.3.1", + "@monaco-editor/react": "4.4.5", "@remixproject/engine": "^0.3.31", "@remixproject/engine-web": "^0.3.31", "@remixproject/plugin": "^0.3.31", diff --git a/yarn.lock b/yarn.lock index 6bac163214..655bc648b9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3242,19 +3242,19 @@ npmlog "^4.1.2" write-file-atomic "^2.3.0" -"@monaco-editor/loader@^1.2.0": - version "1.2.0" - resolved "https://registry.yarnpkg.com/@monaco-editor/loader/-/loader-1.2.0.tgz#373fad69973384624e3d9b60eefd786461a76acd" - integrity sha512-cJVCG/T/KxXgzYnjKqyAgsKDbH9mGLjcXxN6AmwumBwa2rVFkwvGcUj1RJtD0ko4XqLqJxwqsN/Z/KURB5f1OQ== +"@monaco-editor/loader@^1.3.2": + version "1.3.2" + resolved "https://registry.yarnpkg.com/@monaco-editor/loader/-/loader-1.3.2.tgz#04effbb87052d19cd7d3c9d81c0635490f9bb6d8" + integrity sha512-BTDbpHl3e47r3AAtpfVFTlAi7WXv4UQ/xZmz8atKl4q7epQV5e7+JbigFDViWF71VBi4IIBdcWP57Hj+OWuc9g== dependencies: state-local "^1.0.6" -"@monaco-editor/react@^4.3.1": - version "4.3.1" - resolved "https://registry.yarnpkg.com/@monaco-editor/react/-/react-4.3.1.tgz#d65bcbf174c39b6d4e7fec43d0cddda82b70a12a" - integrity sha512-f+0BK1PP/W5I50hHHmwf11+Ea92E5H1VZXs+wvKplWUWOfyMa1VVwqkJrXjRvbcqHL+XdIGYWhWNdi4McEvnZg== +"@monaco-editor/react@4.4.5": + version "4.4.5" + resolved "https://registry.yarnpkg.com/@monaco-editor/react/-/react-4.4.5.tgz#beabe491efeb2457441a00d1c7651c653697f65b" + integrity sha512-IImtzU7sRc66OOaQVCG+5PFHkSWnnhrUWGBuH6zNmH2h0YgmAhcjHZQc/6MY9JWEbUtVF1WPBMJ9u1XuFbRrVA== dependencies: - "@monaco-editor/loader" "^1.2.0" + "@monaco-editor/loader" "^1.3.2" prop-types "^15.7.2" "@mrmlnc/readdir-enhanced@^2.2.1":