test imports

editorcontextDummy
bunsenstraat 3 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 { Node, AstNode } from './index'
import type { CompilationError } from '@remix-project/remix-solidity-ts'
export declare interface AstWalker {
new(): EventEmitter;

@ -4,6 +4,11 @@ import { sourceMappingDecoder } from '@remix-project/remix-debug'
import { CompilerAbstract } 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 = {
name: 'contextualListener',
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() {
this.on('editor', 'contentChanged', async () => {
console.log('contentChanged')
await this.getAST()
await this.compile()
this._stopHighlighting()
})
this.on('solidity', 'loadingCompiler', async(url) => {
console.log('loading compiler', url)
this.compiler.event.register('compilerLoaded', async() => await this.compile() )
this.compiler.loadVersion(true, url)
})
@ -73,7 +82,33 @@ export class EditorContextListener extends Plugin {
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 && Object.keys(data.sources).length === 0) return
this.lastCompilationResult = new CompilerAbstract('soljson', data, source, input)
@ -91,8 +126,10 @@ export class EditorContextListener extends Plugin {
setInterval(async () => {
await this.compile()
}, 5000)
//await this.compile()
}, 1000)
setInterval(async () => {
const compilationResult = this.lastCompilationResult // await this.call('compilerArtefacts', 'getLastCompilationResult')
@ -118,6 +155,7 @@ export class EditorContextListener extends Plugin {
}
async compile() {
console.log('compile')
try {
const state = await this.call('solidity', 'getCompilerState')
this.compiler.set('optimize', state.optimize)
@ -131,6 +169,7 @@ export class EditorContextListener extends Plugin {
const sources = { [this.currentFile]: { content } }
this.compiler.compile(sources, this.currentFile)
} catch (e) {
console.log(e)
}
}
@ -159,7 +198,7 @@ export class EditorContextListener extends Plugin {
async getAST(text: string = null) {
this.currentFile = await this.call('fileManager', 'file')
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 {
const ast = (SolidityParser as any).parse(fileContent, { loc: true, range: true, tolerant: true })
this.lastAST = ast
@ -207,7 +246,7 @@ export class EditorContextListener extends Plugin {
async nodesAtEditorPosition(position: any, type: string = '') {
const lastCompilationResult = this.lastCompilationResult // await this.call('compilerArtefacts', 'getLastCompilationResult')
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) {
const nodes = sourceMappingDecoder.nodesAtPosition(type, position, lastCompilationResult.data.sources[this.currentFile] || lastCompilationResult.data.sources[urlFromPath.file])
return nodes
@ -326,7 +365,7 @@ export class EditorContextListener extends Plugin {
this._stopHighlighting()
this.currentPosition = cursorPosition
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])) {
const nodes = sourceMappingDecoder.nodesAtPosition(null, cursorPosition, compilationResult.data.sources[file] || compilationResult.data.sources[urlFromPath.file])
this.nodes = nodes

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

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

Loading…
Cancel
Save