@@ -203,6 +203,7 @@ export const EditorUI = (props: EditorUIProps) => {
203203 const currentFileRef = useRef ( '' )
204204 const currentUrlRef = useRef ( '' )
205205 const currentDecoratorListCollectionRef = useRef ( { } )
206+ const inlineCompletionProviderRef = useRef < RemixInLineCompletionProvider | null > ( null )
206207
207208 // const currentDecorations = useRef({ sourceAnnotationsPerFile: {}, markerPerFile: {} }) // decorations that are currently in use by the editor
208209 // const registeredDecorations = useRef({}) // registered decorations
@@ -474,8 +475,6 @@ export const EditorUI = (props: EditorUIProps) => {
474475 }
475476 } , [ props . currentFile , props . isDiff ] )
476477
477- const inlineCompletionProvider = new RemixInLineCompletionProvider ( props , monacoRef . current , trackMatomoEvent )
478-
479478 const convertToMonacoDecoration = ( decoration : lineText | sourceAnnotation | sourceMarker , typeOfDecoration : string ) => {
480479 if ( typeOfDecoration === 'sourceAnnotationsPerFile' ) {
481480 decoration = decoration as sourceAnnotation
@@ -771,6 +770,18 @@ export const EditorUI = (props: EditorUIProps) => {
771770 }
772771 } )
773772
773+ editor . onDidChangeModelContent ( ( e ) => {
774+ if ( inlineCompletionProviderRef . current && inlineCompletionProviderRef . current . currentCompletion ) {
775+ const changes = e . changes ;
776+ // Check if the change matches the current completion
777+ if ( changes . some ( change => change . text === inlineCompletionProviderRef . current . currentCompletion . item . insertText ) ) {
778+ inlineCompletionProviderRef . current . currentCompletion . onAccepted ( )
779+ inlineCompletionProviderRef . current . currentCompletion . accepted = true
780+ trackMatomoEvent < AIEvent > ( { category : 'ai' , action : 'remixAI' , name : 'Copilot_Completion_Accepted' , isClick : true } )
781+ }
782+ }
783+ } ) ;
784+
774785 editor . onDidPaste ( async ( e ) => {
775786 const shouldShowWarning = localStorage . getItem ( HIDE_PASTE_WARNING_KEY ) !== 'true' ;
776787 // Only show the modal if the user hasn't opted out
@@ -855,19 +866,7 @@ export const EditorUI = (props: EditorUIProps) => {
855866 props . plugin . call ( 'notification' , 'modal' , modalContent )
856867 trackMatomoEvent ( { category : 'editor' , action : 'onDidPaste' , name : 'more_than_10_lines' , isClick : false } )
857868 }
858- } )
859-
860- editor . onDidChangeModelContent ( ( e ) => {
861- if ( inlineCompletionProvider . currentCompletion ) {
862- const changes = e . changes ;
863- // Check if the change matches the current completion
864- if ( changes . some ( change => change . text === inlineCompletionProvider . currentCompletion . item . insertText ) ) {
865- inlineCompletionProvider . currentCompletion . onAccepted ( )
866- inlineCompletionProvider . currentCompletion . accepted = true
867- trackMatomoEvent < AIEvent > ( { category : 'ai' , action : 'remixAI' , name : 'Copilot_Completion_Accepted' , isClick : true } )
868- }
869- }
870- } ) ;
869+ } )
871870
872871 // add context menu items
873872 const zoominAction = {
@@ -1186,7 +1185,11 @@ export const EditorUI = (props: EditorUIProps) => {
11861185 }
11871186
11881187 function handleEditorWillMount ( monaco ) {
1188+
11891189 monacoRef . current = monaco
1190+
1191+ inlineCompletionProviderRef . current = new RemixInLineCompletionProvider ( props , monacoRef . current , trackMatomoEvent )
1192+
11901193 // Register a new language
11911194 monacoRef . current . languages . register ( { id : 'remix-solidity' } )
11921195 monacoRef . current . languages . register ( { id : 'remix-cairo' } )
@@ -1293,7 +1296,7 @@ export const EditorUI = (props: EditorUIProps) => {
12931296
12941297 monacoRef . current . languages . setMonarchTokensProvider ( 'remix-cairo' , cairoTokensProvider as any )
12951298 monacoRef . current . languages . setLanguageConfiguration ( 'remix-cairo' , cairoLanguageConfig as any )
1296- monacoRef . current . languages . registerInlineCompletionsProvider ( 'remix-cairo' , inlineCompletionProvider )
1299+ monacoRef . current . languages . registerInlineCompletionsProvider ( 'remix-cairo' , inlineCompletionProviderRef . current )
12971300
12981301 monacoRef . current . languages . setMonarchTokensProvider ( 'remix-zokrates' , zokratesTokensProvider as any )
12991302 monacoRef . current . languages . setLanguageConfiguration ( 'remix-zokrates' , zokratesLanguageConfig as any )
@@ -1303,21 +1306,21 @@ export const EditorUI = (props: EditorUIProps) => {
13031306
13041307 monacoRef . current . languages . setMonarchTokensProvider ( 'remix-circom' , circomTokensProvider as any )
13051308 monacoRef . current . languages . setLanguageConfiguration ( 'remix-circom' , circomLanguageConfig ( monacoRef . current ) as any )
1306- monacoRef . current . languages . registerInlineCompletionsProvider ( 'remix-circom' , inlineCompletionProvider )
1309+ monacoRef . current . languages . registerInlineCompletionsProvider ( 'remix-circom' , inlineCompletionProviderRef . current )
13071310
13081311 monacoRef . current . languages . setMonarchTokensProvider ( 'remix-toml' , tomlTokenProvider as any )
13091312 monacoRef . current . languages . setLanguageConfiguration ( 'remix-toml' , tomlLanguageConfig as any )
13101313
13111314 monacoRef . current . languages . setMonarchTokensProvider ( 'remix-noir' , noirTokensProvider as any )
13121315 monacoRef . current . languages . setLanguageConfiguration ( 'remix-noir' , noirLanguageConfig as any )
1313- monacoRef . current . languages . registerInlineCompletionsProvider ( 'remix-noir' , inlineCompletionProvider )
1316+ monacoRef . current . languages . registerInlineCompletionsProvider ( 'remix-noir' , inlineCompletionProviderRef . current )
13141317
13151318 monacoRef . current . languages . registerDefinitionProvider ( 'remix-solidity' , new RemixDefinitionProvider ( props , monaco ) )
13161319 monacoRef . current . languages . registerDocumentHighlightProvider ( 'remix-solidity' , new RemixHighLightProvider ( props , monaco ) )
13171320 monacoRef . current . languages . registerReferenceProvider ( 'remix-solidity' , new RemixReferenceProvider ( props , monaco ) )
13181321 monacoRef . current . languages . registerHoverProvider ( 'remix-solidity' , new RemixHoverProvider ( props , monaco ) )
13191322 monacoRef . current . languages . registerCompletionItemProvider ( 'remix-solidity' , new RemixCompletionProvider ( props , monaco ) )
1320- monacoRef . current . languages . registerInlineCompletionsProvider ( 'remix-solidity' , inlineCompletionProvider )
1323+ monacoRef . current . languages . registerInlineCompletionsProvider ( 'remix-solidity' , inlineCompletionProviderRef . current )
13211324 monaco . languages . registerCodeActionProvider ( 'remix-solidity' , new RemixCodeActionProvider ( props , monaco ) )
13221325
13231326 loadTypes ( monacoRef . current )
0 commit comments