Merge branch 'master' of https://github.com/ethereum/remix-project into desktopmerge

desktopmerge
filip mertens 1 year ago
commit e89f5bb2d9
  1. 28
      apps/remix-ide/src/app.js
  2. 1
      apps/remix-ide/src/app/components/preload.tsx
  3. 119
      apps/remix-ide/src/app/plugins/parser/services/code-parser-antlr-service.ts
  4. 36
      libs/remix-ui/workspace/src/lib/reducers/workspace.ts

@ -23,20 +23,20 @@ import {WalkthroughService} from './walkthroughService'
import {OffsetToLineColumnConverter, CompilerMetadata, CompilerArtefacts, FetchAndCompile, CompilerImports, GistHandler} from '@remix-project/core-plugin'
import Registry from './app/state/registry'
import { ConfigPlugin } from './app/plugins/config'
import { StoragePlugin } from './app/plugins/storage'
import { Layout } from './app/panels/layout'
import { NotificationPlugin } from './app/plugins/notification'
import { Blockchain } from './blockchain/blockchain'
import { MergeVMProvider, LondonVMProvider, BerlinVMProvider, ShanghaiVMProvider } from './app/providers/vm-provider'
import { MainnetForkVMProvider } from './app/providers/mainnet-vm-fork-provider'
import { SepoliaForkVMProvider } from './app/providers/sepolia-vm-fork-provider'
import { GoerliForkVMProvider } from './app/providers/goerli-vm-fork-provider'
import { CustomForkVMProvider } from './app/providers/custom-vm-fork-provider'
import { HardhatProvider } from './app/providers/hardhat-provider'
import { GanacheProvider } from './app/providers/ganache-provider'
import { FoundryProvider } from './app/providers/foundry-provider'
import { ExternalHttpProvider } from './app/providers/external-http-provider'
import {ConfigPlugin} from './app/plugins/config'
import {StoragePlugin} from './app/plugins/storage'
import {Layout} from './app/panels/layout'
import {NotificationPlugin} from './app/plugins/notification'
import {Blockchain} from './blockchain/blockchain'
import {MergeVMProvider, LondonVMProvider, BerlinVMProvider, ShanghaiVMProvider} from './app/providers/vm-provider'
import {MainnetForkVMProvider} from './app/providers/mainnet-vm-fork-provider'
import {SepoliaForkVMProvider} from './app/providers/sepolia-vm-fork-provider'
import {GoerliForkVMProvider} from './app/providers/goerli-vm-fork-provider'
import {CustomForkVMProvider} from './app/providers/custom-vm-fork-provider'
import {HardhatProvider} from './app/providers/hardhat-provider'
import {GanacheProvider} from './app/providers/ganache-provider'
import {FoundryProvider} from './app/providers/foundry-provider'
import {ExternalHttpProvider} from './app/providers/external-http-provider'
import {InjectedProviderDefault} from './app/providers/injected-provider-default'
import {InjectedProviderTrustWallet} from './app/providers/injected-provider-trustwallet'
import {Injected0ptimismProvider} from './app/providers/injected-optimism-provider'

