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