Commit 369279cb authored by tizah's avatar tizah

refactored static analysis to improve performance

parent 43ae28e4
import React from 'react' //eslint-disable-line
interface StaticAnalyserCheckBoxProps {
onClick?: (event) => void
onChange?: (event) => void
label?: string
inputType?: string
name?: string
checked?: boolean
id?: string
itemName?: string
categoryId?: string
}
const StaticAnalyserCheckedBox = ({
id,
label,
onClick,
inputType,
name,
checked,
onChange,
itemName,
categoryId
}: StaticAnalyserCheckBoxProps) => {
return (
<div className="listenOnNetwork_2A0YE0 custom-control custom-checkbox" style={{ display: 'flex', alignItems: 'center' }} onClick={onClick}>
<input
id={id}
type={inputType}
onChange={onChange}
style={{ verticalAlign: 'bottom' }}
name={name}
className="custom-control-input"
checked={checked}
/>
<label className="form-check-label custom-control-label" id={`heading${categoryId}`} style={{ paddingTop: '0.15rem' }}>
{name ? <div className="font-weight-bold">{itemName}</div> : ''}
{label}
</label>
</div>
)
}
export default StaticAnalyserCheckedBox
import React, { useState } from 'react' //eslint-disable-line import React from 'react' //eslint-disable-line
interface ErrorRendererProps { interface ErrorRendererProps {
message: any; message: any;
...@@ -32,6 +32,7 @@ const ErrorRenderer = ({ message, opt, editor }: ErrorRendererProps) => { ...@@ -32,6 +32,7 @@ const ErrorRenderer = ({ message, opt, editor }: ErrorRendererProps) => {
if (!message) return if (!message) return
let position = getPositionDetails(message) let position = getPositionDetails(message)
console.log({ position })
if (!position.errFile || (opt.errorType && opt.errorType === position.errFile)) { if (!position.errFile || (opt.errorType && opt.errorType === position.errFile)) {
// Updated error reported includes '-->' before file details // Updated error reported includes '-->' before file details
const errorDetails = message.split('-->') const errorDetails = message.split('-->')
......
import React, { useState } from 'react' //eslint-disable-line import React from 'react' //eslint-disable-line
export const compilation = (analysisModule, state, run) => { export const compilation = (analysisModule, dispatch) => {
// const setCompilationResult = async (data, source, file) => {
// await setResult({ lastCompilationResult: data, lastCompilationSource: source, currentFile: file })
// }
if (analysisModule) { if (analysisModule) {
analysisModule.on( analysisModule.on(
'solidity', 'solidity',
'compilationFinished', 'compilationFinished',
(file, source, languageVersion, data) => { (file, source, languageVersion, data) => {
if (languageVersion.indexOf('soljson') !== 0) return if (languageVersion.indexOf('soljson') !== 0) return
setCompilationResult(data, source, file) dispatch({ type: 'compilationFinished', payload: { file, source, languageVersion, data } })
if (state.categoryIndex.length > 0) {
run(data, source, file)
}
} }
) )
} }
} }
export const setCompilationResult = async (data, source, file) => {
return await { data, source, file }
}
import remixLib from '@remix-project/remix-lib'
import * as _ from 'lodash'
const StaticAnalysisRunner = require('@remix-project/remix-analyzer').CodeAnalysis
const utils = remixLib.util export const initialState = {
file: null,
const runner = new StaticAnalysisRunner() source: null,
languageVersion: null,
const preProcessModules = (arr: any) => { data: null
return arr.map((Item, i) => {
const itemObj = new Item()
itemObj._index = i
itemObj.categoryDisplayName = itemObj.category.displayName
itemObj.categoryId = itemObj.category.id
return itemObj
})
} }
const groupedModules = utils.groupBy(
preProcessModules(runner.modules()),
'categoryId'
)
const getIndex = (modules, array) => {
Object.values(modules).map((value: {_index}) => {
if (Array.isArray(value)) {
value.forEach((x) => {
array.push(x._index.toString())
})
} else {
array.push(value._index.toString())
}
})
}
const groupedModuleIndex = (modules) => {
const indexOfCategory = []
if (!_.isEmpty(modules)) {
getIndex(modules, indexOfCategory)
}
return indexOfCategory
}
export const initialState = { categoryIndex: [] }
export const analysisReducer = (state, action) => { export const analysisReducer = (state, action) => {
switch (action.type) { switch (action.type) {
case 'initialize': case 'compilationFinished':
return { ...state, categoryIndex: groupedModuleIndex(groupedModules) }
case 'uncheck':
return { return {
...state, ...state,
categoryIndex: state.categoryIndex.filter((el) => { file: action.payload.file,
return !action.payload.includes(el) source: action.payload.source,
}) languageVersion: action.payload.languageVersion,
data: action.payload.data
} }
case 'check':
return { ...state, categoryIndex: _.uniq([...state.categoryIndex, ...action.payload]) }
case 'uncheckSingle':
return { ...state, categoryIndex: state.categoryIndex.filter(val => val !== action.payload) }
case 'checkSingle':
return { ...state, categoryIndex: _.uniq([...state.categoryIndex, action.payload]) }
default: default:
return { ...state, categoryIndex: groupedModuleIndex(groupedModules) } return initialState
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment