diff --git a/apps/remix-ide/src/app/editor/editor.js b/apps/remix-ide/src/app/editor/editor.js index a4b8b2f0a7..554be0ae3e 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', 'open', 'addModel', 'addErrorMarker'] + methods: ['highlight', 'discardHighlight', 'clearAnnotations', 'addAnnotation', 'gotoLine', 'revealRange', 'getCursorPosition', 'open', 'addModel', 'addErrorMarker', 'clearErrorMarkers'] } class Editor extends Plugin { @@ -523,6 +523,10 @@ class Editor extends Plugin { this.api.addErrorMarker(error) } + async clearErrorMarkers(sources){ + this.api.clearErrorMarkers(sources) + } + /** * Add an annotation to the current session. * An annotation has the following shape: diff --git a/libs/remix-core-plugin/src/lib/editor-context-listener.ts b/libs/remix-core-plugin/src/lib/editor-context-listener.ts index 18054b15ec..ce1f86bcc9 100644 --- a/libs/remix-core-plugin/src/lib/editor-context-listener.ts +++ b/libs/remix-core-plugin/src/lib/editor-context-listener.ts @@ -110,25 +110,29 @@ export class EditorContextListener extends Plugin { if (data.error) checkIfFatalError(data.error) if (data.errors) data.errors.forEach((err) => checkIfFatalError(err)) + const allErrors = [] if (data.errors) { - const allErrors = [] for (const error of data.errors) { console.log('ERROR POS', error) let pos = helper.getPositionDetails(error.formattedMessage) console.log('ERROR POS', pos) const lineColumn = await this.call('offsetToLineColumnConverter', 'offsetToLineColumn', - { - start: error.sourceLocation.start, - length: error.sourceLocation.end - error.sourceLocation.start - }, - 0, - result.getSourceCode().sources, - result.getAsts()) + { + start: error.sourceLocation.start, + length: error.sourceLocation.end - error.sourceLocation.start + }, + 0, + result.getSourceCode().sources, + null) console.log('lineColumn', lineColumn) - allErrors.push({error, lineColumn}) + allErrors.push({ error, lineColumn }) } await this.call('editor', 'addErrorMarker', allErrors) + } else { + await this.call('editor', 'clearErrorMarkers', result.getSourceCode().sources) } + + if (!data.sources) return if (data.sources && Object.keys(data.sources).length === 0) return this.lastCompilationResult = new CompilerAbstract('soljson', data, source, input) diff --git a/libs/remix-core-plugin/src/lib/offset-line-to-column-converter.ts b/libs/remix-core-plugin/src/lib/offset-line-to-column-converter.ts index 76a2213a88..1dc883e7d3 100644 --- a/libs/remix-core-plugin/src/lib/offset-line-to-column-converter.ts +++ b/libs/remix-core-plugin/src/lib/offset-line-to-column-converter.ts @@ -31,11 +31,13 @@ export class OffsetToLineColumnConverter extends Plugin { */ offsetToLineColumn (rawLocation, file, sources, asts) { console.log('offsetToLineColumn', rawLocation, file, sources, asts) - if (!this.lineBreakPositionsByContent[file]) { + //if (!this.lineBreakPositionsByContent[file]) { const sourcesArray = Object.keys(sources) if (!asts || (file === 0 && sourcesArray.length === 1)) { // if we don't have ast, we process the only one available content (applicable also for compiler older than 0.4.12) + console.log('convert ', sources[sourcesArray[0]].content) this.lineBreakPositionsByContent[file] = this.sourceMappingDecoder.getLinebreakPositions(sources[sourcesArray[0]].content) + } else { for (const filename in asts) { const source = asts[filename] @@ -45,7 +47,8 @@ export class OffsetToLineColumnConverter extends Plugin { } } } - } + //} + console.log(this.lineBreakPositionsByContent[file]) return this.sourceMappingDecoder.convertOffsetToLineColumn(rawLocation, this.lineBreakPositionsByContent[file]) } 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 b0bc51aa76..70e27efa2d 100644 --- a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx +++ b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx @@ -78,6 +78,7 @@ export interface EditorUIProps { getHoverPosition: (position: IPosition) => number addDecoration: (marker: sourceMarker, filePath: string, typeOfDecoration: string) => DecorationsReturn addErrorMarker: (errors: []) => void + clearErrorMarkers: (sources: {}) => void clearDecorationsByPlugin: (filePath: string, plugin: string, typeOfDecoration: string, registeredDecorations: any, currentDecorations: any) => DecorationsReturn keepDecorationsFor: (filePath: string, plugin: string, typeOfDecoration: string, registeredDecorations: any, currentDecorations: any) => DecorationsReturn } @@ -358,6 +359,7 @@ export const EditorUI = (props: EditorUIProps) => { props.editorAPI.addErrorMarker = async (errors: []) => { + let allMarkersPerfile: Record> = {} for (const error of errors) { const marker = (error as any).error const lineColumn = (error as any).lineColumn @@ -367,6 +369,7 @@ export const EditorUI = (props: EditorUIProps) => { const fileFromUrl = await props.plugin.call('fileManager', 'getPathFromUrl', filePath) filePath = fileFromUrl.file const model = editorModelsState[filePath]?.model + if (model) { const markerData: monaco.editor.IMarkerData = { severity: MarkerSeverity.Error, @@ -375,10 +378,29 @@ export const EditorUI = (props: EditorUIProps) => { endLineNumber: lineColumn.end.line + 1, endColumn: lineColumn.end.column + 1, message: marker.message, - code: '21ji2j21ij21iji' } console.log(markerData) - monacoRef.current.editor.setModelMarkers(model, 'remix-solidity', [markerData]) + if (!allMarkersPerfile[filePath]) { + allMarkersPerfile[filePath] = [] + } + allMarkersPerfile[filePath].push(markerData) + } + } + for (const filePath in allMarkersPerfile) { + const model = editorModelsState[filePath]?.model + if (model) { + monacoRef.current.editor.setModelMarkers(model, 'remix-solidity', allMarkersPerfile[filePath]) + } + } + } + + props.editorAPI.clearErrorMarkers = async (sources: {}) => { + console.log('clear', sources) + for (const source of Object.keys(sources)) { + const filePath = source + const model = editorModelsState[filePath]?.model + if (model) { + monacoRef.current.editor.setModelMarkers(model, 'remix-solidity', []) } } }