From f38438dab6572dcd51e9721ead9daf2fcff6daa3 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Tue, 6 Dec 2022 16:50:51 +0100 Subject: [PATCH] fix decoding --- apps/debugger/src/app/debugger-api.ts | 2 ++ .../src/app/plugins/parser/code-parser.tsx | 20 +++++++++++++++++-- .../editor/src/lib/providers/hoverProvider.ts | 8 ++++---- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/apps/debugger/src/app/debugger-api.ts b/apps/debugger/src/app/debugger-api.ts index c562d76f1a..f33c46763b 100644 --- a/apps/debugger/src/app/debugger-api.ts +++ b/apps/debugger/src/app/debugger-api.ts @@ -174,10 +174,12 @@ export const DebuggerApiMixin = (Base) => class extends Base { onStartDebugging () { this.call('layout', 'maximiseSidePanel') + this.emit('startDebugging') } onStopDebugging () { this.call('layout', 'resetSidePanel') + this.emit('stopDebugging') } } diff --git a/apps/remix-ide/src/app/plugins/parser/code-parser.tsx b/apps/remix-ide/src/app/plugins/parser/code-parser.tsx index e378223a81..cb66b490ba 100644 --- a/apps/remix-ide/src/app/plugins/parser/code-parser.tsx +++ b/apps/remix-ide/src/app/plugins/parser/code-parser.tsx @@ -78,6 +78,8 @@ export class CodeParser extends Plugin { setCurrentFileAST: (text?: string) => Promise getImports: () => Promise + debuggerIsOn: boolean = false + constructor(astWalker: any) { super(profile) @@ -98,7 +100,7 @@ export class CodeParser extends Plugin { } const showGasSettings = await this.call('config', 'getAppParameter', 'show-gas') const showErrorSettings = await this.call('config', 'getAppParameter', 'display-errors') - if (showGasSettings || showErrorSettings || completionSettings) { + if (showGasSettings || showErrorSettings || completionSettings || this.debuggerIsOn) { await this.compilerService.compile() } } @@ -159,6 +161,16 @@ export class CodeParser extends Plugin { this.on('solidity', 'compilerLoaded', async () => { await this.reload() }) + + this.on('debugger', 'startDebugging', async () => { + this.debuggerIsOn = true + await this.reload() + }) + + this.on('debugger', 'stopDebugging', async () => { + this.debuggerIsOn = false + await this.reload() + }) } async reload(){ @@ -338,7 +350,11 @@ export class CodeParser extends Plugin { * @returns */ async nodesAtPosition(position: number, type = ''): Promise { - const lastCompilationResult = this.compilerAbstract + let lastCompilationResult = this.compilerAbstract + if(this.debuggerIsOn) { + lastCompilationResult = await this.call('compilerArtefacts', 'get', '__last') + this.currentFile = await this.call('fileManager', 'file') + } if (!lastCompilationResult) return [] const urlFromPath = await this.call('fileManager', 'getUrlFromPath', this.currentFile) if (lastCompilationResult && lastCompilationResult.languageversion.indexOf('soljson') === 0 && lastCompilationResult.data && lastCompilationResult.data.sources && lastCompilationResult.data.sources[this.currentFile]) { diff --git a/libs/remix-ui/editor/src/lib/providers/hoverProvider.ts b/libs/remix-ui/editor/src/lib/providers/hoverProvider.ts index b3694ce970..5606e6741a 100644 --- a/libs/remix-ui/editor/src/lib/providers/hoverProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/hoverProvider.ts @@ -148,18 +148,18 @@ export class RemixHoverProvider implements languages.HoverProvider { try { const decodedVar = await this.props.plugin.call('debugger', 'decodeLocalVariable', nodeAtPosition.id) - if (decodedVar !== null) { + if (decodedVar !== null && decodedVar.type) { contents.push({ - value: JSON.stringify(decodedVar.value, null, '\t') + value: `LOCAL VARIABLE ${nodeAtPosition.name}: ${JSON.stringify(decodedVar.value, null, '\t')}` }) } } catch (e) {} try { const decodedVar = await this.props.plugin.call('debugger', 'decodeStateVariable', nodeAtPosition.id) - if (decodedVar !== null) { + if (decodedVar !== null && decodedVar.type) { contents.push({ - value: JSON.stringify(decodedVar.value, null, '\t') + value: `STATE VARIABLE ${nodeAtPosition.name}: ${JSON.stringify(decodedVar.value, null, '\t')}` }) } } catch (e) {}