|
|
@ -14,10 +14,12 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli |
|
|
|
props: EditorUIProps |
|
|
|
props: EditorUIProps |
|
|
|
monaco: any |
|
|
|
monaco: any |
|
|
|
completionEnabled: boolean |
|
|
|
completionEnabled: boolean |
|
|
|
|
|
|
|
isGeneratingContract: boolean |
|
|
|
constructor(props: any, monaco: any) { |
|
|
|
constructor(props: any, monaco: any) { |
|
|
|
this.props = props |
|
|
|
this.props = props |
|
|
|
this.monaco = monaco |
|
|
|
this.monaco = monaco |
|
|
|
this.completionEnabled = true |
|
|
|
this.completionEnabled = true |
|
|
|
|
|
|
|
this.isGeneratingContract = false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async provideInlineCompletions(model: monacoTypes.editor.ITextModel, position: monacoTypes.Position, context: monacoTypes.languages.InlineCompletionContext, token: monacoTypes.CancellationToken): Promise<monacoTypes.languages.InlineCompletions<monacoTypes.languages.InlineCompletion>> { |
|
|
|
async provideInlineCompletions(model: monacoTypes.editor.ITextModel, position: monacoTypes.Position, context: monacoTypes.languages.InlineCompletionContext, token: monacoTypes.CancellationToken): Promise<monacoTypes.languages.InlineCompletions<monacoTypes.languages.InlineCompletion>> { |
|
|
@ -60,6 +62,7 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli |
|
|
|
try { |
|
|
|
try { |
|
|
|
const split = word.split('\n') |
|
|
|
const split = word.split('\n') |
|
|
|
if (split.length < 2) return |
|
|
|
if (split.length < 2) return |
|
|
|
|
|
|
|
|
|
|
|
const ask = split[split.length - 2].trimStart() |
|
|
|
const ask = split[split.length - 2].trimStart() |
|
|
|
if (split[split.length - 1].trim() === '' && ask.startsWith('///')) { |
|
|
|
if (split[split.length - 1].trim() === '' && ask.startsWith('///')) { |
|
|
|
// use the code generation model, only take max 1000 word as context
|
|
|
|
// use the code generation model, only take max 1000 word as context
|
|
|
@ -82,6 +85,25 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log("is sol comment", this.isSolidityComment(word)) |
|
|
|
|
|
|
|
if (this.isSolidityComment(word) && word.includes("sol-gen") && this.isGeneratingContract===false){ |
|
|
|
|
|
|
|
this.isGeneratingContract = true |
|
|
|
|
|
|
|
console.log("new contract generation") |
|
|
|
|
|
|
|
const output = await this.props.plugin.call('solcoder', 'contract_generation', word) |
|
|
|
|
|
|
|
_paq.push(['trackEvent', 'ai', 'solcoder', 'contract_generation']) |
|
|
|
|
|
|
|
const handleCompletionTimer = new CompletionTimer(5000, () => { this.isGeneratingContract = false }); |
|
|
|
|
|
|
|
handleCompletionTimer.start() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const item: monacoTypes.languages.InlineCompletion = { |
|
|
|
|
|
|
|
insertText: output[0] |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
items: [item], |
|
|
|
|
|
|
|
enableForwardStability: true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (word.split('\n').at(-1).trimStart().startsWith('//') || |
|
|
|
if (word.split('\n').at(-1).trimStart().startsWith('//') || |
|
|
|
word.split('\n').at(-1).trimStart().startsWith('/*') || |
|
|
|
word.split('\n').at(-1).trimStart().startsWith('/*') || |
|
|
|
word.split('\n').at(-1).trimStart().startsWith('*') || |
|
|
|
word.split('\n').at(-1).trimStart().startsWith('*') || |
|
|
@ -158,6 +180,20 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
isSolidityComment(text: string): boolean { |
|
|
|
|
|
|
|
const joinedText = text.trim().replace(/\n\s*/g, ' '); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const singleLineComment = /^\/\/.*$/; |
|
|
|
|
|
|
|
const multiLineComment = /^\/\*[\s\S]*\*\/$/; |
|
|
|
|
|
|
|
const singleLineNatSpec = /^\/\/\/.*$/; |
|
|
|
|
|
|
|
const multiLineNatSpec = /^\/\*\*[\s\S]*\*\/$/; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return singleLineComment.test(joinedText) || |
|
|
|
|
|
|
|
multiLineComment.test(joinedText) || |
|
|
|
|
|
|
|
singleLineNatSpec.test(joinedText) || |
|
|
|
|
|
|
|
multiLineNatSpec.test(joinedText); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
process_completion(data: any) { |
|
|
|
process_completion(data: any) { |
|
|
|
let clean = data.split('\n')[0].startsWith('\n') ? [data.split('\n')[0], data.split('\n')[1]].join('\n'): data.split('\n')[0] |
|
|
|
let clean = data.split('\n')[0].startsWith('\n') ? [data.split('\n')[0], data.split('\n')[1]].join('\n'): data.split('\n')[0] |
|
|
|
|
|
|
|
|
|
|
|