|
|
@ -4,6 +4,7 @@ import { CompletionTimer } from './completionTimer'; |
|
|
|
|
|
|
|
|
|
|
|
import axios, { AxiosResponse } from 'axios' |
|
|
|
import axios, { AxiosResponse } from 'axios' |
|
|
|
import { slice } from 'lodash'; |
|
|
|
import { slice } from 'lodash'; |
|
|
|
|
|
|
|
import { activateService } from '@remixproject/plugin-utils'; |
|
|
|
const _paq = (window._paq = window._paq || []) |
|
|
|
const _paq = (window._paq = window._paq || []) |
|
|
|
|
|
|
|
|
|
|
|
const controller = new AbortController(); |
|
|
|
const controller = new AbortController(); |
|
|
@ -14,6 +15,9 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli |
|
|
|
props: EditorUIProps |
|
|
|
props: EditorUIProps |
|
|
|
monaco: any |
|
|
|
monaco: any |
|
|
|
completionEnabled: boolean |
|
|
|
completionEnabled: boolean |
|
|
|
|
|
|
|
task: string |
|
|
|
|
|
|
|
currentCompletion |
|
|
|
|
|
|
|
|
|
|
|
constructor(props: any, monaco: any) { |
|
|
|
constructor(props: any, monaco: any) { |
|
|
|
this.props = props |
|
|
|
this.props = props |
|
|
|
this.monaco = monaco |
|
|
|
this.monaco = monaco |
|
|
@ -28,6 +32,7 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli |
|
|
|
const lineRange = model.getFullModelRange().setStartPosition(lineNumber, 1).setEndPosition(lineNumber + 1, 1); |
|
|
|
const lineRange = model.getFullModelRange().setStartPosition(lineNumber, 1).setEndPosition(lineNumber + 1, 1); |
|
|
|
return model.getValueInRange(lineRange); |
|
|
|
return model.getValueInRange(lineRange); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// get text before the position of the completion
|
|
|
|
// get text before the position of the completion
|
|
|
|
const word = model.getValueInRange({ |
|
|
|
const word = model.getValueInRange({ |
|
|
|
startLineNumber: 1, |
|
|
|
startLineNumber: 1, |
|
|
@ -65,6 +70,7 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli |
|
|
|
// use the code generation model, only take max 1000 word as context
|
|
|
|
// use the code generation model, only take max 1000 word as context
|
|
|
|
this.props.plugin.call('terminal', 'log', { type: 'aitypewriterwarning', value: 'Solcoder - generating code for following comment: ' + ask.replace('///', '') }) |
|
|
|
this.props.plugin.call('terminal', 'log', { type: 'aitypewriterwarning', value: 'Solcoder - generating code for following comment: ' + ask.replace('///', '') }) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.task = 'code_generation' |
|
|
|
const data = await this.props.plugin.call('solcoder', 'code_generation', word) |
|
|
|
const data = await this.props.plugin.call('solcoder', 'code_generation', word) |
|
|
|
|
|
|
|
|
|
|
|
const parsedData = data[0].trimStart() //JSON.parse(data).trimStart()
|
|
|
|
const parsedData = data[0].trimStart() //JSON.parse(data).trimStart()
|
|
|
@ -103,15 +109,15 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli |
|
|
|
if (word.replace(/ +$/, '').endsWith('\n')){ |
|
|
|
if (word.replace(/ +$/, '').endsWith('\n')){ |
|
|
|
// Code insertion
|
|
|
|
// Code insertion
|
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
this.task = 'code_insertion' |
|
|
|
const output = await this.props.plugin.call('solcoder', 'code_insertion', word, word_after) |
|
|
|
const output = await this.props.plugin.call('solcoder', 'code_insertion', word, word_after) |
|
|
|
const generatedText = output[0] // no need to clean it. should already be
|
|
|
|
const generatedText = output[0] // no need to clean it. should already be
|
|
|
|
|
|
|
|
|
|
|
|
const item: monacoTypes.languages.InlineCompletion = { |
|
|
|
const item: monacoTypes.languages.InlineCompletion = { |
|
|
|
insertText: generatedText |
|
|
|
insertText: generatedText |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
this.completionEnabled = false |
|
|
|
this.completionEnabled = false |
|
|
|
const handleCompletionTimer = new CompletionTimer(5000, () => { this.completionEnabled = true }); |
|
|
|
const handleCompletionTimer = new CompletionTimer(1000, () => { this.completionEnabled = true }); |
|
|
|
handleCompletionTimer.start() |
|
|
|
handleCompletionTimer.start() |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
@ -127,6 +133,7 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli |
|
|
|
let result |
|
|
|
let result |
|
|
|
try { |
|
|
|
try { |
|
|
|
// Code completion
|
|
|
|
// Code completion
|
|
|
|
|
|
|
|
this.task = 'code_completion' |
|
|
|
const output = await this.props.plugin.call('solcoder', 'code_completion', word) |
|
|
|
const output = await this.props.plugin.call('solcoder', 'code_completion', word) |
|
|
|
const generatedText = output[0] |
|
|
|
const generatedText = output[0] |
|
|
|
let clean = generatedText |
|
|
|
let clean = generatedText |
|
|
@ -168,14 +175,15 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
handleItemDidShow?(completions: monacoTypes.languages.InlineCompletions<monacoTypes.languages.InlineCompletion>, item: monacoTypes.languages.InlineCompletion, updatedInsertText: string): void { |
|
|
|
handleItemDidShow?(completions: monacoTypes.languages.InlineCompletions<monacoTypes.languages.InlineCompletion>, item: monacoTypes.languages.InlineCompletion, updatedInsertText: string): void { |
|
|
|
|
|
|
|
this.currentCompletion = { 'item':item, 'task':this.task } |
|
|
|
|
|
|
|
_paq.push(['trackEvent', 'ai', 'solcoder', this.task + '_did_show']) |
|
|
|
} |
|
|
|
} |
|
|
|
handlePartialAccept?(completions: monacoTypes.languages.InlineCompletions<monacoTypes.languages.InlineCompletion>, item: monacoTypes.languages.InlineCompletion, acceptedCharacters: number): void { |
|
|
|
handlePartialAccept?(completions: monacoTypes.languages.InlineCompletions<monacoTypes.languages.InlineCompletion>, item: monacoTypes.languages.InlineCompletion, acceptedCharacters: number): void { |
|
|
|
|
|
|
|
_paq.push(['trackEvent', 'ai', 'solcoder', this.task + '_partial_accept']) |
|
|
|
} |
|
|
|
} |
|
|
|
freeInlineCompletions(completions: monacoTypes.languages.InlineCompletions<monacoTypes.languages.InlineCompletion>): void { |
|
|
|
freeInlineCompletions(completions: monacoTypes.languages.InlineCompletions<monacoTypes.languages.InlineCompletion>): void { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
groupId?: string; |
|
|
|
groupId?: string; |
|
|
|
yieldsToGroupIds?: string[]; |
|
|
|
yieldsToGroupIds?: string[]; |
|
|
|
toString?(): string { |
|
|
|
toString?(): string { |
|
|
|