editorcontextDummy
filip mertens 3 years ago
parent 41ac44b232
commit 270bd0b05b
  1. 6
      apps/remix-ide/src/app/editor/editor.js
  2. 10
      libs/remix-core-plugin/src/lib/editor-context-listener.ts
  3. 7
      libs/remix-core-plugin/src/lib/offset-line-to-column-converter.ts
  4. 26
      libs/remix-ui/editor/src/lib/remix-ui-editor.tsx

@ -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:

@ -110,8 +110,8 @@ export class EditorContextListener extends Plugin {
if (data.error) checkIfFatalError(data.error)
if (data.errors) data.errors.forEach((err) => checkIfFatalError(err))
if (data.errors) {
const allErrors = []
if (data.errors) {
for (const error of data.errors) {
console.log('ERROR POS', error)
let pos = helper.getPositionDetails(error.formattedMessage)
@ -123,12 +123,16 @@ export class EditorContextListener extends Plugin {
},
0,
result.getSourceCode().sources,
result.getAsts())
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)

@ -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])
}

@ -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<string, Array<monaco.editor.IMarkerData>> = {}
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', [])
}
}
}

Loading…
Cancel
Save