pull/5370/head
bunsenstraat 2 years ago
parent 0ac035b7ad
commit 12e40331eb
  1. 84
      apps/remix-ide-e2e/src/tests/editor_error_marker.test.ts
  2. 41
      libs/remix-ui/editor/src/lib/remix-ui-editor.tsx

@ -0,0 +1,84 @@
'use strict'
import { NightwatchBrowser } from 'nightwatch'
import init from '../helpers/init'
module.exports = {
before: function (browser: NightwatchBrowser, done: VoidFunction) {
init(browser, done, 'http://127.0.0.1:8080', true)
},
'Should add error marker': function (browser: NightwatchBrowser) {
browser
.openFile('contracts')
.openFile('contracts/1_Storage.sol')
.addFile('scripts/adderror.ts', {content: addErrorMarker})
.pause(4000)
.executeScriptInTerminal('remix.exeCurrent()')
.pause(4000)
.openFile('contracts/1_Storage.sol')
.useXpath()
.waitForElementVisible("//*[@class='cdr squiggly-error']")
.waitForElementVisible("//*[@class='cdr squiggly-warning']")
},
'Should clear error marker': function (browser: NightwatchBrowser) {
browser
.useCss()
.addFile('scripts/clear.ts', {content: clearMarkers})
.pause(4000)
.executeScriptInTerminal('remix.exeCurrent()')
.pause(4000)
.openFile('contracts/1_Storage.sol')
.useXpath()
.waitForElementNotPresent("//*[@class='cdr squiggly-error']")
.waitForElementNotPresent("//*[@class='cdr squiggly-warning']")
}
}
const clearMarkers =`
(async () => {
await remix.call('editor', 'clearErrorMarkers' as any, ['contracts/1_Storage.sol'])
})()`
const addErrorMarker = `
(async () => {
let errors = [
{
position: {
start: {
line: 10,
column: 1,
},
end: {
line: 10,
column: 10
}
},
message: 'testing',
severity: 'error',
file: 'contracts/1_Storage.sol'
},
{
position: {
start: {
line: 18,
column: 1,
},
end: {
line: 18,
column: 10
}
},
message: 'testing2',
severity: 'warning',
file: 'contracts/1_Storage.sol'
},
]
await remix.call('editor', 'addErrorMarker' as any, errors)
})()`

@ -42,6 +42,22 @@ type sourceMarker = {
hide: boolean
}
type errorMarker = {
message: string
severity: MarkerSeverity
position: {
start: {
line: number
column: number
},
end: {
line: number
column: number
}
},
file: string
}
loader.config({ paths: { vs: 'assets/js/monaco-editor/dev/vs' } })
export type DecorationsReturn = {
@ -352,20 +368,17 @@ export const EditorUI = (props: EditorUIProps) => {
return addDecoration(marker, filePath, typeOfDecoration)
}
props.editorAPI.addErrorMarker = async (errors: []) => {
props.editorAPI.addErrorMarker = async (errors: errorMarker[]) => {
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
let filePath = error.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,
@ -373,14 +386,13 @@ export const EditorUI = (props: EditorUIProps) => {
}
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)
severity: errorServerityMap[error.severity],
startLineNumber: ((error.position.start && error.position.start.line) || 0),
startColumn: ((error.position.start && error.position.start.column) || 0),
endLineNumber: ((error.position.end && error.position.end.line) || 0),
endColumn: ((error.position.end && error.position.end.column) || 0),
message: error.message,
}
if (!allMarkersPerfile[filePath]) {
allMarkersPerfile[filePath] = []
}
@ -391,7 +403,6 @@ export const EditorUI = (props: EditorUIProps) => {
for (const filePath in allMarkersPerfile) {
const model = editorModelsState[filePath]?.model
if (model) {
console.log(model)
monacoRef.current.editor.setModelMarkers(model, 'remix-solidity', allMarkersPerfile[filePath])
}
}

Loading…
Cancel
Save