test imports

editorcontextDummy
bunsenstraat 2 years ago
parent 9914fc1269
commit 06e411e76b
  1. 1
      libs/remix-astwalker/src/astWalker.ts
  2. 51
      libs/remix-core-plugin/src/lib/editor-context-listener.ts
  3. 6
      libs/remix-solidity/src/compiler/compiler.ts
  4. 11
      libs/remix-ui/editor/src/lib/providers/completionProvider.ts
  5. 2
      libs/remix-ui/run-tab/src/lib/reducers/runTab.ts

@ -1,5 +1,6 @@
import { EventEmitter } from 'events' import { EventEmitter } from 'events'
import { Node, AstNode } from './index' import { Node, AstNode } from './index'
import type { CompilationError } from '@remix-project/remix-solidity-ts'
export declare interface AstWalker { export declare interface AstWalker {
new(): EventEmitter; new(): EventEmitter;

@ -4,6 +4,11 @@ import { sourceMappingDecoder } from '@remix-project/remix-debug'
import { CompilerAbstract } from '@remix-project/remix-solidity' import { CompilerAbstract } from '@remix-project/remix-solidity'
import { Compiler } from '@remix-project/remix-solidity' import { Compiler } from '@remix-project/remix-solidity'
import { helper } from '@remix-project/remix-solidity'
import type { CompilationError } from '@remix-project/remix-solidity-ts'
const profile = { const profile = {
name: 'contextualListener', name: 'contextualListener',
methods: ['getBlockName', 'getAST', 'nodesWithScope', 'getNodes', 'compile', 'getNodeById', 'getLastCompilationResult', 'positionOfDefinition', 'definitionAtPosition', 'jumpToDefinition', 'referrencesAtPosition', 'nodesAtEditorPosition', 'referencesOf', 'getActiveHighlights', 'gasEstimation', 'declarationOf', 'jumpToPosition'], methods: ['getBlockName', 'getAST', 'nodesWithScope', 'getNodes', 'compile', 'getNodeById', 'getLastCompilationResult', 'positionOfDefinition', 'definitionAtPosition', 'jumpToDefinition', 'referrencesAtPosition', 'nodesAtEditorPosition', 'referencesOf', 'getActiveHighlights', 'gasEstimation', 'declarationOf', 'jumpToPosition'],
@ -59,12 +64,16 @@ export class EditorContextListener extends Plugin {
async onActivation() { async onActivation() {
this.on('editor', 'contentChanged', async () => { this.on('editor', 'contentChanged', async () => {
console.log('contentChanged')
await this.getAST() await this.getAST()
await this.compile()
this._stopHighlighting() this._stopHighlighting()
}) })
this.on('solidity', 'loadingCompiler', async(url) => { this.on('solidity', 'loadingCompiler', async(url) => {
console.log('loading compiler', url) console.log('loading compiler', url)
this.compiler.event.register('compilerLoaded', async() => await this.compile() )
this.compiler.loadVersion(true, url) this.compiler.loadVersion(true, url)
}) })
@ -73,7 +82,33 @@ export class EditorContextListener extends Plugin {
this.onAstFinished = async (success, data, source, input, version) => { this.onAstFinished = async (success, data, source, input, version) => {
console.log('compile success', success)
this.call('editor', 'clearAnnotations')
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
const isValidError = (error.message && error.message.includes('Deferred import')) ? false : error.severity !== 'warning'
if (isValidError) {
console.log(error)
noFatalErrors = false
}
}
if (data.error) checkIfFatalError(data.error)
if (data.errors) data.errors.forEach((err) => checkIfFatalError(err))
if (data.errors) {
for (const error of data.errors) {
let pos = helper.getPositionDetails(error.formattedMessage)
if (pos.errFile) {
pos = {
row: pos.errLine,
column: pos.errCol,
text: error.formattedMessage,
type: error.severity
}
await this.call('editor', 'addAnnotation', pos, pos.errFile)
}
}
}
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)
@ -91,8 +126,10 @@ export class EditorContextListener extends Plugin {
setInterval(async () => { setInterval(async () => {
await this.compile() //await this.compile()
}, 5000) }, 1000)
setInterval(async () => { setInterval(async () => {
const compilationResult = this.lastCompilationResult // await this.call('compilerArtefacts', 'getLastCompilationResult') const compilationResult = this.lastCompilationResult // await this.call('compilerArtefacts', 'getLastCompilationResult')
@ -118,6 +155,7 @@ export class EditorContextListener extends Plugin {
} }
async compile() { async compile() {
console.log('compile')
try { try {
const state = await this.call('solidity', 'getCompilerState') const state = await this.call('solidity', 'getCompilerState')
this.compiler.set('optimize', state.optimize) this.compiler.set('optimize', state.optimize)
@ -131,6 +169,7 @@ export class EditorContextListener extends Plugin {
const sources = { [this.currentFile]: { content } } const sources = { [this.currentFile]: { content } }
this.compiler.compile(sources, this.currentFile) this.compiler.compile(sources, this.currentFile)
} catch (e) { } catch (e) {
console.log(e)
} }
} }
@ -159,7 +198,7 @@ export class EditorContextListener extends Plugin {
async getAST(text: string = null) { async getAST(text: string = null) {
this.currentFile = await this.call('fileManager', 'file') this.currentFile = await this.call('fileManager', 'file')
if (!this.currentFile) return if (!this.currentFile) return
let fileContent = text || await this.call('fileManager', 'readFile', this.currentFile) const fileContent = text || await this.call('fileManager', 'readFile', this.currentFile)
try { try {
const ast = (SolidityParser as any).parse(fileContent, { loc: true, range: true, tolerant: true }) const ast = (SolidityParser as any).parse(fileContent, { loc: true, range: true, tolerant: true })
this.lastAST = ast this.lastAST = ast
@ -207,7 +246,7 @@ export class EditorContextListener extends Plugin {
async nodesAtEditorPosition(position: any, type: string = '') { async nodesAtEditorPosition(position: any, type: string = '') {
const lastCompilationResult = this.lastCompilationResult // await this.call('compilerArtefacts', 'getLastCompilationResult') const lastCompilationResult = this.lastCompilationResult // await this.call('compilerArtefacts', 'getLastCompilationResult')
if (!lastCompilationResult) return false if (!lastCompilationResult) return false
let urlFromPath = await this.call('fileManager', 'getUrlFromPath', this.currentFile) 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) {
const nodes = sourceMappingDecoder.nodesAtPosition(type, position, lastCompilationResult.data.sources[this.currentFile] || lastCompilationResult.data.sources[urlFromPath.file]) const nodes = sourceMappingDecoder.nodesAtPosition(type, position, lastCompilationResult.data.sources[this.currentFile] || lastCompilationResult.data.sources[urlFromPath.file])
return nodes return nodes
@ -326,7 +365,7 @@ export class EditorContextListener extends Plugin {
this._stopHighlighting() this._stopHighlighting()
this.currentPosition = cursorPosition this.currentPosition = cursorPosition
this.currentFile = file this.currentFile = file
let urlFromPath = await this.call('fileManager', 'getUrlFromPath', this.currentFile) const urlFromPath = await this.call('fileManager', 'getUrlFromPath', this.currentFile)
if (compilationResult && compilationResult.data && (compilationResult.data.sources[file] || compilationResult.data.sources[urlFromPath.file])) { if (compilationResult && compilationResult.data && (compilationResult.data.sources[file] || compilationResult.data.sources[urlFromPath.file])) {
const nodes = sourceMappingDecoder.nodesAtPosition(null, cursorPosition, compilationResult.data.sources[file] || compilationResult.data.sources[urlFromPath.file]) const nodes = sourceMappingDecoder.nodesAtPosition(null, cursorPosition, compilationResult.data.sources[file] || compilationResult.data.sources[urlFromPath.file])
this.nodes = nodes this.nodes = nodes

@ -84,7 +84,6 @@ export class Compiler {
*/ */
compile (files: Source, target: string): void { compile (files: Source, target: string): void {
console.log('compiler', files, target)
this.state.target = target this.state.target = target
this.event.trigger('compilationStarted', []) this.event.trigger('compilationStarted', [])
this.internalCompile(files) this.internalCompile(files)
@ -156,6 +155,7 @@ export class Compiler {
if (!noFatalErrors) { if (!noFatalErrors) {
// There are fatal errors, abort here // There are fatal errors, abort here
this.state.lastCompilationResult = null this.state.lastCompilationResult = null
this.event.trigger('astFinished', [false, data, source, input, version])
this.event.trigger('compilationFinished', [false, data, source, input, version]) this.event.trigger('compilationFinished', [false, data, source, input, version])
} else if (missingInputs !== undefined && missingInputs.length > 0 && source && source.sources) { } else if (missingInputs !== undefined && missingInputs.length > 0 && source && source.sources) {
// try compiling again with the new set of inputs // try compiling again with the new set of inputs
@ -169,9 +169,10 @@ export class Compiler {
source: source source: source
} }
} }
this.event.trigger('astFinished', [true, data, source, input, version])
this.event.trigger('compilationFinished', [true, data, source, input, version]) this.event.trigger('compilationFinished', [true, data, source, input, version])
} }
this.event.trigger('astFinished', [true, data, source, input, version])
} }
/** /**
@ -272,7 +273,6 @@ export class Compiler {
const jobs: Record<'sources', SourceWithTarget> [] = [] const jobs: Record<'sources', SourceWithTarget> [] = []
this.state.worker.addEventListener('message', (msg: Record <'data', MessageFromWorker>) => { this.state.worker.addEventListener('message', (msg: Record <'data', MessageFromWorker>) => {
console.log(msg)
const data: MessageFromWorker = msg.data const data: MessageFromWorker = msg.data
switch (data.cmd) { switch (data.cmd) {
case 'versionLoaded': case 'versionLoaded':

@ -88,11 +88,16 @@ export class RemixCompletionProvider {
if (splits.length > 1) { if (splits.length > 1) {
let last = splits[splits.length - 2].trim() let last = splits[splits.length - 2].trim()
const lastParentheses = last.lastIndexOf('(') const lastParentheses = last.lastIndexOf('(')
const lastClosingParentheses = last.lastIndexOf(')')
const lastBracket = last.lastIndexOf('{') const lastBracket = last.lastIndexOf('{')
const lastSemiColon = last.lastIndexOf(';') const lastSemiColon = last.lastIndexOf(';')
let textBefore = null let textBefore = null
let lastWord = null let lastWord = null
let lineWithoutEdits = null let lineWithoutEdits = null
// get word before last closing parentheses
if (lastParentheses > -1 && lastClosingParentheses > -1) {
//textBefore = last.substring(0, lastParentheses)
}
// find largest // find largest
const lastIndex = Math.max(lastParentheses, lastBracket, lastSemiColon) const lastIndex = Math.max(lastParentheses, lastBracket, lastSemiColon)
if (lastIndex > -1) { if (lastIndex > -1) {
@ -132,7 +137,7 @@ export class RemixCompletionProvider {
if (nodeOfScope.typeName && nodeOfScope.typeName.nodeType === 'UserDefinedTypeName') { if (nodeOfScope.typeName && nodeOfScope.typeName.nodeType === 'UserDefinedTypeName') {
const declarationOf = await this.props.plugin.call('contextualListener', 'declarationOf', nodeOfScope.typeName) const declarationOf = await this.props.plugin.call('contextualListener', 'declarationOf', nodeOfScope.typeName)
console.log('HAS DECLARATION OF', declarationOf) console.log('HAS DECLARATION OF', declarationOf)
nodes = declarationOf.nodes nodes = declarationOf.nodes || declarationOf.members
const baseContracts = await getlinearizedBaseContracts(declarationOf) const baseContracts = await getlinearizedBaseContracts(declarationOf)
for (const baseContract of baseContracts) { for (const baseContract of baseContracts) {
nodes = [...nodes, ...baseContract.nodes] nodes = [...nodes, ...baseContract.nodes]
@ -201,7 +206,7 @@ export class RemixCompletionProvider {
const getParamaters = async (parameters: any) => { const getParamaters = async (parameters: any) => {
if (parameters && parameters.parameters) { if (parameters && parameters.parameters) {
let params = [] const params = []
for (const param of parameters.parameters) { for (const param of parameters.parameters) {
params.push(await getVariableDeclaration(param)) params.push(await getVariableDeclaration(param))
} }
@ -211,7 +216,7 @@ export class RemixCompletionProvider {
const completeParameters = async (parameters: any) => { const completeParameters = async (parameters: any) => {
if (parameters && parameters.parameters) { if (parameters && parameters.parameters) {
let params = [] const params = []
for (const param of parameters.parameters) { for (const param of parameters.parameters) {
params.push(param.name) params.push(param.name)
} }

@ -1,4 +1,4 @@
import { CompilerAbstract } from '@remix-project/remix-solidity-ts' import { CompilerAbstract, CompilationError } from '@remix-project/remix-solidity-ts'
import { ContractData } from '@remix-project/core-plugin' import { ContractData } from '@remix-project/core-plugin'
interface Action { interface Action {
type: string type: string

Loading…
Cancel
Save