add provider

pull/4175/head
bunsenstraat 1 year ago committed by yann300
parent e79bd99212
commit 81357381f1
  1. 75
      libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts
  2. 2
      libs/remix-ui/editor/src/lib/remix-ui-editor.tsx

@ -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<monacoTypes.languages.InlineCompletions<monacoTypes.languages.InlineCompletion>> {
// 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<monacoTypes.languages.InlineCompletion>, item: monacoTypes.languages.InlineCompletion, updatedInsertText: string): void {
}
handlePartialAccept?(completions: monacoTypes.languages.InlineCompletions<monacoTypes.languages.InlineCompletion>, item: monacoTypes.languages.InlineCompletion, acceptedCharacters: number): void {
}
freeInlineCompletions(completions: monacoTypes.languages.InlineCompletions<monacoTypes.languages.InlineCompletion>): void {
}
groupId?: string;
yieldsToGroupIds?: string[];
toString?(): string {
throw new Error('Method not implemented.');
}
}

@ -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)

Loading…
Cancel
Save