|
|
|
@ -31,6 +31,7 @@ export class CodeParser extends Plugin { |
|
|
|
|
currentFile: any |
|
|
|
|
_index: any |
|
|
|
|
astWalker: any |
|
|
|
|
errorState: boolean = false |
|
|
|
|
onAstFinished: (success: any, data: CompilationResult, source: CompilationSource, input: any, version: any) => Promise<void> |
|
|
|
|
|
|
|
|
|
constructor(astWalker) { |
|
|
|
@ -70,6 +71,7 @@ export class CodeParser extends Plugin { |
|
|
|
|
this.onAstFinished = async (success, data: CompilationResult, source: CompilationSource, input: any, version) => { |
|
|
|
|
console.log('compile success', success, data, this) |
|
|
|
|
this.call('editor', 'clearAnnotations') |
|
|
|
|
this.errorState = true |
|
|
|
|
let noFatalErrors = true // ie warnings are ok
|
|
|
|
|
const checkIfFatalError = (error: CompilationError) => { |
|
|
|
|
// Ignore warnings and the 'Deferred import' error as those are generated by us as a workaround
|
|
|
|
@ -111,7 +113,7 @@ export class CodeParser extends Plugin { |
|
|
|
|
if (!data.sources) return |
|
|
|
|
if (data.sources && Object.keys(data.sources).length === 0) return |
|
|
|
|
this.lastCompilationResult = new CompilerAbstract('soljson', data, source, input) |
|
|
|
|
|
|
|
|
|
this.errorState = false |
|
|
|
|
this._index = { |
|
|
|
|
Declarations: {}, |
|
|
|
|
FlatReferences: {} |
|
|
|
@ -120,8 +122,8 @@ export class CodeParser extends Plugin { |
|
|
|
|
this.emit('astFinished') |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.compiler = new Compiler((url, cb) => this.call('contentImport', 'resolveAndSave', url, undefined, false).then((result) => cb(null, result)).catch((error) => cb(error.message))) |
|
|
|
|
this.compiler.event.register('astFinished', this.onAstFinished) |
|
|
|
|
this.compiler = new Compiler((url, cb) => this.call('contentImport', 'resolveAndSave', url, undefined, true).then((result) => cb(null, result)).catch((error) => cb(error.message))) |
|
|
|
|
this.compiler.event.register('compilationFinished', this.onAstFinished) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// COMPILER
|
|
|
|
@ -263,6 +265,9 @@ export class CodeParser extends Plugin { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
VariableDeclaration: (node) => { |
|
|
|
|
nodes.push({ ...node, nodeType: node.type }) |
|
|
|
|
}, |
|
|
|
|
UserDefinedTypeName: (node) => { |
|
|
|
|
nodes.push({ ...node, nodeType: node.type }) |
|
|
|
|
}, |
|
|
|
@ -278,6 +283,12 @@ export class CodeParser extends Plugin { |
|
|
|
|
Identifier: function (node) { |
|
|
|
|
nodes.push({ ...node, nodeType: node.type }) |
|
|
|
|
}, |
|
|
|
|
EventDefinition: function (node) { |
|
|
|
|
nodes.push({ ...node, nodeType: node.type }) |
|
|
|
|
}, |
|
|
|
|
ModifierDefinition: function (node) { |
|
|
|
|
nodes.push({ ...node, nodeType: node.type }) |
|
|
|
|
}, |
|
|
|
|
InvalidNode: function (node) { |
|
|
|
|
nodes.push({ ...node, nodeType: node.type }) |
|
|
|
|
} |
|
|
|
@ -296,7 +307,7 @@ export class CodeParser extends Plugin { |
|
|
|
|
const lastCompilationResult = this.lastCompilationResult |
|
|
|
|
if (!lastCompilationResult) return false |
|
|
|
|
const urlFromPath = await this.call('fileManager', 'getUrlFromPath', this.currentFile) |
|
|
|
|
if (lastCompilationResult && lastCompilationResult.languageversion.indexOf('soljson') === 0 && lastCompilationResult.data) { |
|
|
|
|
if (lastCompilationResult && lastCompilationResult.languageversion.indexOf('soljson') === 0 && lastCompilationResult.data && lastCompilationResult.data.sources && lastCompilationResult.data.sources[this.currentFile]) { |
|
|
|
|
const nodes = sourceMappingDecoder.nodesAtPosition(type, position, lastCompilationResult.data.sources[this.currentFile] || lastCompilationResult.data.sources[urlFromPath.file]) |
|
|
|
|
return nodes |
|
|
|
|
} |
|
|
|
@ -322,7 +333,7 @@ export class CodeParser extends Plugin { |
|
|
|
|
* @returns
|
|
|
|
|
*/ |
|
|
|
|
async getDeclaration(id: any) { |
|
|
|
|
if(this._index.Declarations && this._index.Declarations[id]) return this._index.Declarations[id] |
|
|
|
|
if (this._index.Declarations && this._index.Declarations[id]) return this._index.Declarations[id] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -375,7 +386,7 @@ export class CodeParser extends Plugin { |
|
|
|
|
console.log(this._index.FlatReferences) |
|
|
|
|
let nodeDefinition: any |
|
|
|
|
let node: any |
|
|
|
|
if (nodes && nodes.length) { |
|
|
|
|
if (nodes && nodes.length && !this.errorState) { |
|
|
|
|
node = nodes[nodes.length - 1] |
|
|
|
|
nodeDefinition = node |
|
|
|
|
if (!isNodeDefinition(node)) { |
|
|
|
@ -399,11 +410,29 @@ export class CodeParser extends Plugin { |
|
|
|
|
if (!nodeDefinition) nodeDefinition = node |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (nodeDefinition && nodeDefinition.type && nodeDefinition.type === 'Identifier') { |
|
|
|
|
const nodeForIdentifier = await this.findIdentifier(nodeDefinition) |
|
|
|
|
if (nodeForIdentifier) nodeDefinition = nodeForIdentifier |
|
|
|
|
} |
|
|
|
|
return nodeDefinition |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
*
|
|
|
|
|
* @param identifierNode
|
|
|
|
|
* @returns
|
|
|
|
|
*/ |
|
|
|
|
async findIdentifier(identifierNode: any) { |
|
|
|
|
let astNodes = await this.listAstNodes() |
|
|
|
|
for (const node of astNodes) { |
|
|
|
|
if (node.name === identifierNode.name && node.nodeType !== 'Identifier') { |
|
|
|
|
return node |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
*
|
|
|
|
|
* @param node
|
|
|
|
@ -570,13 +599,18 @@ export class CodeParser extends Plugin { |
|
|
|
|
*/ |
|
|
|
|
async getVariableDeclaration(node: any) { |
|
|
|
|
if (node.typeDescriptions && node.typeDescriptions.typeString) { |
|
|
|
|
return `${node.typeDescriptions.typeString}${node.name && node.name.length ? ` ${node.name}` : ''}` |
|
|
|
|
} else |
|
|
|
|
return `${node.typeDescriptions.typeString} ${node.visibility}${node.name && node.name.length ? ` ${node.name}` : ''}` |
|
|
|
|
} else { |
|
|
|
|
if (node.typeName && node.typeName.name) { |
|
|
|
|
return `${node.typeName.name}${node.name && node.name.length ? ` ${node.name}` : ''}` |
|
|
|
|
} else { |
|
|
|
|
return `${node.name && node.name.length ? ` ${node.name}` : ''}` |
|
|
|
|
return `${node.typeName.name} ${node.visibility}${node.name && node.name.length ? ` ${node.name}` : ''}` |
|
|
|
|
}
|
|
|
|
|
else if (node.typeName && node.typeName.namePath) { |
|
|
|
|
return `${node.typeName.namePath} ${node.visibility}${node.name && node.name.length ? ` ${node.name}` : ''}` |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
return `${node.visibility}${node.name && node.name.length ? ` ${node.name}` : ''}` |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|