From 9903038b2861bf5139cbd6012e894092c8830012 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Tue, 17 May 2022 08:26:38 +0200 Subject: [PATCH] mv class --- .../editor/src/lib/providers/hoverProvider.ts | 2 +- .../editor/src/lib/remix-ui-editor.tsx | 135 +----------------- 2 files changed, 2 insertions(+), 135 deletions(-) diff --git a/libs/remix-ui/editor/src/lib/providers/hoverProvider.ts b/libs/remix-ui/editor/src/lib/providers/hoverProvider.ts index 3b3426b469..6e9fba6013 100644 --- a/libs/remix-ui/editor/src/lib/providers/hoverProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/hoverProvider.ts @@ -1,6 +1,6 @@ -export class RemixHoverProvide { +export class RemixHoverProvider { props: any monaco: any diff --git a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx index 60e333a848..e65c636929 100644 --- a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx +++ b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx @@ -473,140 +473,7 @@ export const EditorUI = (props: EditorUIProps) => { } }) - monacoRef.current.languages.registerHoverProvider('remix-solidity', { - provideHover: async function (model: any, position: monaco.Position) { - const cursorPosition = props.editorAPI.getHoverPosition(position) - const nodeDefinition = await props.plugin.call('contextualListener', 'definitionAtPosition', cursorPosition) - console.log(nodeDefinition) - const contents = [] - - const getDocs = async (node: any) => { - if (node.documentation && node.documentation.text) { - let text = '' - node.documentation.text.split('\n').forEach(line => { - text += `${line.trim()}\n` - }) - contents.push({ - - value: text - }) - } - } - - const getLinks = async (node: any) => { - const position = await props.plugin.call('contextualListener', 'positionOfDefinition', node) - const lastCompilationResult = await props.plugin.call('compilerArtefacts', 'getLastCompilationResult') - const filename = lastCompilationResult.getSourceName(position.file) - console.log(filename, position) - const lineColumn = await props.plugin.call('offsetToLineColumnConverter', 'offsetToLineColumn', - position, - position.file, - lastCompilationResult.getSourceCode().sources, - lastCompilationResult.getAsts()) - contents.push({ - value: `${filename} ${lineColumn.start.line}:${lineColumn.start.column}` - }) - } - - const getVariableDeclaration = async (node: any) => { - if (node.typeDescriptions && node.typeDescriptions.typeString) { - return `${node.typeDescriptions.typeString}${node.name && node.name.length ? ` ${node.name}` : ''}` - } - } - - const getParamaters = async (parameters: any) => { - if (parameters && parameters.parameters) { - let params = [] - for (const param of parameters.parameters) { - params.push(await getVariableDeclaration(param)) - } - return `(${params.join(', ')})` - } - } - - const getOverrides = async (node: any) => { - if (node.overrides) { - let overrides = [] - for (const override of node.overrides.overrides) { - overrides.push(override.name) - } - if (overrides.length) - return ` overrides (${overrides.join(', ')})` - } - return '' - } - - const getlinearizedBaseContracts = async (node: any) => { - let params = [] - for (const id of node.linearizedBaseContracts) { - const baseContract = await props.plugin.call('contextualListener', 'getNodeById', id) - params.push( - baseContract.name - ) - } - if (params.length) - return `is ${params.join(', ')}` - return '' - } - - if (!nodeDefinition) return null - if (nodeDefinition.absolutePath) { - const target = await props.plugin.call('fileManager', 'getPathFromUrl', nodeDefinition.absolutePath) - if (target.file !== nodeDefinition.absolutePath) { - contents.push({ - value: `${target.file}` - }) - } - contents.push({ - value: `${nodeDefinition.absolutePath}` - }) - } - if (nodeDefinition.typeDescriptions && nodeDefinition.nodeType === 'VariableDeclaration') { - contents.push({ - value: await getVariableDeclaration(nodeDefinition) - }) - - } - else if (nodeDefinition.typeDescriptions && nodeDefinition.nodeType === 'ElementaryTypeName') { - contents.push({ - value: `${nodeDefinition.typeDescriptions.typeString}` - }) - - } else if (nodeDefinition.nodeType === 'FunctionDefinition') { - contents.push({ - value: `function ${nodeDefinition.name} ${await getParamaters(nodeDefinition.parameters)} ${nodeDefinition.visibility} ${nodeDefinition.stateMutability}${await getOverrides(nodeDefinition)} returns ${await getParamaters(nodeDefinition.returnParameters)}` - }) - - - } else if (nodeDefinition.nodeType === 'ContractDefinition') { - contents.push({ - value: `${nodeDefinition.contractKind} ${nodeDefinition.name} ${await getlinearizedBaseContracts(nodeDefinition)}` - }) - - - } else { - contents.push({ - value: `${nodeDefinition.nodeType}` - }) - - } - getLinks(nodeDefinition) - for (const key in contents) { - contents[key].value = '```remix-solidity\n' + contents[key].value + '\n```' - } - getDocs(nodeDefinition) - - return { - range: new monaco.Range( - position.lineNumber, - position.column, - position.lineNumber, - model.getLineMaxColumn(position.lineNumber) - ), - contents: contents - }; - } - }) + monacoRef.current.languages.registerHoverProvider('remix-solidity', new RemixHoverProvider(props, monaco)) loadTypes(monacoRef.current) }