error markers

pull/5370/head
filip mertens 3 years ago
parent d76e5a0eb7
commit cd0c128d5d
  1. 2
      apps/remix-ide/src/app/editor/editor.js
  2. 23
      libs/remix-core-plugin/src/lib/editor-context-listener.ts
  3. 1
      libs/remix-core-plugin/src/lib/offset-line-to-column-converter.ts
  4. 52
      libs/remix-ui/editor/src/lib/remix-ui-editor.tsx

@ -165,7 +165,7 @@ class Editor extends Plugin {
} }
} }
} }
if (name === this.currentFile) { if (name !== this.currentFile) {
this.currentFile = name this.currentFile = name
this.renderComponent() this.renderComponent()
} }

@ -4,8 +4,8 @@ import { sourceMappingDecoder } from '@remix-project/remix-debug'
import { CompilerAbstract } from '@remix-project/remix-solidity' import { CompilerAbstract } from '@remix-project/remix-solidity'
import { Compiler } 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 = { const profile = {
@ -104,13 +104,30 @@ export class EditorContextListener extends Plugin {
noFatalErrors = false noFatalErrors = false
} }
} }
const result = new CompilerAbstract('soljson', data, source, input)
if (data.error) checkIfFatalError(data.error) if (data.error) checkIfFatalError(data.error)
if (data.errors) data.errors.forEach((err) => checkIfFatalError(err)) if (data.errors) data.errors.forEach((err) => checkIfFatalError(err))
if (data.errors) { if (data.errors) {
const allErrors = []
for (const error of data.errors) { for (const error of data.errors) {
console.log('ERROR POS', error) 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) return
if (data.sources && Object.keys(data.sources).length === 0) return if (data.sources && Object.keys(data.sources).length === 0) return

@ -30,6 +30,7 @@ export class OffsetToLineColumnConverter extends Plugin {
* @param {Object.<string, {ast, id}>} asts - Map of content sources * @param {Object.<string, {ast, id}>} asts - Map of content sources
*/ */
offsetToLineColumn (rawLocation, file, sources, asts) { 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) const sourcesArray = Object.keys(sources)
if (!asts || (file === 0 && sourcesArray.length === 1)) { if (!asts || (file === 0 && sourcesArray.length === 1)) {

@ -77,7 +77,7 @@ export interface EditorUIProps {
getCursorPosition: () => cursorPosition getCursorPosition: () => cursorPosition
getHoverPosition: (position: IPosition) => number getHoverPosition: (position: IPosition) => number
addDecoration: (marker: sourceMarker, filePath: string, typeOfDecoration: string) => DecorationsReturn 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 clearDecorationsByPlugin: (filePath: string, plugin: string, typeOfDecoration: string, registeredDecorations: any, currentDecorations: any) => DecorationsReturn
keepDecorationsFor: (filePath: string, plugin: string, typeOfDecoration: string, registeredDecorations: any, currentDecorations: any) => DecorationsReturn keepDecorationsFor: (filePath: string, plugin: string, typeOfDecoration: string, registeredDecorations: any, currentDecorations: any) => DecorationsReturn
} }
@ -356,32 +356,30 @@ export const EditorUI = (props: EditorUIProps) => {
return addDecoration(marker, filePath, typeOfDecoration) return addDecoration(marker, filePath, typeOfDecoration)
} }
props.editorAPI.addErrorMarker = async (marker: CompilationError) => { props.editorAPI.addErrorMarker = async (errors: []) => {
console.log(editorModelsState) for (const error of errors) {
let filePath = marker.sourceLocation.file const marker = (error as any).error
console.log(filePath) const lineColumn = (error as any).lineColumn
if (!filePath) return let filePath = marker.sourceLocation.file
const fileFromUrl = await props.plugin.call('fileManager', 'getPathFromUrl', filePath)
filePath = fileFromUrl.file if (!filePath) return
const model = editorModelsState[filePath]?.model const fileFromUrl = await props.plugin.call('fileManager', 'getPathFromUrl', filePath)
if (model) { filePath = fileFromUrl.file
console.log(model) const model = editorModelsState[filePath]?.model
const markerData: monaco.editor.IMarkerData = { if (model) {
severity: MarkerSeverity.Error, const markerData: monaco.editor.IMarkerData = {
startLineNumber: 1, severity: MarkerSeverity.Error,
startColumn: 1, startLineNumber: lineColumn.start.line + 1,
endLineNumber: 1, startColumn: lineColumn.start.column + 1,
endColumn: 2, endLineNumber: lineColumn.end.line + 1,
message: marker.message, endColumn: lineColumn.end.column + 1,
code: '21ji2j21ij21iji' 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({}))
} }
} }
@ -510,7 +508,7 @@ export const EditorUI = (props: EditorUIProps) => {
language={editorModelsState[props.currentFile] ? editorModelsState[props.currentFile].language : 'text'} language={editorModelsState[props.currentFile] ? editorModelsState[props.currentFile].language : 'text'}
onMount={handleEditorDidMount} onMount={handleEditorDidMount}
beforeMount={handleEditorWillMount} beforeMount={handleEditorWillMount}
options={{ glyphMargin: true, readOnly: true}} options={{ glyphMargin: true, readOnly: true }}
defaultValue={defaultEditorValue} defaultValue={defaultEditorValue}
/> />
<div className="contextview"> <div className="contextview">

Loading…
Cancel
Save