From 81357381f1ca4f4f64b2643b86d4d65875842007 Mon Sep 17 00:00:00 2001 From: bunsenstraat Date: Fri, 6 Oct 2023 09:51:15 +0200 Subject: [PATCH] add provider --- .../lib/providers/inlineCompletionProvider.ts | 75 +++++++++++++++++++ .../editor/src/lib/remix-ui-editor.tsx | 2 + 2 files changed, 77 insertions(+) create mode 100644 libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts diff --git a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts new file mode 100644 index 0000000000..71c91e3d80 --- /dev/null +++ b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts @@ -0,0 +1,75 @@ +import { EditorUIProps, monacoTypes } from '@remix-ui/editor'; +const controller = new AbortController(); +const { signal } = controller; +const result: string = '' + +export class RemixInLineCompletionProvider implements monacoTypes.languages.InlineCompletionsProvider { + props: EditorUIProps + monaco: any + constructor(props: any, monaco: any) { + this.props = props + this.monaco = monaco + } + async provideInlineCompletions(model: monacoTypes.editor.ITextModel, position: monacoTypes.Position, context: monacoTypes.languages.InlineCompletionContext, token: monacoTypes.CancellationToken): Promise> { + + // get text before the position of the completion + const word = model.getValueInRange({ + startLineNumber: 1, + startColumn: 1, + endLineNumber: position.lineNumber, + endColumn: position.column, + }); + + // abort if there is a signal + + + const url = 'http://localhost:9090/infer' + const data = {'prefix': 'contract test', 'max_token': 20} + + const response = await fetch(url, { + method: "POST", + mode: "no-cors", + cache: "no-cache", + headers: { + "Content-Type": "application/json", + }, + signal, + redirect: "follow", + referrerPolicy: "no-referrer", + body: JSON.stringify(data), + }); + + + + + console.log(response.body) + console.log('word', word) + + + + const item: monacoTypes.languages.InlineCompletion = { + insertText: { + snippet: 'hello world\nhuman readable', + } + }; + + return { + items: [item], + } + + } + handleItemDidShow?(completions: monacoTypes.languages.InlineCompletions, item: monacoTypes.languages.InlineCompletion, updatedInsertText: string): void { + + } + handlePartialAccept?(completions: monacoTypes.languages.InlineCompletions, item: monacoTypes.languages.InlineCompletion, acceptedCharacters: number): void { + + } + freeInlineCompletions(completions: monacoTypes.languages.InlineCompletions): void { + + } + groupId?: string; + yieldsToGroupIds?: string[]; + toString?(): string { + throw new Error('Method not implemented.'); + } +} \ 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 652e6b3992..3180e69fb3 100644 --- a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx +++ b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx @@ -19,6 +19,7 @@ import { RemixCodeActionProvider } from './providers/codeActionProvider' import './remix-ui-editor.css' import { circomLanguageConfig, circomTokensProvider } from './syntaxes/circom' import { IPosition } from 'monaco-editor' +import { RemixInLineCompletionProvider } from './providers/inlineCompletionProvider' enum MarkerSeverity { Hint = 1, @@ -867,6 +868,7 @@ 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.registerInlineCompletionsProvider('remix-solidity', new RemixInLineCompletionProvider(props, monaco)) monaco.languages.registerCodeActionProvider('remix-solidity', new RemixCodeActionProvider(props, monaco)) loadTypes(monacoRef.current)