pull/2774/head
bunsenstraat 2 years ago
parent 3e280d5ffa
commit 169e1bb700
  1. 84
      apps/remix-ide-e2e/src/tests/editor_error_marker.test.ts
  2. 53
      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 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' } }) loader.config({ paths: { vs: 'assets/js/monaco-editor/dev/vs' } })
export type DecorationsReturn = { export type DecorationsReturn = {
@ -352,20 +368,17 @@ export const EditorUI = (props: EditorUIProps) => {
return addDecoration(marker, filePath, typeOfDecoration) return addDecoration(marker, filePath, typeOfDecoration)
} }
props.editorAPI.addErrorMarker = async (errors: []) => { props.editorAPI.addErrorMarker = async (errors: errorMarker[]) => {
const allMarkersPerfile: Record<string, Array<monaco.editor.IMarkerData>> = {} const allMarkersPerfile: Record<string, Array<monaco.editor.IMarkerData>> = {}
console.log(errors)
for (const error of errors) { for (const error of errors) {
const marker = (error as any).error let filePath = error.file
const lineColumn = (error as any).lineColumn
let filePath = marker.sourceLocation.file
if (!filePath) return if (!filePath) return
const fileFromUrl = await props.plugin.call('fileManager', 'getPathFromUrl', filePath) const fileFromUrl = await props.plugin.call('fileManager', 'getPathFromUrl', filePath)
filePath = fileFromUrl.file filePath = fileFromUrl.file
const model = editorModelsState[filePath]?.model const model = editorModelsState[filePath]?.model
console.log(filePath)
const errorServerityMap = { const errorServerityMap = {
'error': MarkerSeverity.Error, 'error': MarkerSeverity.Error,
'warning': MarkerSeverity.Warning, 'warning': MarkerSeverity.Warning,
@ -373,14 +386,13 @@ export const EditorUI = (props: EditorUIProps) => {
} }
if (model) { if (model) {
const markerData: monaco.editor.IMarkerData = { const markerData: monaco.editor.IMarkerData = {
severity: errorServerityMap[marker.severity], severity: errorServerityMap[error.severity],
startLineNumber: ((lineColumn.start && lineColumn.start.line) || 0) + 1, startLineNumber: ((error.position.start && error.position.start.line) || 0),
startColumn: ((lineColumn.start && lineColumn.start.column) || 0) + 1, startColumn: ((error.position.start && error.position.start.column) || 0),
endLineNumber: ((lineColumn.end && lineColumn.end.line) || 0) + 1, endLineNumber: ((error.position.end && error.position.end.line) || 0),
endColumn: ((lineColumn.end && lineColumn.end.column) || 0) + 1, endColumn: ((error.position.end && error.position.end.column) || 0),
message: marker.message, message: error.message,
} }
console.log(markerData)
if (!allMarkersPerfile[filePath]) { if (!allMarkersPerfile[filePath]) {
allMarkersPerfile[filePath] = [] allMarkersPerfile[filePath] = []
} }
@ -391,7 +403,6 @@ export const EditorUI = (props: EditorUIProps) => {
for (const filePath in allMarkersPerfile) { for (const filePath in allMarkersPerfile) {
const model = editorModelsState[filePath]?.model const model = editorModelsState[filePath]?.model
if (model) { if (model) {
console.log(model)
monacoRef.current.editor.setModelMarkers(model, 'remix-solidity', allMarkersPerfile[filePath]) monacoRef.current.editor.setModelMarkers(model, 'remix-solidity', allMarkersPerfile[filePath])
} }
} }
@ -463,7 +474,7 @@ export const EditorUI = (props: EditorUIProps) => {
} }
} }
function handleEditorDidMount (editor) { function handleEditorDidMount(editor) {
editorRef.current = editor editorRef.current = editor
defineAndSetTheme(monacoRef.current) defineAndSetTheme(monacoRef.current)
reducerListener(props.plugin, dispatch, monacoRef.current, editorRef.current, props.events) reducerListener(props.plugin, dispatch, monacoRef.current, editorRef.current, props.events)
@ -523,7 +534,7 @@ export const EditorUI = (props: EditorUIProps) => {
} }
} }
function handleEditorWillMount (monaco) { function handleEditorWillMount(monaco) {
monacoRef.current = monaco monacoRef.current = monaco
// Register a new language // Register a new language
monacoRef.current.languages.register({ id: 'remix-solidity' }) monacoRef.current.languages.register({ id: 'remix-solidity' })
@ -551,7 +562,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">
@ -559,9 +570,9 @@ export const EditorUI = (props: EditorUIProps) => {
hide={false} hide={false}
gotoLine={(line, column) => props.plugin.call('editor', 'gotoLine', line, column)} gotoLine={(line, column) => props.plugin.call('editor', 'gotoLine', line, column)}
openFile={(file) => props.plugin.call('fileManager', 'switchFile', file)} openFile={(file) => props.plugin.call('fileManager', 'switchFile', file)}
getLastCompilationResult={() => { return props.plugin.call('compilerArtefacts', 'getLastCompilationResult') } } getLastCompilationResult={() => { return props.plugin.call('compilerArtefacts', 'getLastCompilationResult') }}
offsetToLineColumn={(position, file, sources, asts) => { return props.plugin.call('offsetToLineColumnConverter', 'offsetToLineColumn', position, file, sources, asts) } } offsetToLineColumn={(position, file, sources, asts) => { return props.plugin.call('offsetToLineColumnConverter', 'offsetToLineColumn', position, file, sources, asts) }}
getCurrentFileName={() => { return props.plugin.call('fileManager', 'file') } } getCurrentFileName={() => { return props.plugin.call('fileManager', 'file') }}
onContextListenerChanged={(listener) => { props.plugin.on('contextualListener', 'contextChanged', listener) }} onContextListenerChanged={(listener) => { props.plugin.on('contextualListener', 'contextChanged', listener) }}
onCurrentFileChanged={(listener) => { props.plugin.on('fileManager', 'currentFileChanged', listener) }} onCurrentFileChanged={(listener) => { props.plugin.on('fileManager', 'currentFileChanged', listener) }}
referencesOf={(node: astNode) => { return props.plugin.call('contextualListener', 'referencesOf', node) }} referencesOf={(node: astNode) => { return props.plugin.call('contextualListener', 'referencesOf', node) }}

Loading…
Cancel
Save