fix multiple issues identified by @bunsentraat and @Aniket_Eng

pull/5370/head
Joseph Izang 2 years ago committed by Aniket
parent 6d45a588b4
commit b0ac1c22ec
  1. 12
      apps/remix-ide/src/app/files/fileManager.ts
  2. 1
      apps/remix-ide/src/app/panels/tab-proxy.js
  3. 50
      apps/remix-ide/src/app/plugins/solidity-umlgen.tsx
  4. 2
      apps/remix-ide/src/remixAppManager.js
  5. 2
      libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx
  6. 3
      libs/remix-ui/solidity-uml-gen/src/lib/solidity-uml-gen.tsx

@ -5,6 +5,7 @@ import Registry from '../state/registry'
import { EventEmitter } from 'events' import { EventEmitter } from 'events'
import { fileChangedToastMsg, recursivePasteToastMsg, storageFullMessage } from '@remix-ui/helper' import { fileChangedToastMsg, recursivePasteToastMsg, storageFullMessage } from '@remix-ui/helper'
import helper from '../../lib/helper.js' import helper from '../../lib/helper.js'
import { RemixAppManager } from '../../remixAppManager'
/* /*
attach to files event (removed renamed) attach to files event (removed renamed)
@ -40,7 +41,7 @@ class FileManager extends Plugin {
events: EventEmitter events: EventEmitter
editor: any editor: any
_components: any _components: any
appManager: any appManager: RemixAppManager
_deps: any _deps: any
getCurrentFile: () => any getCurrentFile: () => any
getFile: (path: any) => Promise<unknown> getFile: (path: any) => Promise<unknown>
@ -622,13 +623,20 @@ class FileManager extends Plugin {
file = resolved.file file = resolved.file
await this.saveCurrentFile() await this.saveCurrentFile()
if (this.currentFile() === file) return if (this.currentFile() === file) return
const provider = resolved.provider const provider = resolved.provider
this._deps.config.set('currentFile', file) this._deps.config.set('currentFile', file)
this.openedFiles[file] = file this.openedFiles[file] = file
let content = '' let content = ''
try { 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) { } catch (error) {
console.log(error) console.log(error)
throw error throw error

@ -183,6 +183,7 @@ export class TabProxy extends Plugin {
} }
focus (name) { focus (name) {
console.log('what switched tabs', name)
this.emit('switchApp', name) this.emit('switchApp', name)
this.tabsApi.activateTab(name) this.tabsApi.activateTab(name)
} }

@ -10,7 +10,7 @@ import { convertUmlClasses2Dot } from 'sol2uml/lib/converterClasses2Dot'
import { convertAST2UmlClasses } from 'sol2uml/lib/converterAST2Classes' import { convertAST2UmlClasses } from 'sol2uml/lib/converterAST2Classes'
import vizRenderStringSync from '@aduh95/viz.js/sync' import vizRenderStringSync from '@aduh95/viz.js/sync'
import { PluginViewWrapper } from '@remix-ui/helper' 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 parser = (window as any).SolidityParser
const profile = { const profile = {
@ -41,7 +41,23 @@ export class SolidityUmlGen extends ViewPlugin implements ISolidityUmlGen {
} }
onActivation(): void { 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 { onDeactivation(): void {
@ -49,25 +65,13 @@ export class SolidityUmlGen extends ViewPlugin implements ISolidityUmlGen {
} }
generateCustomAction = async (action: customAction) => { generateCustomAction = async (action: customAction) => {
this.currentFile = action.path[0]
this.generateUml(action.path[0]) this.generateUml(action.path[0])
} }
generateUml(currentFile: string) { generateUml(currentFile: string) {
this.call('solidity', 'compile', currentFile) this.call('solidity', 'compile', currentFile)
this.on('solidity', 'compilationFinished', async (file, source, languageVersion, data, input, version) => { this.renderComponent()
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)
})
} }
/** /**
@ -88,18 +92,8 @@ export class SolidityUmlGen extends ViewPlugin implements ISolidityUmlGen {
return result return result
} }
async showUmlDiagram(path: string, svgPayload: string) { async showUmlDiagram(svgPayload: string) {
if (!this.amIActivated) return this.updatedSvg = svgPayload
if((!path && path.length < 1) || (svgPayload.length < 1 || !svgPayload.startsWith('<?xml'))) {
await this.call('notification', 'alert', {
id: 'solidityumlgenAlert',
message: 'Both file path and svg payload are required!'
})
return
} else {
this.currentFile = path
this.updatedSvg = svgPayload
}
this.renderComponent() this.renderComponent()
} }

@ -179,7 +179,7 @@ export class RemixAppManager extends PluginManager {
await this.call('filePanel', 'registerContextMenuItem', { await this.call('filePanel', 'registerContextMenuItem', {
id: 'solidityumlgen', id: 'solidityumlgen',
name: 'generateCustomAction', name: 'generateCustomAction',
label: 'generate UML', label: 'Generate UML',
type: [], type: [],
extension: ['.sol'], extension: ['.sol'],
path: [], path: [],

@ -13,7 +13,6 @@ import { configFileContent } from './compilerConfiguration'
import axios, { AxiosResponse } from 'axios' import axios, { AxiosResponse } from 'axios'
import './css/style.css' import './css/style.css'
const defaultPath = "compiler_config.json" const defaultPath = "compiler_config.json"
declare global { declare global {
@ -22,7 +21,6 @@ declare global {
_paq: any _paq: any
} }
} }
const _paq = window._paq = window._paq || [] //eslint-disable-line const _paq = window._paq = window._paq || [] //eslint-disable-line
export const CompilerContainer = (props: CompilerContainerProps) => { export const CompilerContainer = (props: CompilerContainerProps) => {

@ -39,7 +39,6 @@ export function RemixUiSolidityUmlGen ({ plugin, updatedSvg }: RemixUiSolidityUm
useEffect(() => { useEffect(() => {
console.log('updatedSvg updated')
setValidSvg (updatedSvg.startsWith('<?xml') && updatedSvg.includes('<svg')) setValidSvg (updatedSvg.startsWith('<?xml') && updatedSvg.includes('<svg'))
setShowViewer(updatedSvg.startsWith('<?xml') && updatedSvg.includes('<svg')) setShowViewer(updatedSvg.startsWith('<?xml') && updatedSvg.includes('<svg'))
} }
@ -62,7 +61,7 @@ export function RemixUiSolidityUmlGen ({ plugin, updatedSvg }: RemixUiSolidityUm
<div className="d-flex justify-center align-content-center"> <div className="d-flex justify-center align-content-center">
{/* <ActionButtons buttons={buttons}/> */} {/* <ActionButtons buttons={buttons}/> */}
</div> </div>
<div id="umlImageHolder" className="mx-2 my-3 ml-5"> <div id="umlImageHolder" className="mx-2 my-3 ml-5 w-100">
{ validSvg && showViewer ? ( { validSvg && showViewer ? (
<TransformWrapper> <TransformWrapper>
<TransformComponent> <TransformComponent>

Loading…
Cancel
Save