editorcontextDummy
filip mertens 2 years ago
parent 41ac44b232
commit 270bd0b05b
  1. 6
      apps/remix-ide/src/app/editor/editor.js
  2. 22
      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', name: 'editor',
description: 'service - editor', description: 'service - editor',
version: packageJson.version, 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 { class Editor extends Plugin {
@ -523,6 +523,10 @@ class Editor extends Plugin {
this.api.addErrorMarker(error) this.api.addErrorMarker(error)
} }
async clearErrorMarkers(sources){
this.api.clearErrorMarkers(sources)
}
/** /**
* Add an annotation to the current session. * Add an annotation to the current session.
* An annotation has the following shape: * An annotation has the following shape:

@ -110,25 +110,29 @@ export class EditorContextListener extends Plugin {
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))
const allErrors = []
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)
let pos = helper.getPositionDetails(error.formattedMessage) let pos = helper.getPositionDetails(error.formattedMessage)
console.log('ERROR POS', pos) console.log('ERROR POS', pos)
const lineColumn = await this.call('offsetToLineColumnConverter', 'offsetToLineColumn', const lineColumn = await this.call('offsetToLineColumnConverter', 'offsetToLineColumn',
{ {
start: error.sourceLocation.start, start: error.sourceLocation.start,
length: error.sourceLocation.end - error.sourceLocation.start length: error.sourceLocation.end - error.sourceLocation.start
}, },
0, 0,
result.getSourceCode().sources, result.getSourceCode().sources,
result.getAsts()) null)
console.log('lineColumn', lineColumn) console.log('lineColumn', lineColumn)
allErrors.push({error, lineColumn}) allErrors.push({ error, lineColumn })
} }
await this.call('editor', 'addErrorMarker', allErrors) await this.call('editor', 'addErrorMarker', allErrors)
} else {
await this.call('editor', 'clearErrorMarkers', result.getSourceCode().sources)
} }
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
this.lastCompilationResult = new CompilerAbstract('soljson', data, source, input) this.lastCompilationResult = new CompilerAbstract('soljson', data, source, input)

@ -31,11 +31,13 @@ export class OffsetToLineColumnConverter extends Plugin {
*/ */
offsetToLineColumn (rawLocation, file, sources, asts) { offsetToLineColumn (rawLocation, file, sources, asts) {
console.log('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)) {
// if we don't have ast, we process the only one available content (applicable also for compiler older than 0.4.12) // 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) this.lineBreakPositionsByContent[file] = this.sourceMappingDecoder.getLinebreakPositions(sources[sourcesArray[0]].content)
} else { } else {
for (const filename in asts) { for (const filename in asts) {
const source = asts[filename] 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]) return this.sourceMappingDecoder.convertOffsetToLineColumn(rawLocation, this.lineBreakPositionsByContent[file])
} }

@ -78,6 +78,7 @@ export interface EditorUIProps {
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: (errors: []) => void addErrorMarker: (errors: []) => void
clearErrorMarkers: (sources: {}) => 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
} }
@ -358,6 +359,7 @@ export const EditorUI = (props: EditorUIProps) => {
props.editorAPI.addErrorMarker = async (errors: []) => { props.editorAPI.addErrorMarker = async (errors: []) => {
let allMarkersPerfile: Record<string, Array<monaco.editor.IMarkerData>> = {}
for (const error of errors) { for (const error of errors) {
const marker = (error as any).error const marker = (error as any).error
const lineColumn = (error as any).lineColumn const lineColumn = (error as any).lineColumn
@ -367,6 +369,7 @@ export const EditorUI = (props: EditorUIProps) => {
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
if (model) { if (model) {
const markerData: monaco.editor.IMarkerData = { const markerData: monaco.editor.IMarkerData = {
severity: MarkerSeverity.Error, severity: MarkerSeverity.Error,
@ -375,10 +378,29 @@ export const EditorUI = (props: EditorUIProps) => {
endLineNumber: lineColumn.end.line + 1, endLineNumber: lineColumn.end.line + 1,
endColumn: lineColumn.end.column + 1, endColumn: lineColumn.end.column + 1,
message: marker.message, message: marker.message,
code: '21ji2j21ij21iji'
} }
console.log(markerData) 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