pull/5370/head
bunsenstraat 2 years ago
parent e40f476127
commit 7950559fad
  1. 9
      apps/remix-ide/src/app/plugins/parser/services/code-parser-antlr-service.ts

@ -25,6 +25,7 @@ export default class CodeParserAntlrService {
parserStartTime: number = 0 parserStartTime: number = 0
workerTimer: NodeJS.Timer workerTimer: NodeJS.Timer
parserTreshHold: number = 10 parserTreshHold: number = 10
parserTrehsholdSampleAmount = 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.parserTrehsholdSampleAmount), 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.parserTrehsholdSampleAmount-1)) {
// 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.parserTreshHold) {
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.parserTrehsholdSampleAmount), 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