diff --git a/libs/remix-ui/editor-context-view/src/lib/remix-ui-editor-context-view.tsx b/libs/remix-ui/editor-context-view/src/lib/remix-ui-editor-context-view.tsx index ea99c34b99..ca6ca5930c 100644 --- a/libs/remix-ui/editor-context-view/src/lib/remix-ui-editor-context-view.tsx +++ b/libs/remix-ui/editor-context-view/src/lib/remix-ui-editor-context-view.tsx @@ -1,11 +1,27 @@ import React, { useEffect, useState, useRef } from 'react' // eslint-disable-line import { sourceMappingDecoder } from '@remix-project/remix-debug' -import './remix-ui-editor-context-view.css'; +import './remix-ui-editor-context-view.css' + +/* eslint-disable-next-line */ + +export type astNode = { + name: string, + id: number, + children: Array, + typeDescriptions: any, + nodeType: String, + src: any, + nodeId: any, + position: any +} export type onContextListenerChangedListener = (nodes: Array) => void -/* eslint-disable-next-line */ +export type gasEstimationType = { + executionCost: string, + codeDepositCost: string +} export interface RemixUiEditorContextViewProps { hide: boolean, gotoLine: (line: number, column: number) => void, @@ -29,39 +45,25 @@ function isDefinition (node: any) { node.nodeType === 'EventDefinition' } -export type gasEstimationType = { - executionCost: string, - codeDepositCost: string -} -export type astNode = { - name: string, - id: number, - children: Array, - typeDescriptions: any, - nodeType: String, - src: any, - nodeId: any, - position: any -} type nullableAstNode = astNode | null -export function RemixUiEditorContextView(props: RemixUiEditorContextViewProps) { +export function RemixUiEditorContextView (props: RemixUiEditorContextViewProps) { const nodesRef = useRef>([]) /* - gotoLineDisableRef is used to temporarily disable the update of the view. + gotoLineDisableRef is used to temporarily disable the update of the view. e.g when the user ask the component to "gotoLine" we don't want to rerender the component (but just to put the mouse on the desired line) */ const referencesRef = useRef([]) const activeHighlightsRef = useRef([]) const currentNodeRef = useRef(null as nullableAstNode) const gasEstimationRef = useRef({} as gasEstimationType) - const gotoLineDisableRef = useRef(false) - const [nodesState, setNode] = useState>([]) - + const gotoLineDisableRef = useRef(false) + const [, setNode] = useState>([]) + useEffect(() => { - props.onContextListenerChanged(async (nodes: Array) => { + props.onContextListenerChanged(async (nodes: Array) => { if (gotoLineDisableRef.current) { gotoLineDisableRef.current = false return @@ -75,23 +77,23 @@ export function RemixUiEditorContextView(props: RemixUiEditorContextViewProps) { } if (currentNodeRef.current) { referencesRef.current = await props.referencesOf(currentNodeRef.current) - gasEstimationRef.current = await props.gasEstimation(currentNodeRef.current) + gasEstimationRef.current = await props.gasEstimation(currentNodeRef.current) } - activeHighlightsRef.current = await props.getActiveHighlights() + activeHighlightsRef.current = await props.getActiveHighlights() setNode(nodes) }) }, []) const _render = (node: nullableAstNode) => { if (!node) return (
) - let references = referencesRef.current + const references = referencesRef.current const type = node.typeDescriptions && node.typeDescriptions.typeString ? node.typeDescriptions.typeString : node.nodeType - let referencesCount = `${references ? references.length : '0'} reference(s)` + const referencesCount = `${references ? references.length : '0'} reference(s)` let ref = 0 const nodes: Array = activeHighlightsRef.current - - /* + + /* * show gas estimation */ const gasEstimation = () => { @@ -120,7 +122,7 @@ export function RemixUiEditorContextView(props: RemixUiEditorContextViewProps) { await props.openFile(fileName) } if (lineColumn.start && lineColumn.start.line && lineColumn.start.column) { - gotoLineDisableRef.current = true + gotoLineDisableRef.current = true props.gotoLine(lineColumn.start.line, lineColumn.end.column + 1) } } @@ -164,13 +166,13 @@ export function RemixUiEditorContextView(props: RemixUiEditorContextViewProps) { ) - } + } return ( !props.hide &&
{_render(currentNodeRef.current)}
- ); + ) } export default RemixUiEditorContextView