|
|
@ -8,22 +8,23 @@ 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 |
|
|
|
severity: MarkerSeverity |
|
|
|
severity: MarkerSeverity |
|
|
|
position: { |
|
|
|
position: { |
|
|
|
start: { |
|
|
|
start: { |
|
|
|
line: number |
|
|
|
line: number |
|
|
|
column: number |
|
|
|
column: number |
|
|
|
}, |
|
|
|
}, |
|
|
|
end: { |
|
|
|
end: { |
|
|
|
line: number |
|
|
|
line: number |
|
|
|
column: number |
|
|
|
column: number |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
file: string |
|
|
|
file: string |
|
|
|
} |
|
|
|
} |
|
|
|
export default class CodeParserCompiler { |
|
|
|
export default class CodeParserCompiler { |
|
|
|
plugin: CodeParser |
|
|
|
plugin: CodeParser |
|
|
|
compiler: any // used to compile the current file seperately from the main compiler
|
|
|
|
compiler: any // used to compile the current file seperately from the main compiler
|
|
|
@ -39,41 +40,51 @@ 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') |
|
|
|
for (const error of data.errors) { |
|
|
|
const currentFileContent = await this.plugin.call('fileManager', 'readFile', file) |
|
|
|
//console.log(error)
|
|
|
|
const sources = result.getSourceCode().sources || [] |
|
|
|
const lineBreaks = sourceMappingDecoder.getLinebreakPositions(sources[error.sourceLocation.file].content) |
|
|
|
if (data.error) { |
|
|
|
const lineColumn = sourceMappingDecoder.convertOffsetToLineColumn({ |
|
|
|
if (data.error.formattedMessage) { |
|
|
|
start: error.sourceLocation.start, |
|
|
|
// mark this file as error
|
|
|
|
length: error.sourceLocation.end - error.sourceLocation.start |
|
|
|
const errorMarker = await this.createErrorMarker(data.error, file, { start: { line: 0, column: 0 }, end: { line: 0, column: 100 } }) |
|
|
|
}, lineBreaks) |
|
|
|
allErrors = [...allErrors, errorMarker] |
|
|
|
|
|
|
|
} |
|
|
|
const filePath = error.sourceLocation.file |
|
|
|
} else { |
|
|
|
|
|
|
|
for (const error of data.errors) { |
|
|
|
allErrors = [...allErrors, { |
|
|
|
if (!error.sourceLocation) { |
|
|
|
message: error.formattedMessage, |
|
|
|
// mark this file as error
|
|
|
|
severity: error.severity === 'error' ? MarkerSeverity.Error : MarkerSeverity.Warning, |
|
|
|
const errorMarker = await this.createErrorMarker(error, file, { start: { line: 0, column: 0 }, end: { line: 0, column: 100 } }) |
|
|
|
position: { |
|
|
|
allErrors = [...allErrors, errorMarker] |
|
|
|
start: { |
|
|
|
} else { |
|
|
|
line: ((lineColumn.start && lineColumn.start.line) || 0) + 1, |
|
|
|
const lineBreaks = sourceMappingDecoder.getLinebreakPositions(sources[error.sourceLocation.file].content) |
|
|
|
column: ((lineColumn.start && lineColumn.start.column) || 0) + 1 |
|
|
|
const lineColumn = sourceMappingDecoder.convertOffsetToLineColumn({ |
|
|
|
}, |
|
|
|
start: error.sourceLocation.start, |
|
|
|
end: { |
|
|
|
length: error.sourceLocation.end - error.sourceLocation.start |
|
|
|
line: ((lineColumn.end && lineColumn.end.line) || 0) + 1, |
|
|
|
}, lineBreaks) |
|
|
|
column: ((lineColumn.end && lineColumn.end.column) || 0) + 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const filePath = error.sourceLocation.file |
|
|
|
|
|
|
|
const fileTarget = await this.plugin.call('fileManager', 'getUrlFromPath', filePath) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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') |
|
|
|
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) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
await this.plugin.call('editor', 'clearErrorMarkers', result.getSourceCode().sources) |
|
|
|
await this.plugin.call('editor', 'clearErrorMarkers', result.getSourceCode().sources) |
|
|
@ -144,14 +155,14 @@ export default class CodeParserCompiler { |
|
|
|
this.compiler.compile(sources, this.plugin.currentFile) |
|
|
|
this.compiler.compile(sources, this.plugin.currentFile) |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
// do nothing
|
|
|
|
// do nothing
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async addDecorators(allErrors: errorMarker[], sources: any) { |
|
|
|
async addDecorators(allErrors: errorMarker[], sources: any) { |
|
|
|
const displayErrors = await this.plugin.call('config', 'getAppParameter', 'display-errors') |
|
|
|
const displayErrors = await this.plugin.call('config', 'getAppParameter', 'display-errors') |
|
|
|
if(!displayErrors) return |
|
|
|
if (!displayErrors) return |
|
|
|
const errorsPerFiles: {[fileName: string]: errorMarker[]} = {} |
|
|
|
const errorsPerFiles: { [fileName: string]: errorMarker[] } = {} |
|
|
|
for (const error of allErrors) { |
|
|
|
for (const error of allErrors) { |
|
|
|
if (!errorsPerFiles[error.file]) { |
|
|
|
if (!errorsPerFiles[error.file]) { |
|
|
|
errorsPerFiles[error.file] = [] |
|
|
|
errorsPerFiles[error.file] = [] |
|
|
@ -165,7 +176,7 @@ export default class CodeParserCompiler { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// sort errorPerFiles by error priority
|
|
|
|
// sort errorPerFiles by error priority
|
|
|
|
const sortedErrorsPerFiles: {[fileName: string]: errorMarker[]} = {} |
|
|
|
const sortedErrorsPerFiles: { [fileName: string]: errorMarker[] } = {} |
|
|
|
for (const fileName in errorsPerFiles) { |
|
|
|
for (const fileName in errorsPerFiles) { |
|
|
|
const errors = errorsPerFiles[fileName] |
|
|
|
const errors = errorsPerFiles[fileName] |
|
|
|
errors.sort((a, b) => { |
|
|
|
errors.sort((a, b) => { |
|
|
@ -179,10 +190,11 @@ 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', |
|
|
|
fileStateIconClass: '', |
|
|
|
fileStateIconClass: '', |
|
|
|
fileStateIcon: '', |
|
|
|
fileStateIcon: '', |
|
|
@ -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,9 +225,27 @@ 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 |
|
|
|
for (const fileName of Object.keys(sources)) { |
|
|
|
for (const fileName of Object.keys(sources)) { |
|
|
|
const decorator: fileDecoration = { |
|
|
|
const decorator: fileDecoration = { |
|
|
|
path: fileName, |
|
|
|
path: fileName, |
|
|
@ -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 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |