|
|
@ -1,6 +1,8 @@ |
|
|
|
/* eslint-disable no-control-regex */ |
|
|
|
/* eslint-disable no-control-regex */ |
|
|
|
import { EditorUIProps, monacoTypes } from '@remix-ui/editor'; |
|
|
|
import { EditorUIProps, monacoTypes } from '@remix-ui/editor'; |
|
|
|
import { JsonStreamParser } from '@remix/remix-ai-core'; |
|
|
|
import { JsonStreamParser } from '@remix/remix-ai-core'; |
|
|
|
|
|
|
|
import * as monaco from 'monaco-editor'; |
|
|
|
|
|
|
|
|
|
|
|
const _paq = (window._paq = window._paq || []) |
|
|
|
const _paq = (window._paq = window._paq || []) |
|
|
|
|
|
|
|
|
|
|
|
export class RemixInLineCompletionProvider implements monacoTypes.languages.InlineCompletionsProvider { |
|
|
|
export class RemixInLineCompletionProvider implements monacoTypes.languages.InlineCompletionsProvider { |
|
|
@ -26,9 +28,8 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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>> { |
|
|
|
if (context.selectedSuggestionInfo) { |
|
|
|
const isActivate = await await this.props.plugin.call('settings', 'get', 'settings/copilot/suggest/activate') |
|
|
|
return { items: []}; |
|
|
|
if (!isActivate) return |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const currentTime = Date.now(); |
|
|
|
const currentTime = Date.now(); |
|
|
|
const timeSinceLastRequest = currentTime - this.lastRequestTime; |
|
|
|
const timeSinceLastRequest = currentTime - this.lastRequestTime; |
|
|
@ -65,13 +66,6 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
const isActivate = await await this.props.plugin.call('settings', 'get', 'settings/copilot/suggest/activate') |
|
|
|
|
|
|
|
if (!isActivate) return |
|
|
|
|
|
|
|
} catch (err) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
const split = word.split('\n') |
|
|
|
const split = word.split('\n') |
|
|
|
if (split.length < 2) return |
|
|
|
if (split.length < 2) return |
|
|
@ -109,11 +103,6 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli |
|
|
|
return { items: []}; // do not do completion on single and multiline comment
|
|
|
|
return { items: []}; // do not do completion on single and multiline comment
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// abort if there is a signal
|
|
|
|
|
|
|
|
if (token.isCancellationRequested) { |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (word.replace(/ +$/, '').endsWith('\n')){ |
|
|
|
if (word.replace(/ +$/, '').endsWith('\n')){ |
|
|
|
// Code insertion
|
|
|
|
// Code insertion
|
|
|
|
try { |
|
|
|
try { |
|
|
@ -122,7 +111,8 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli |
|
|
|
|
|
|
|
|
|
|
|
this.task = 'code_insertion' |
|
|
|
this.task = 'code_insertion' |
|
|
|
const item: monacoTypes.languages.InlineCompletion = { |
|
|
|
const item: monacoTypes.languages.InlineCompletion = { |
|
|
|
insertText: generatedText |
|
|
|
insertText: generatedText, |
|
|
|
|
|
|
|
range: new monaco.Range(position.lineNumber, position.column, position.lineNumber, position.column) |
|
|
|
}; |
|
|
|
}; |
|
|
|
this.currentCompletion.text = generatedText |
|
|
|
this.currentCompletion.text = generatedText |
|
|
|
this.currentCompletion.item = item |
|
|
|
this.currentCompletion.item = item |
|
|
@ -141,25 +131,26 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli |
|
|
|
try { |
|
|
|
try { |
|
|
|
// Code completion
|
|
|
|
// Code completion
|
|
|
|
this.task = 'code_completion' |
|
|
|
this.task = 'code_completion' |
|
|
|
const output = await this.props.plugin.call('remixAI', 'code_completion', word) |
|
|
|
const output = await this.props.plugin.call('remixAI', 'code_completion', word, word_after) |
|
|
|
const generatedText = output |
|
|
|
const generatedText = output |
|
|
|
let clean = generatedText |
|
|
|
let clean = generatedText |
|
|
|
|
|
|
|
|
|
|
|
if (generatedText.indexOf('@custom:dev-run-script./') !== -1) { |
|
|
|
if (generatedText.indexOf('@custom:dev-run-script./') !== -1) { |
|
|
|
clean = generatedText.replace('@custom:dev-run-script', '@custom:dev-run-script ') |
|
|
|
clean = generatedText.replace('@custom:dev-run-script', '@custom:dev-run-script ') |
|
|
|
} |
|
|
|
} |
|
|
|
clean = clean.replace(word, '').trimStart() |
|
|
|
clean = clean.replace(word, '') |
|
|
|
clean = this.process_completion(clean) |
|
|
|
clean = this.process_completion(clean) |
|
|
|
|
|
|
|
|
|
|
|
const item: monacoTypes.languages.InlineCompletion = { |
|
|
|
const item: monacoTypes.languages.InlineCompletion = { |
|
|
|
insertText: clean, |
|
|
|
insertText: clean, |
|
|
|
|
|
|
|
range: new monaco.Range(position.lineNumber, position.column, position.lineNumber, position.column) |
|
|
|
}; |
|
|
|
}; |
|
|
|
this.currentCompletion.text = clean |
|
|
|
this.currentCompletion.text = clean |
|
|
|
this.currentCompletion.item = item |
|
|
|
this.currentCompletion.item = item |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
items: [item], |
|
|
|
items: [item], |
|
|
|
enableForwardStability: true |
|
|
|
enableForwardStability: false |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (err) { |
|
|
|
} catch (err) { |
|
|
|
return |
|
|
|
return |
|
|
@ -174,7 +165,7 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli |
|
|
|
return "" |
|
|
|
return "" |
|
|
|
} |
|
|
|
} |
|
|
|
// remove comment inline
|
|
|
|
// remove comment inline
|
|
|
|
clean = clean.split('//')[0].trimEnd() |
|
|
|
clean = clean.split('//')[0] |
|
|
|
return clean |
|
|
|
return clean |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|