|
|
|
@ -8,6 +8,7 @@ import { fileDecoration, fileDecorationType } from '@remix-ui/file-decorators' |
|
|
|
|
import { sourceMappingDecoder } from '@remix-project/remix-debug' |
|
|
|
|
import { CompilerRetriggerMode } from '@remix-project/remix-solidity-ts'; |
|
|
|
|
import { MarkerSeverity } from 'monaco-editor'; |
|
|
|
|
import { findLinesInStringWithMatch, SearchResultLine } from '@remix-ui/search' |
|
|
|
|
|
|
|
|
|
type errorMarker = { |
|
|
|
|
message: string |
|
|
|
@ -39,39 +40,49 @@ export default class CodeParserCompiler { |
|
|
|
|
init() { |
|
|
|
|
|
|
|
|
|
this.onAstFinished = async (success, data: CompilationResult, source: CompilationSource, input: any, version) => { |
|
|
|
|
//console.log('onAstFinished', success, data, source, input, version)
|
|
|
|
|
this.plugin.call('editor', 'clearAnnotations') |
|
|
|
|
this.errorState = true |
|
|
|
|
const result = new CompilerAbstract('soljson', data, source, input) |
|
|
|
|
let allErrors: errorMarker[] = [] |
|
|
|
|
if (data.errors) { |
|
|
|
|
const sources = result.getSourceCode().sources |
|
|
|
|
if (data.errors || data.error) { |
|
|
|
|
const file = await this.plugin.call('fileManager', 'getCurrentFile') |
|
|
|
|
const currentFileContent = await this.plugin.call('fileManager', 'readFile', file) |
|
|
|
|
const sources = result.getSourceCode().sources || [] |
|
|
|
|
if (data.error) { |
|
|
|
|
if (data.error.formattedMessage) { |
|
|
|
|
// mark this file as error
|
|
|
|
|
const errorMarker = await this.createErrorMarker(data.error, file, { start: { line: 0, column: 0 }, end: { line: 0, column: 100 } }) |
|
|
|
|
allErrors = [...allErrors, errorMarker] |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
for (const error of data.errors) { |
|
|
|
|
//console.log(error)
|
|
|
|
|
if (!error.sourceLocation) { |
|
|
|
|
// mark this file as error
|
|
|
|
|
const errorMarker = await this.createErrorMarker(error, file, { start: { line: 0, column: 0 }, end: { line: 0, column: 100 } }) |
|
|
|
|
allErrors = [...allErrors, errorMarker] |
|
|
|
|
} else { |
|
|
|
|
const lineBreaks = sourceMappingDecoder.getLinebreakPositions(sources[error.sourceLocation.file].content) |
|
|
|
|
const lineColumn = sourceMappingDecoder.convertOffsetToLineColumn({ |
|
|
|
|
start: error.sourceLocation.start, |
|
|
|
|
length: error.sourceLocation.end - error.sourceLocation.start |
|
|
|
|
}, lineBreaks) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const filePath = error.sourceLocation.file |
|
|
|
|
const fileTarget = await this.plugin.call('fileManager', 'getUrlFromPath', filePath) |
|
|
|
|
|
|
|
|
|
allErrors = [...allErrors, { |
|
|
|
|
message: error.formattedMessage, |
|
|
|
|
severity: error.severity === 'error' ? MarkerSeverity.Error : MarkerSeverity.Warning, |
|
|
|
|
position: { |
|
|
|
|
start: { |
|
|
|
|
line: ((lineColumn.start && lineColumn.start.line) || 0) + 1, |
|
|
|
|
column: ((lineColumn.start && lineColumn.start.column) || 0) + 1 |
|
|
|
|
}, |
|
|
|
|
end: { |
|
|
|
|
line: ((lineColumn.end && lineColumn.end.line) || 0) + 1, |
|
|
|
|
column: ((lineColumn.end && lineColumn.end.column) || 0) + 1 |
|
|
|
|
const importFilePositions = await this.getPositionForImportErrors(fileTarget.file, currentFileContent) |
|
|
|
|
for (const importFilePosition of importFilePositions) { |
|
|
|
|
for (const line of importFilePosition.lines) { |
|
|
|
|
allErrors = [...allErrors, await this.createErrorMarker(error, file, line.position)] |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
allErrors = [...allErrors, await this.createErrorMarker(error, filePath, lineColumn)] |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
, file: filePath |
|
|
|
|
}] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const displayErrors = await this.plugin.call('config', 'getAppParameter', 'display-errors') |
|
|
|
|
if (displayErrors) await this.plugin.call('editor', 'addErrorMarker', allErrors) |
|
|
|
|
this.addDecorators(allErrors, sources) |
|
|
|
@ -179,8 +190,9 @@ export default class CodeParserCompiler { |
|
|
|
|
const decorators: fileDecoration[] = [] |
|
|
|
|
for (const fileName in sortedErrorsPerFiles) { |
|
|
|
|
const errors = sortedErrorsPerFiles[fileName] |
|
|
|
|
const fileTarget = await this.plugin.call('fileManager', 'getPathFromUrl', fileName) |
|
|
|
|
const decorator: fileDecoration = { |
|
|
|
|
path: fileName, |
|
|
|
|
path: fileTarget.file, |
|
|
|
|
isDirectory: false, |
|
|
|
|
fileStateType: errors[0].severity == MarkerSeverity.Error ? fileDecorationType.Error : fileDecorationType.Warning, |
|
|
|
|
fileStateLabelClass: errors[0].severity == MarkerSeverity.Error ? 'text-danger' : 'text-warning', |
|
|
|
@ -194,8 +206,9 @@ export default class CodeParserCompiler { |
|
|
|
|
decorators.push(decorator) |
|
|
|
|
} |
|
|
|
|
for (const fileName of filesWithOutErrors) { |
|
|
|
|
const fileTarget = await this.plugin.call('fileManager', 'getPathFromUrl', fileName) |
|
|
|
|
const decorator: fileDecoration = { |
|
|
|
|
path: fileName, |
|
|
|
|
path: fileTarget.file, |
|
|
|
|
isDirectory: false, |
|
|
|
|
fileStateType: fileDecorationType.None, |
|
|
|
|
fileStateLabelClass: '', |
|
|
|
@ -212,6 +225,24 @@ export default class CodeParserCompiler { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async createErrorMarker(error: any, filePath: string, lineColumn): Promise<errorMarker> { |
|
|
|
|
return { |
|
|
|
|
message: error.formattedMessage, |
|
|
|
|
severity: error.severity === 'error' ? MarkerSeverity.Error : MarkerSeverity.Warning, |
|
|
|
|
position: { |
|
|
|
|
start: { |
|
|
|
|
line: ((lineColumn.start && lineColumn.start.line) || 0) + 1, |
|
|
|
|
column: ((lineColumn.start && lineColumn.start.column) || 0) + 1 |
|
|
|
|
}, |
|
|
|
|
end: { |
|
|
|
|
line: ((lineColumn.end && lineColumn.end.line) || 0) + 1, |
|
|
|
|
column: ((lineColumn.end && lineColumn.end.column) || 0) + 1 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
, file: filePath |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async clearDecorators(sources: any) { |
|
|
|
|
const decorators: fileDecoration[] = [] |
|
|
|
|
if (!sources) return |
|
|
|
@ -234,4 +265,13 @@ export default class CodeParserCompiler { |
|
|
|
|
await this.plugin.call('fileDecorator', 'setFileDecorators', decorators) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async getPositionForImportErrors(importedFileName: string, text: string) { |
|
|
|
|
const re = new RegExp(importedFileName, 'gi') |
|
|
|
|
const result: SearchResultLine[] = findLinesInStringWithMatch( |
|
|
|
|
text, |
|
|
|
|
re |
|
|
|
|
) |
|
|
|
|
return result |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |