Merge pull request #2951 from ethereum/parsertreshhold

remove toast for parser
pull/2953/head
bunsenstraat 2 years ago committed by GitHub
commit 4bd10c600c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      apps/remix-ide/src/app/plugins/parser/services/code-parser-antlr-service.ts

@ -24,7 +24,8 @@ export default class CodeParserAntlrService {
worker: Worker worker: Worker
parserStartTime: number = 0 parserStartTime: number = 0
workerTimer: NodeJS.Timer workerTimer: NodeJS.Timer
parserTreshHold: number = 10 parserThreshold: number = 10
parserThresholdSampleAmount = 3
cache: { cache: {
[name: string]: { [name: string]: {
text: string, text: string,
@ -58,7 +59,7 @@ export default class CodeParserAntlrService {
ast: ev.data.ast, ast: ev.data.ast,
duration: ev.data.duration, duration: ev.data.duration,
blocks: ev.data.blocks, blocks: ev.data.blocks,
blockDurations: self.cache[ev.data.file].blockDurations? [...self.cache[ev.data.file].blockDurations.slice(-3), 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) self.setFileParsingState(ev.data.file)
} }
@ -70,17 +71,15 @@ export default class CodeParserAntlrService {
setFileParsingState(file: string) { setFileParsingState(file: string) {
if (this.cache[file]) { if (this.cache[file]) {
if (this.cache[file].blockDurations && this.cache[file].blockDurations.length > 3) { if (this.cache[file].blockDurations && this.cache[file].blockDurations.length > this.parserThresholdSampleAmount) {
// calculate average of durations to determine if the parsing should be disabled // calculate average of durations to determine if the parsing should be disabled
const values = [...this.cache[file].blockDurations] const values = [...this.cache[file].blockDurations]
const average = values.reduce((a, b) => a + b, 0) / values.length const average = values.reduce((a, b) => a + b, 0) / values.length
if (average > this.parserTreshHold) { if (average > this.parserThreshold) {
this.cache[file].parsingEnabled = false this.cache[file].parsingEnabled = false
this.plugin.call('notification', 'toast','Some autocomplete features will be temporarily disabled because the file takes too long to process.')
} else { } else {
this.cache[file].parsingEnabled = true this.cache[file].parsingEnabled = true
} }
} }
} }
} }
@ -249,7 +248,7 @@ export default class CodeParserAntlrService {
const startTime = Date.now() const startTime = Date.now()
const blocks = (SolidityParser as any).parseBlock(fileContent, { loc: true, range: true, tolerant: true }) 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){ 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(-3), 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) this.setFileParsingState(this.plugin.currentFile)
} }
if (blocks) this.cache[this.plugin.currentFile].blocks = blocks if (blocks) this.cache[this.plugin.currentFile].blocks = blocks

Loading…
Cancel
Save