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

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

@ -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 {

@ -29,14 +29,14 @@ export default class CodeParserAntlrService {
parserThresholdSampleAmount = 3
cache: {
[name: string]: {
text: string
ast: antlr.ParseResult | null
duration?: number
parsingEnabled?: boolean
blocks?: BlockDefinition[]
text: string,
ast: antlr.ParseResult | null,
duration?: number,
parsingEnabled?: boolean,
blocks?: BlockDefinition[],
blockDurations?: number[]
}
} = {}
} = {};
constructor(plugin: CodeParser) {
this.plugin = plugin
this.createWorker()
@ -60,15 +60,14 @@ export default class CodeParserAntlrService {
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],
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)
}
break
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) {
@ -124,13 +124,13 @@ export default class CodeParserAntlrService {
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) {
@ -154,8 +154,8 @@ export default class CodeParserAntlrService {
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,11 +195,13 @@ export default class CodeParserAntlrService {
},
StructDefinition: function (node: antlr.StructDefinition) {
nodes.push({ ...node, nodeType: node.type, id: null, src: null })
},
}
})
return nodes
}
/**
*
* @param ast
@ -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
@ -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,
]
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

@ -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: '',
@ -851,13 +850,15 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
}
case 'SET_GIT_CONFIG': {
const payload: { username: string, token: string, email: string } = action.payload
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 {
@ -869,7 +870,6 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
}
}
default:
throw new Error()
}

Loading…
Cancel
Save