From b0ac1c22ecad7dc146ab0cfb6d5364abd3daa4ac Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Tue, 24 Jan 2023 23:25:12 +0100 Subject: [PATCH] fix multiple issues identified by @bunsentraat and @Aniket_Eng --- apps/remix-ide/src/app/files/fileManager.ts | 12 ++++- apps/remix-ide/src/app/panels/tab-proxy.js | 1 + .../src/app/plugins/solidity-umlgen.tsx | 50 ++++++++----------- apps/remix-ide/src/remixAppManager.js | 2 +- .../src/lib/compiler-container.tsx | 2 - .../src/lib/solidity-uml-gen.tsx | 3 +- 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/apps/remix-ide/src/app/files/fileManager.ts b/apps/remix-ide/src/app/files/fileManager.ts index 3ecfaadf15..982365459d 100644 --- a/apps/remix-ide/src/app/files/fileManager.ts +++ b/apps/remix-ide/src/app/files/fileManager.ts @@ -5,6 +5,7 @@ import Registry from '../state/registry' import { EventEmitter } from 'events' import { fileChangedToastMsg, recursivePasteToastMsg, storageFullMessage } from '@remix-ui/helper' import helper from '../../lib/helper.js' +import { RemixAppManager } from '../../remixAppManager' /* attach to files event (removed renamed) @@ -40,7 +41,7 @@ class FileManager extends Plugin { events: EventEmitter editor: any _components: any - appManager: any + appManager: RemixAppManager _deps: any getCurrentFile: () => any getFile: (path: any) => Promise @@ -622,13 +623,20 @@ class FileManager extends Plugin { file = resolved.file await this.saveCurrentFile() if (this.currentFile() === file) return + const provider = resolved.provider this._deps.config.set('currentFile', file) this.openedFiles[file] = file let content = '' try { - content = await provider.get(file) + content = await provider.get(file) + if (file.split('.')[1].includes('svg')) { + if (!await this.appManager.isActive('solidityumlgen')) await this.appManager.activatePlugin('solidityumlgen') + provider.isReadOnly(file) + this.call('solidityumlgen', 'showUmlDiagram', content) + return + } } catch (error) { console.log(error) throw error diff --git a/apps/remix-ide/src/app/panels/tab-proxy.js b/apps/remix-ide/src/app/panels/tab-proxy.js index 3821788e18..844a68e8b3 100644 --- a/apps/remix-ide/src/app/panels/tab-proxy.js +++ b/apps/remix-ide/src/app/panels/tab-proxy.js @@ -183,6 +183,7 @@ export class TabProxy extends Plugin { } focus (name) { + console.log('what switched tabs', name) this.emit('switchApp', name) this.tabsApi.activateTab(name) } diff --git a/apps/remix-ide/src/app/plugins/solidity-umlgen.tsx b/apps/remix-ide/src/app/plugins/solidity-umlgen.tsx index 54f68e0ce5..c1e37639a5 100644 --- a/apps/remix-ide/src/app/plugins/solidity-umlgen.tsx +++ b/apps/remix-ide/src/app/plugins/solidity-umlgen.tsx @@ -10,7 +10,7 @@ import { convertUmlClasses2Dot } from 'sol2uml/lib/converterClasses2Dot' import { convertAST2UmlClasses } from 'sol2uml/lib/converterAST2Classes' import vizRenderStringSync from '@aduh95/viz.js/sync' import { PluginViewWrapper } from '@remix-ui/helper' -import { customAction, customActionType } from '@remixproject/plugin-api' +import { customAction } from '@remixproject/plugin-api' const parser = (window as any).SolidityParser const profile = { @@ -41,7 +41,23 @@ export class SolidityUmlGen extends ViewPlugin implements ISolidityUmlGen { } onActivation(): void { - this.amIActivated = true + if (this.currentFile.length < 1) + this.on('solidity', 'compilationFinished', async (file, source, languageVersion, data, input, version) => { + let result = '' + try { + if (data.sources && Object.keys(data.sources).length > 1) { // we should flatten first as there are multiple asts + result = await this.flattenContract(source, this.currentFile, data) + } + const ast = result.length > 1 ? parser.parse(result) : parser.parse(source.sources[this.currentFile].content) + const payload = vizRenderStringSync(convertUmlClasses2Dot(convertAST2UmlClasses(ast, this.currentFile))) + const fileName = `${this.currentFile.split('/')[0]}/resources/${this.currentFile.split('/')[1].split('.')[0]}.svg` + await this.call('fileManager', 'writeFile', fileName, payload) + this.updatedSvg = payload + this.renderComponent() + } catch (error) { + console.log({ error }) + } + }) } onDeactivation(): void { @@ -49,25 +65,13 @@ export class SolidityUmlGen extends ViewPlugin implements ISolidityUmlGen { } generateCustomAction = async (action: customAction) => { + this.currentFile = action.path[0] this.generateUml(action.path[0]) } generateUml(currentFile: string) { this.call('solidity', 'compile', currentFile) - this.on('solidity', 'compilationFinished', async (file, source, languageVersion, data, input, version) => { - let result = '' - if (data.sources && Object.keys(data.sources).length > 1) { // we should flatten first as there are multiple asts - result = await this.flattenContract(source, currentFile, data) - } - const ast = result.length > 1 ? parser.parse(result) : parser.parse(source.sources[currentFile].content) - const payload = vizRenderStringSync(convertUmlClasses2Dot(convertAST2UmlClasses(ast, currentFile))) - const fileName = `${currentFile.split('/')[0]}/resources/${currentFile.split('/')[1].split('.')[0]}.svg` - await this.call('fileManager', 'writeFile', fileName, payload) - this.updatedSvg = payload //test - console.log({ payload }) - this.renderComponent() - // await this.showUmlDiagram(fileName, payload) - }) + this.renderComponent() } /** @@ -88,18 +92,8 @@ export class SolidityUmlGen extends ViewPlugin implements ISolidityUmlGen { return result } - async showUmlDiagram(path: string, svgPayload: string) { - if (!this.amIActivated) return - if((!path && path.length < 1) || (svgPayload.length < 1 || !svgPayload.startsWith(' { diff --git a/libs/remix-ui/solidity-uml-gen/src/lib/solidity-uml-gen.tsx b/libs/remix-ui/solidity-uml-gen/src/lib/solidity-uml-gen.tsx index 598c30997f..7e35ebe8ee 100644 --- a/libs/remix-ui/solidity-uml-gen/src/lib/solidity-uml-gen.tsx +++ b/libs/remix-ui/solidity-uml-gen/src/lib/solidity-uml-gen.tsx @@ -39,7 +39,6 @@ export function RemixUiSolidityUmlGen ({ plugin, updatedSvg }: RemixUiSolidityUm useEffect(() => { - console.log('updatedSvg updated') setValidSvg (updatedSvg.startsWith(' {/* */} -
+
{ validSvg && showViewer ? (