@ -74,6 +74,7 @@ export const Preload = () => {
testBlockStorage.current ? null : localStorageFileSystem.current
])
if (fsLoaded) {
console.log(fsLoaded.name + ' activated')
_paq.push(['trackEvent', 'Storage', 'activate', fsLoaded.name])
loadAppComponent()
} else {

@ -28,15 +28,15 @@ export default class CodeParserAntlrService {
parserThreshold: number = 10
parserThresholdSampleAmount = 3
cache: {
[name: string]: {
text: string
ast: antlr.ParseResult | null
duration?: number
parsingEnabled?: boolean
blocks?: BlockDefinition[]
blockDurations?: number[]
}
} = {}
[name: string]: {
text: string,
ast: antlr.ParseResult | null,
duration?: number,
parsingEnabled?: boolean,
blocks?: BlockDefinition[],
blockDurations?: number[]
}
} = {};
constructor(plugin: CodeParser) {
this.plugin = plugin
this.createWorker()
@ -52,23 +52,22 @@ export default class CodeParserAntlrService {
this.worker.addEventListener('message', function (ev) {
switch (ev.data.cmd) {
case 'parsed':
if (ev.data.ast && self.parserStartTime === ev.data.timestamp) {
self.cache[ev.data.file] = {
...self.cache[ev.data.file],
text: ev.data.text,
ast: ev.data.ast,
duration: ev.data.duration,
blocks: ev.data.blocks,
blockDurations: self.cache[ev.data.file].blockDurations
? [...self.cache[ev.data.file].blockDurations.slice(-self.parserThresholdSampleAmount), ev.data.blockDuration]
: [ev.data.blockDuration],
}
self.setFileParsingState(ev.data.file)
case 'parsed':
if (ev.data.ast && self.parserStartTime === ev.data.timestamp) {
self.cache[ev.data.file] = {
...self.cache[ev.data.file],
text: ev.data.text,
ast: ev.data.ast,
duration: ev.data.duration,
blocks: ev.data.blocks,
blockDurations: self.cache[ev.data.file].blockDurations? [...self.cache[ev.data.file].blockDurations.slice(-self.parserThresholdSampleAmount), ev.data.blockDuration]: [ev.data.blockDuration]
}
break
self.setFileParsingState(ev.data.file)
}
break;
}
})
});
}
setFileParsingState(file: string) {
@ -105,8 +104,9 @@ export default class CodeParserAntlrService {
text,
timestamp: this.parserStartTime,
file,
parsingEnabled: (this.cache[file] && this.cache[file].parsingEnabled) || true,
})
parsingEnabled: (this.cache[file] && this.cache[file].parsingEnabled) || true
});
}
async parseSolidity(text: string) {
@ -115,22 +115,22 @@ export default class CodeParserAntlrService {
}
/**
* Tries to parse the current file or the given text and returns the AST
* If the parsing fails it returns the last successful AST for this file
* @param text
* @returns
*/
* Tries to parse the current file or the given text and returns the AST
* If the parsing fails it returns the last successful AST for this file
* @param text
* @returns
*/
async setCurrentFileAST(text: string | null = null) {
try {
this.plugin.currentFile = await this.plugin.call('fileManager', 'file')
if (this.plugin.currentFile && this.plugin.currentFile.endsWith('.sol')) {
const fileContent = text || (await this.plugin.call('fileManager', 'readFile', this.plugin.currentFile))
const fileContent = text || await this.plugin.call('fileManager', 'readFile', this.plugin.currentFile)
if (!this.cache[this.plugin.currentFile]) {
this.cache[this.plugin.currentFile] = {
text: '',
ast: null,
parsingEnabled: true,
blockDurations: [],
blockDurations: []
}
}
if (this.cache[this.plugin.currentFile] && this.cache[this.plugin.currentFile].text !== fileContent) {
@ -147,15 +147,15 @@ export default class CodeParserAntlrService {
}
/**
* Lists the AST nodes from the current file parser
* These nodes need to be changed to match the node types returned by the compiler
* @returns
*/
* Lists the AST nodes from the current file parser
* These nodes need to be changed to match the node types returned by the compiler
* @returns
*/
async listAstNodes() {
this.plugin.currentFile = await this.plugin.call('fileManager', 'file')
if (!this.cache[this.plugin.currentFile]) return
const nodes: AstNode[] = []
;(SolidityParser as any).visit(this.cache[this.plugin.currentFile].ast, {
const nodes: AstNode[] = [];
(SolidityParser as any).visit(this.cache[this.plugin.currentFile].ast, {
StateVariableDeclaration: (node: antlr.StateVariableDeclaration) => {
if (node.variables) {
for (const variable of node.variables) {
@ -195,16 +195,18 @@ export default class CodeParserAntlrService {
},
StructDefinition: function (node: antlr.StructDefinition) {
nodes.push({ ...node, nodeType: node.type, id: null, src: null })
},
}
})
return nodes
}
/**
*
* @param ast
* @returns
*/
*
* @param ast
* @returns
*/
async getLastNodeInLine(ast: string) {
let lastNode: any
const checkLastNode = (node: antlr.MemberAccess | antlr.Identifier) => {
@ -217,13 +219,13 @@ export default class CodeParserAntlrService {
}
}
;(SolidityParser as any).visit(ast, {
(SolidityParser as any).visit(ast, {
MemberAccess: function (node: antlr.MemberAccess) {
checkLastNode(node)
},
Identifier: function (node: antlr.Identifier) {
checkLastNode(node)
},
}
})
if (lastNode && lastNode.expression) {
return lastNode.expression
@ -231,8 +233,8 @@ export default class CodeParserAntlrService {
return lastNode
}
/*
* get the code blocks of the current file
*/
* get the code blocks of the current file
*/
async getCurrentFileBlocks(text: string | null = null) {
this.plugin.currentFile = await this.plugin.call('fileManager', 'file')
if (this.cache[this.plugin.currentFile]) {
@ -241,15 +243,12 @@ export default class CodeParserAntlrService {
}
}
if (this.plugin.currentFile && this.plugin.currentFile.endsWith('.sol')) {
const fileContent = text || (await this.plugin.call('fileManager', 'readFile', this.plugin.currentFile))
const fileContent = text || await this.plugin.call('fileManager', 'readFile', this.plugin.currentFile)
try {
const startTime = Date.now()
const blocks = (SolidityParser as any).parseBlock(fileContent, { loc: true, range: true, tolerant: true })
if (this.cache[this.plugin.currentFile] && this.cache[this.plugin.currentFile].blockDurations) {
this.cache[this.plugin.currentFile].blockDurations = [
...this.cache[this.plugin.currentFile].blockDurations.slice(-this.parserThresholdSampleAmount),
Date.now() - startTime,
]
if(this.cache[this.plugin.currentFile] && this.cache[this.plugin.currentFile].blockDurations){
this.cache[this.plugin.currentFile].blockDurations = [...this.cache[this.plugin.currentFile].blockDurations.slice(-this.parserThresholdSampleAmount), Date.now() - startTime]
this.setFileParsingState(this.plugin.currentFile)
}
if (blocks) this.cache[this.plugin.currentFile].blocks = blocks
@ -261,12 +260,12 @@ export default class CodeParserAntlrService {
}
/**
* Returns the block surrounding the given position
* For example if the position is in the middle of a function, it will return the function
* @param {position} position
* @param {string} text // optional
* @return {any}
* */
* Returns the block surrounding the given position
* For example if the position is in the middle of a function, it will return the function
* @param {position} position
* @param {string} text // optional
* @return {any}
* */
async getANTLRBlockAtPosition(position: any, text: string = null) {
const blocks: any[] = await this.getCurrentFileBlocks(text)

@ -35,7 +35,7 @@ export interface BrowserState {
}
fileState: fileDecoration[]
recentFolders: string[]
},
}
localhost: {
sharedFolder: string
files: {[x: string]: Record<string, FileType>}
@ -87,8 +87,7 @@ export const browserInitialState: BrowserState = {
removedMenuItems: [],
error: null
},
fileState: [],
recentFolders: []
fileState: []
},
localhost: {
sharedFolder: '',
@ -850,25 +849,26 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
}
}
case 'SET_GIT_CONFIG': {
const payload: { username: string, token: string, email: string } = action.payload
return {
...state,
gitConfig: payload
}
case 'SET_GIT_CONFIG': {
const payload: {username: string; token: string; email: string} =
action.payload
return {
...state,
gitConfig: payload
}
}
case 'SET_ELECTRON_RECENT_FOLDERS': {
const payload: string[] = action.payload
return {
...state,
browser: {
...state.browser,
recentFolders: payload
}
case 'SET_ELECTRON_RECENT_FOLDERS': {
const payload: string[] = action.payload
return {
...state,
browser: {
...state.browser,
recentFolders: payload
}
}
}
default:
throw new Error()

Loading…
Cancel
Save