From 4b18f3119def906dad2940c36b0cdf2fb8e7f188 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Thu, 22 Sep 2022 11:25:06 +0200 Subject: [PATCH 1/3] smarter disabling --- .../services/code-parser-antlr-service.ts | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/apps/remix-ide/src/app/plugins/parser/services/code-parser-antlr-service.ts b/apps/remix-ide/src/app/plugins/parser/services/code-parser-antlr-service.ts index f8f8ba0de5..705ff6c2eb 100644 --- a/apps/remix-ide/src/app/plugins/parser/services/code-parser-antlr-service.ts +++ b/apps/remix-ide/src/app/plugins/parser/services/code-parser-antlr-service.ts @@ -30,9 +30,9 @@ export default class CodeParserAntlrService { text: string, ast: antlr.ParseResult | null, duration?: number, - blockDuration?: number, parsingEnabled?: boolean, - blocks?: BlockDefinition[] + blocks?: BlockDefinition[], + blockDurations?: number[] } } = {}; constructor(plugin: CodeParser) { @@ -52,15 +52,15 @@ export default class CodeParserAntlrService { switch (ev.data.cmd) { case 'parsed': if (ev.data.ast && self.parserStartTime === ev.data.timestamp) { - self.setFileParsingState(ev.data.file, ev.data.blockDuration) self.cache[ev.data.file] = { ...self.cache[ev.data.file], text: ev.data.text, ast: ev.data.ast, duration: ev.data.duration, - blockDuration: ev.data.blockDuration, 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] } + self.setFileParsingState(ev.data.file) } break; } @@ -68,16 +68,20 @@ export default class CodeParserAntlrService { }); } - setFileParsingState(file: string, duration: number) { + setFileParsingState(file: string) { if (this.cache[file]) { - if (this.cache[file].blockDuration) { - if (this.cache[file].blockDuration > this.parserTreshHold && duration > this.parserTreshHold) { + if (this.cache[file].blockDurations && this.cache[file].blockDurations.length > 3) { + // calculate average of durations to determine if the parsing should be disabled + const values = [...this.cache[file].blockDurations] + const average = values.reduce((a, b) => a + b, 0) / values.length + if (average > this.parserTreshHold) { this.cache[file].parsingEnabled = false - this.plugin.call('notification', 'toast', `This file is big so some autocomplete features will be disabled.`) + this.plugin.call('notification', 'toast','Some autocomplete features will be disabled temporarily because the file takes too long to process.') } else { this.cache[file].parsingEnabled = true } + } } } From 9960217f0d2457e0754bd33e96ba69c5768eea4b Mon Sep 17 00:00:00 2001 From: bunsenstraat Date: Thu, 22 Sep 2022 11:26:07 +0200 Subject: [PATCH 2/3] Update code-parser-antlr-service.ts --- .../app/plugins/parser/services/code-parser-antlr-service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/remix-ide/src/app/plugins/parser/services/code-parser-antlr-service.ts b/apps/remix-ide/src/app/plugins/parser/services/code-parser-antlr-service.ts index 705ff6c2eb..4eb78ba9eb 100644 --- a/apps/remix-ide/src/app/plugins/parser/services/code-parser-antlr-service.ts +++ b/apps/remix-ide/src/app/plugins/parser/services/code-parser-antlr-service.ts @@ -77,7 +77,7 @@ export default class CodeParserAntlrService { const average = values.reduce((a, b) => a + b, 0) / values.length if (average > this.parserTreshHold) { this.cache[file].parsingEnabled = false - this.plugin.call('notification', 'toast','Some autocomplete features will be disabled temporarily because the file takes too long to process.') + this.plugin.call('notification', 'toast','Some autocomplete features will be temporarily disabled because the file takes too long to process.') } else { this.cache[file].parsingEnabled = true } @@ -283,4 +283,4 @@ export default class CodeParserAntlrService { return block } -} \ No newline at end of file +} From 1dfcb308d135235cb6ac6c28565154c518f22304 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Thu, 22 Sep 2022 11:37:47 +0200 Subject: [PATCH 3/3] fix state set --- .../plugins/parser/services/code-parser-antlr-service.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/remix-ide/src/app/plugins/parser/services/code-parser-antlr-service.ts b/apps/remix-ide/src/app/plugins/parser/services/code-parser-antlr-service.ts index 705ff6c2eb..194d591562 100644 --- a/apps/remix-ide/src/app/plugins/parser/services/code-parser-antlr-service.ts +++ b/apps/remix-ide/src/app/plugins/parser/services/code-parser-antlr-service.ts @@ -69,7 +69,6 @@ export default class CodeParserAntlrService { } setFileParsingState(file: string) { - if (this.cache[file]) { if (this.cache[file].blockDurations && this.cache[file].blockDurations.length > 3) { // calculate average of durations to determine if the parsing should be disabled @@ -131,7 +130,8 @@ export default class CodeParserAntlrService { this.cache[this.plugin.currentFile] = { text: '', ast: null, - parsingEnabled: true + parsingEnabled: true, + blockDurations: [] } } if (this.cache[this.plugin.currentFile] && this.cache[this.plugin.currentFile].text !== fileContent) { @@ -248,7 +248,10 @@ export default class CodeParserAntlrService { try { const startTime = Date.now() const blocks = (SolidityParser as any).parseBlock(fileContent, { loc: true, range: true, tolerant: true }) - this.setFileParsingState(this.plugin.currentFile, 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(-3), Date.now() - startTime] + this.setFileParsingState(this.plugin.currentFile) + } if (blocks) this.cache[this.plugin.currentFile].blocks = blocks return blocks } catch (e) {