From 0a2935e862ec67783da6713dff5c3129edb29621 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Wed, 18 May 2022 10:46:40 +0200 Subject: [PATCH] signature --- apps/remix-ide/src/app/editor/editor.js | 1 - libs/remix-solidity/src/compiler/types.ts | 2 +- .../src/lib/providers/completionProvider.ts | 24 ++++++++++ .../src/lib/providers/signatureProvider.ts | 45 +++++++++++++++++++ .../editor/src/lib/remix-ui-editor.tsx | 7 ++- 5 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 libs/remix-ui/editor/src/lib/providers/completionProvider.ts create mode 100644 libs/remix-ui/editor/src/lib/providers/signatureProvider.ts diff --git a/apps/remix-ide/src/app/editor/editor.js b/apps/remix-ide/src/app/editor/editor.js index 05b7feadcf..cffc874985 100644 --- a/apps/remix-ide/src/app/editor/editor.js +++ b/apps/remix-ide/src/app/editor/editor.js @@ -163,7 +163,6 @@ class Editor extends Plugin { } async _onChange (file) { - console.log(file) const currentFile = await this.call('fileManager', 'file') if (!currentFile) { return diff --git a/libs/remix-solidity/src/compiler/types.ts b/libs/remix-solidity/src/compiler/types.ts index 76ed36ca17..912c1793cd 100644 --- a/libs/remix-solidity/src/compiler/types.ts +++ b/libs/remix-solidity/src/compiler/types.ts @@ -123,7 +123,7 @@ export interface CompilerInput { outputSelection?: { '*': { '': [ 'ast' ], - '*': [ 'abi', 'metadata', 'devdoc', 'userdoc', 'storageLayout', 'evm.legacyAssembly', 'evm.bytecode', 'evm.deployedBytecode', 'evm.methodIdentifiers', 'evm.gasEstimates', 'evm.assembly' ] + //'*': [ 'abi', 'metadata', 'devdoc', 'userdoc', 'storageLayout', 'evm.legacyAssembly', 'evm.bytecode', 'evm.deployedBytecode', 'evm.methodIdentifiers', 'evm.gasEstimates', 'evm.assembly' ] } } } diff --git a/libs/remix-ui/editor/src/lib/providers/completionProvider.ts b/libs/remix-ui/editor/src/lib/providers/completionProvider.ts new file mode 100644 index 0000000000..8fb3f2df04 --- /dev/null +++ b/libs/remix-ui/editor/src/lib/providers/completionProvider.ts @@ -0,0 +1,24 @@ + +export class RemixCompletionProvider { + + props: any + monaco: any + constructor(props: any, monaco: any) { + this.props = props + this.monaco = monaco + } + + triggerCharacters = ['.', ' '] + async provideCompletionItems(model: any, position: any) { + const textUntilPosition = model.getValueInRange({ + startLineNumber: 1, + startColumn: 1, + endLineNumber: position.lineNumber, + endColumn: position.column + }); + console.log(textUntilPosition) + return { + suggestions: [] + } + } +} \ No newline at end of file diff --git a/libs/remix-ui/editor/src/lib/providers/signatureProvider.ts b/libs/remix-ui/editor/src/lib/providers/signatureProvider.ts new file mode 100644 index 0000000000..1d4bb2af91 --- /dev/null +++ b/libs/remix-ui/editor/src/lib/providers/signatureProvider.ts @@ -0,0 +1,45 @@ +// https://github.com/maziac/binary-file-viewer/blob/c71ab6043867717327ef546f1646938fd4733548/src/signatureprovider.ts +export class RemixSignatureProvider { + + props: any + monaco: any + constructor(props: any, monaco: any) { + this.props = props + this.monaco = monaco + } + + public signatureHelpTriggerCharacters = ['(', ',']; + async provideSignatureHelp(model: any, position: any, token: any, context: any) { + console.log(`providing signature help`, context); + console.log(position) + const line = model.getLineContent(position.lineNumber); + + // find position of the opening parenthesis before the cursor + const openParenIndex = line.lastIndexOf('(', position.column - 1); + console.log(openParenIndex) + const newPosition = new this.monaco.Position(position.lineNumber - 1, openParenIndex -1); + const cursorPosition = this.props.editorAPI.getHoverPosition(newPosition) + const nodeDefinition = await this.props.plugin.call('contextualListener', 'definitionAtPosition', cursorPosition) + + console.log(nodeDefinition) + + return { + value: { + signatures: [{ + label: "test(var1, var2)", + parameters: [{ + label: "var1", + documentation: "param 1" + }, + { + label: "var2", + documentation: "param 2" + }] + }], + activeSignature: 0, + activeParameter: 0 + }, + dispose: () => { } + }; + } +} \ No newline at end of file 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 7c724c3758..a8a7e81836 100644 --- a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx +++ b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx @@ -12,6 +12,8 @@ import { IPosition, languages } from 'monaco-editor' import { sourceMappingDecoder } from '@remix-project/remix-debug' import { RemixHoverProvider } from './providers/hoverProvider' import { RemixReferenceProvider } from './providers/referenceProvider' +import { RemixCompletionProvider } from './providers/completionProvider' +import { RemixSignatureProvider } from './providers/signatureProvider' type cursorPosition = { startLineNumber: number, @@ -437,8 +439,11 @@ export const EditorUI = (props: EditorUIProps) => { monacoRef.current.languages.registerReferenceProvider('remix-solidity', new RemixReferenceProvider(props, monaco)) monacoRef.current.languages.registerHoverProvider('remix-solidity', new RemixHoverProvider(props, monaco)) - + monacoRef.current.languages.registerCompletionItemProvider('remix-solidity', new RemixCompletionProvider(props, monaco)) + monacoRef.current.languages.registerSignatureHelpProvider('remix-solidity', new RemixSignatureProvider(props, monaco)) loadTypes(monacoRef.current) + + props.plugin.call() } return (