add markers

pull/2780/head
filip mertens 2 years ago committed by yann300
parent 1ea9ebabaa
commit ff9f85fbcf
  1. 11
      apps/remix-ide/src/app/editor/editor.js
  2. 61
      libs/remix-ui/editor/src/lib/remix-ui-editor.tsx

@ -13,7 +13,7 @@ const profile = {
name: 'editor',
description: 'service - editor',
version: packageJson.version,
methods: ['highlight', 'discardHighlight', 'clearAnnotations', 'addLineText', 'discardLineTexts', 'addAnnotation', 'gotoLine', 'revealRange', 'getCursorPosition']
methods: ['highlight', 'discardHighlight', 'clearAnnotations', 'addLineText', 'discardLineTexts', '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:

@ -9,6 +9,8 @@ import { IMarkdownString } from 'monaco-editor'
import './remix-ui-editor.css'
import { loadTypes } from './web-types'
import monaco from '../types/monaco'
import { MarkerSeverity } from 'monaco-editor'
type cursorPosition = {
startLineNumber: number,
@ -91,6 +93,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
}
}
@ -381,6 +385,63 @@ export const EditorUI = (props: EditorUIProps) => {
return addDecoration(marker, filePath, typeOfDecoration)
}
props.editorAPI.addErrorMarker = async (errors: []) => {
const allMarkersPerfile: Record<string, Array<monaco.editor.IMarkerData>> = {}
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

Loading…
Cancel
Save