diff --git a/apps/remix-ide/src/app/editor/editor.js b/apps/remix-ide/src/app/editor/editor.js index 8b6abbb8bd..a4b8b2f0a7 100644 --- a/apps/remix-ide/src/app/editor/editor.js +++ b/apps/remix-ide/src/app/editor/editor.js @@ -165,7 +165,7 @@ class Editor extends Plugin { } } } - if (name === this.currentFile) { + if (name !== this.currentFile) { this.currentFile = name this.renderComponent() } 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 d66f026013..18054b15ec 100644 --- a/libs/remix-core-plugin/src/lib/editor-context-listener.ts +++ b/libs/remix-core-plugin/src/lib/editor-context-listener.ts @@ -4,8 +4,8 @@ import { sourceMappingDecoder } from '@remix-project/remix-debug' import { CompilerAbstract } from '@remix-project/remix-solidity' import { Compiler } from '@remix-project/remix-solidity' -import { helper } from '@remix-project/remix-solidity' -import type { CompilationError, CompilationResult, CompilationSource } from '@remix-project/remix-solidity-ts' + +import { CompilationError, CompilationResult, CompilationSource, helper } from '@remix-project/remix-solidity-ts' const profile = { @@ -104,13 +104,30 @@ export class EditorContextListener extends Plugin { noFatalErrors = false } } + const result = new CompilerAbstract('soljson', data, source, input) + + + if (data.error) checkIfFatalError(data.error) if (data.errors) data.errors.forEach((err) => checkIfFatalError(err)) if (data.errors) { + const allErrors = [] for (const error of data.errors) { console.log('ERROR POS', error) - await this.call('editor', 'addErrorMarker', 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()) + console.log('lineColumn', lineColumn) + allErrors.push({error, lineColumn}) } + await this.call('editor', 'addErrorMarker', allErrors) } if (!data.sources) return if (data.sources && Object.keys(data.sources).length === 0) return 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 b6e02bbcdd..76a2213a88 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 @@ -30,6 +30,7 @@ export class OffsetToLineColumnConverter extends Plugin { * @param {Object.} asts - Map of content sources */ offsetToLineColumn (rawLocation, file, sources, asts) { + console.log('offsetToLineColumn', rawLocation, file, sources, asts) if (!this.lineBreakPositionsByContent[file]) { const sourcesArray = Object.keys(sources) if (!asts || (file === 0 && sourcesArray.length === 1)) { 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 f433dd7595..b0bc51aa76 100644 --- a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx +++ b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx @@ -77,7 +77,7 @@ export interface EditorUIProps { getCursorPosition: () => cursorPosition getHoverPosition: (position: IPosition) => number addDecoration: (marker: sourceMarker, filePath: string, typeOfDecoration: string) => DecorationsReturn - addErrorMarker: (error: CompilationError) => void + addErrorMarker: (errors: []) => 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 } @@ -266,7 +266,7 @@ export const EditorUI = (props: EditorUIProps) => { } else if (file.language === 'cairo') { monacoRef.current.editor.setModelLanguage(file.model, 'remix-cairo') } - + }, [props.currentFile]) const convertToMonacoDecoration = (decoration: sourceAnnotation | sourceMarker, typeOfDecoration: string) => { @@ -356,32 +356,30 @@ export const EditorUI = (props: EditorUIProps) => { return addDecoration(marker, filePath, typeOfDecoration) } - props.editorAPI.addErrorMarker = async (marker: CompilationError) => { - - console.log(editorModelsState) - let filePath = marker.sourceLocation.file - console.log(filePath) - if (!filePath) return - const fileFromUrl = await props.plugin.call('fileManager', 'getPathFromUrl', filePath) - filePath = fileFromUrl.file - const model = editorModelsState[filePath]?.model - if (model) { - console.log(model) - const markerData: monaco.editor.IMarkerData = { - severity: MarkerSeverity.Error, - startLineNumber: 1, - startColumn: 1, - endLineNumber: 1, - endColumn: 2, - message: marker.message, - code: '21ji2j21ij21iji' + props.editorAPI.addErrorMarker = async (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 + if (model) { + const markerData: monaco.editor.IMarkerData = { + severity: MarkerSeverity.Error, + startLineNumber: lineColumn.start.line + 1, + startColumn: lineColumn.start.column + 1, + 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]) } - console.log(markerData) - monacoRef.current.editor.colorizeModelLine(model,1) - monacoRef.current.editor.colorizeModelLine(model,2) - console.log(monacoRef.current.editor.getModels()) - monacoRef.current.editor.setModelMarkers(model, 'remix-solidity', [markerData]) - console.log(monacoRef.current.editor.getModelMarkers({})) } } @@ -467,7 +465,7 @@ export const EditorUI = (props: EditorUIProps) => { }) } - function handleEditorWillMount(monaco: Monaco) { + function handleEditorWillMount(monaco: Monaco) { console.log('editor will mount', monaco, typeof monaco) monacoRef.current = monaco // Register a new language @@ -510,7 +508,7 @@ export const EditorUI = (props: EditorUIProps) => { language={editorModelsState[props.currentFile] ? editorModelsState[props.currentFile].language : 'text'} onMount={handleEditorDidMount} beforeMount={handleEditorWillMount} - options={{ glyphMargin: true, readOnly: true}} + options={{ glyphMargin: true, readOnly: true }} defaultValue={defaultEditorValue} />