-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add Sol2Uml To Remix #3245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add Sol2Uml To Remix #3245
Changes from all commits
Commits
Show all changes
104 commits
Select commit
Hold shift + click to select a range
e1898d5
add sol2uml package
joeizang 928f70c
add react-viewer to view generated artifacts
joeizang f566f93
trying out convertAST2UML function
joeizang 35034e0
remove direct installation of solidity-parser package
joeizang 1c8a9ff
parser
3eed4aa
trying out convertAST2UML function
joeizang dffa2d2
remove direct installation of solidity-parser package
joeizang 4db9eb6
import file writer
joeizang 9a32abd
generate svg
joeizang 074564b
generateUML function refactor
joeizang 42e51c1
Move markup to after contract selector
joeizang bf169e9
move
joeizang ae5b368
add transalationslots. fix flatter logic
joeizang f1cd5a6
add comments
joeizang 8ec02ee
load svg in viewer. add pdf packages
joeizang 86b2d92
finish conditional display of flattener button
joeizang a0056fc
fix e2e test
joeizang 6831b66
cleanup
joeizang b7c5b80
move custom tooltip position
joeizang 503d358
disable custom tooltip from verticalIconPanel
joeizang e18e1e3
fix e2e caused by showFlattener && git push
joeizang 325d8ec
simplify condition to show flatten button
joeizang 0ed4f45
fix e2e
joeizang 5cd920e
fix e2e
joeizang 89fc395
uncomment customtooltip
joeizang ad6eae5
cache result
joeizang 9518074
save flattened sol file
joeizang 4b9c37d
intercept blob and encode to base64 string for file explorer
joeizang cf9c734
remove exception throwing logc and replace
joeizang b6d9ffa
localize pdf logic
joeizang 2c92333
install missing dependencies after fixing conflicts
joeizang 48f399e
add changes as @Aniket-Engg comments
joeizang fceb7d7
add changes from @lianaHus & @aniket_engg
joeizang ea1a449
clean out redundancies in file explorer
joeizang 7a9f056
cleanup
joeizang 87b3abe
fix false positive about react-intl
joeizang 7b625fd
generate uml svg. persist flattened contract and svg to file explorer
joeizang fd629a1
add solidity-uml-gen react lib
joeizang ac2ba3e
add solidity-umlgen builtin plugin
joeizang 3698939
clean up contract-selection
joeizang 535eee8
finish cleanup of contract-selection
joeizang 7f7713f
add react viewer to solidityumlgen react lib
joeizang b3c4876
remove solidityumlgen from auto-activated plugins in app.js
joeizang a397963
add required react import
joeizang b53409d
cleanup app.js and other files
joeizang fdaa778
add uml display logic to plugin. call plugin from react lib
joeizang 3a6a222
add plugin class properties. update plugin interface. clean up redund…
joeizang 251bd9d
changes to plugin
joeizang 4341bf7
tried some changes
joeizang da21e05
fix state
e39c1e9
add sol2uml package
joeizang 2ff1c5a
trying out convertAST2UML function
joeizang 5c16050
remove direct installation of solidity-parser package
joeizang c3020c7
import file writer
joeizang f0da7c0
generate svg
joeizang 09e970f
generateUML function refactor
joeizang c3cbf85
Move markup to after contract selector
joeizang fd83e06
move
joeizang 5cced4b
add transalationslots. fix flatter logic
joeizang 5a16253
add comments
joeizang 1e350ca
load svg in viewer. add pdf packages
joeizang 633f270
finish conditional display of flattener button
joeizang e50cfc0
fix e2e test
joeizang 9732f11
cleanup
joeizang 3e5f36b
disable custom tooltip from verticalIconPanel
joeizang 6852d82
fix e2e caused by showFlattener && git push
joeizang 728852d
simplify condition to show flatten button
joeizang dab7ed0
fix e2e
joeizang 12ce2c5
fix e2e
joeizang 7a18759
uncomment customtooltip
joeizang 41b6f04
cache result
joeizang a4ffdd2
save flattened sol file
joeizang 82c24fa
intercept blob and encode to base64 string for file explorer
joeizang 140f45b
remove exception throwing logc and replace
joeizang 60afe22
install missing dependencies after fixing conflicts
joeizang 4523d3d
add changes as @Aniket-Engg comments
joeizang 15f0d9d
add changes from @lianaHus & @aniket_engg
joeizang 68330d8
clean out redundancies in file explorer
joeizang acd168a
generate uml svg. persist flattened contract and svg to file explorer
joeizang ea76a62
add solidity-umlgen builtin plugin
joeizang 348ba10
clean up contract-selection
joeizang ec13a5d
finish cleanup of contract-selection
joeizang 8bd18a9
remove solidityumlgen from auto-activated plugins in app.js
joeizang 766a574
cleanup app.js and other files
joeizang 3b50930
context menu
3c69435
remove react-viewer. cleanup compiler-container
joeizang 81e9c99
add reac-zoom-pan-pinch
joeizang c4fcaa2
show uml in tab
joeizang 9aa4e8c
fix multiple issues identified by @bunsentraat and @Aniket_Eng
joeizang 3b38336
remove writing files to explorer as per @bunsentraat's recommendations
joeizang 44b210d
clean up and fix auto focus on uml gen
joeizang 9dddf66
fix spacing
joeizang 32f3546
clean up file-explorer and context menu
joeizang efed920
clean up filesystemprovider and context
joeizang 2dcaf76
clean up utils/index.ts
joeizang 7d2bd32
fixing css
joeizang c203b0a
remove event listeners on deactivation. fix css
joeizang 3a01bfb
remove logic to write file during uml gen
joeizang 1a899fa
add types and defaults.
joeizang a43a5b8
update packages. add async await to plugin
joeizang e148cd9
add contractFlattening capabilities without external plugin activation
joeizang a41b605
add fixes from @LianaHus & @Aniket-Engg
joeizang d8da3df
fix color inversion
joeizang 3477c46
fix theme state not updating correctly
joeizang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import React from 'react' | ||
| import { Plugin } from '@remixproject/engine' | ||
| import { customAction } from '@remixproject/plugin-api' | ||
| import { concatSourceFiles, getDependencyGraph } from '@remix-ui/solidity-compiler' | ||
|
|
||
| const profile = { | ||
| name: 'contractflattener', | ||
| displayName: 'Contract Flattener', | ||
| description: 'Flatten solidity contracts', | ||
| methods: ['flattenAContract'], | ||
| events: [], | ||
| } | ||
|
|
||
| export class ContractFlattener extends Plugin { | ||
| fileName: string | ||
| constructor() { | ||
| super(profile) | ||
| this.fileName = '' | ||
| } | ||
|
|
||
| onActivation(): void { | ||
| this.on('solidity', 'compilationFinished', async (file, source, languageVersion, data, input, version) => { | ||
| await this.flattenContract(source, this.fileName, data) | ||
| }) | ||
| } | ||
|
|
||
| async flattenAContract(action: customAction) { | ||
| this.fileName = action.path[0] | ||
| this.call('solidity', 'compile', this.fileName) | ||
| } | ||
|
|
||
| /** | ||
| * Takes currently compiled contract that has a bunch of imports at the top | ||
| * and flattens them ready for UML creation. Takes the flattened result | ||
| * and assigns to a local property | ||
| * @returns {Promise<string>} | ||
| */ | ||
| async flattenContract (source: any, filePath: string, data: any) { | ||
| const ast = data.sources | ||
| const dependencyGraph = getDependencyGraph(ast, filePath) | ||
| const sorted = dependencyGraph.isEmpty() | ||
| ? [filePath] | ||
| : dependencyGraph.sort().reverse() | ||
| const sources = source.sources | ||
| const result = concatSourceFiles(sorted, sources) | ||
| await this.call('fileManager', 'writeFile', `${filePath}_flattened.sol`, result) | ||
| return result | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| /* eslint-disable @nrwl/nx/enforce-module-boundaries */ | ||
| import { ViewPlugin } from '@remixproject/engine-web' | ||
| import React from 'react' | ||
| // eslint-disable-next-line @nrwl/nx/enforce-module-boundaries | ||
| import { RemixUiSolidityUmlGen } from '@remix-ui/solidity-uml-gen' | ||
| import { ISolidityUmlGen } from 'libs/remix-ui/solidity-uml-gen/src/types' | ||
| import { RemixAppManager } from 'libs/remix-ui/plugin-manager/src/types' | ||
| import { concatSourceFiles, getDependencyGraph } from 'libs/remix-ui/solidity-compiler/src/lib/logic/flattenerUtilities' | ||
| 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 } from '@remixproject/plugin-api' | ||
| const parser = (window as any).SolidityParser | ||
|
|
||
| const profile = { | ||
| name: 'solidityumlgen', | ||
| displayName: 'Solidity UML Generator', | ||
| description: 'Generate UML diagram in svg format from last compiled contract', | ||
| location: 'mainPanel', | ||
| methods: ['showUmlDiagram', 'generateUml', 'generateCustomAction'], | ||
| events: [], | ||
| } | ||
|
|
||
| export class SolidityUmlGen extends ViewPlugin implements ISolidityUmlGen { | ||
| element: HTMLDivElement | ||
| currentFile: string | ||
| svgPayload: string | ||
| updatedSvg: string | ||
| currentlySelectedTheme: string | ||
| loading: boolean | ||
|
|
||
| appManager: RemixAppManager | ||
| dispatch: React.Dispatch<any> = () => {} | ||
| constructor(appManager: RemixAppManager) { | ||
| super(profile) | ||
| this.currentFile = '' | ||
| this.svgPayload = '' | ||
| this.updatedSvg = '' | ||
| this.loading = false | ||
| this.currentlySelectedTheme = '' | ||
| this.appManager = appManager | ||
| this.element = document.createElement('div') | ||
| this.element.setAttribute('id', 'sol-uml-gen') | ||
| } | ||
|
|
||
| onActivation(): void { | ||
| 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 umlClasses = convertAST2UmlClasses(ast, this.currentFile) | ||
| const umlDot = convertUmlClasses2Dot(umlClasses) | ||
| const payload = vizRenderStringSync(umlDot) | ||
| const currentTheme = await this.call('theme', 'currentTheme') | ||
| this.currentlySelectedTheme = currentTheme.quality | ||
| this.updatedSvg = payload | ||
| this.renderComponent() | ||
| } catch (error) { | ||
| console.log({ error }) | ||
| } | ||
| }) | ||
| this.on('theme', 'themeChanged', (theme) => { | ||
| this.currentlySelectedTheme = theme.quality | ||
| this.renderComponent() | ||
| }) | ||
| } | ||
|
|
||
| async mangleSvgPayload(svgPayload: string) : Promise<string> { | ||
| const parser = new DOMParser() | ||
| const themeQuality = await this.call('theme', 'currentTheme') | ||
| const parsedDocument = parser.parseFromString(svgPayload, 'image/svg+xml') | ||
| const res = parsedDocument.documentElement | ||
| parsedDocument.bgColor = '#cccabc' | ||
| res.style.filter = themeQuality.quality === 'dark' ? 'invert(1)' : 'invert(0)' | ||
| const stringifiedSvg = new XMLSerializer().serializeToString(parsedDocument) | ||
| console.log({ parsedDocument, themeQuality, stringifiedSvg }) | ||
| return stringifiedSvg | ||
| } | ||
|
|
||
| onDeactivation(): void { | ||
| this.off('solidity', 'compilationFinished') | ||
| } | ||
|
|
||
| generateCustomAction = async (action: customAction) => { | ||
| this.currentFile = action.path[0] | ||
| await this.generateUml(action.path[0]) | ||
| } | ||
|
|
||
| async generateUml(currentFile: string) { | ||
| await this.call('solidity', 'compile', currentFile) | ||
| await this.call('tabs', 'focus', 'solidityumlgen') | ||
| this.loading = true | ||
| this.renderComponent() | ||
| } | ||
|
|
||
| /** | ||
| * Takes currently compiled contract that has a bunch of imports at the top | ||
| * and flattens them ready for UML creation. Takes the flattened result | ||
| * and assigns to a local property | ||
| * @returns {Promise<string>} | ||
| */ | ||
| async flattenContract (source: any, filePath: string, data: any) { | ||
| const hold = { data, source, filePath } | ||
| const ast = data.sources | ||
| const dependencyGraph = getDependencyGraph(ast, filePath) | ||
| const sorted = dependencyGraph.isEmpty() | ||
| ? [filePath] | ||
| : dependencyGraph.sort().reverse() | ||
| const sources = source.sources | ||
| const result = concatSourceFiles(sorted, sources) | ||
| await this.call('fileManager', 'writeFile', `${filePath}_flattened.sol`, result) | ||
| return result | ||
| } | ||
|
|
||
| async showUmlDiagram(svgPayload: string) { | ||
| this.updatedSvg = svgPayload | ||
| this.renderComponent() | ||
| } | ||
|
|
||
| hideSpinner() { | ||
| this.loading = false | ||
| this.renderComponent() | ||
| } | ||
|
|
||
| setDispatch (dispatch: React.Dispatch<any>) { | ||
| this.dispatch = dispatch | ||
| this.renderComponent() | ||
| } | ||
|
|
||
| render() { | ||
| return <div id='sol-uml-gen'> | ||
| <PluginViewWrapper plugin={this} /> | ||
| </div> | ||
| } | ||
|
|
||
| renderComponent () { | ||
| this.dispatch({ | ||
| ...this, | ||
| updatedSvg: this.updatedSvg, | ||
| loading: this.loading, | ||
| themeSelected: this.currentlySelectedTheme | ||
| }) | ||
| } | ||
|
|
||
| updateComponent(state: any) { | ||
| return <RemixUiSolidityUmlGen | ||
| plugin={state} | ||
| updatedSvg={state.updatedSvg} | ||
| loading={state.loading} | ||
| themeSelected={state.currentlySelectedTheme} | ||
| /> | ||
| } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| export * from './lib/solidity-compiler' | ||
| export * from './lib/logic' | ||
| export * from './lib/logic/flattenerUtilities' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this change necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, when left as a string, It becomes difficult to write the pdf to file explorer. Even though deep in the recesses of the plugin engin, it takes a string. Making it any allows me to write the result from generating the pdf to fileexplorer.