11package com .microsoft .copilot .eclipse .ui .nes ;
22
33import java .net .URI ;
4- import java .util .Collections ;
54
65import org .apache .commons .lang3 .StringUtils ;
76import org .eclipse .core .resources .IFile ;
2120import org .eclipse .jface .text .TextSelection ;
2221import org .eclipse .jface .text .source .IAnnotationModel ;
2322import org .eclipse .jface .text .source .IAnnotationModelListener ;
24- import org .eclipse .jface .text .source .ISourceViewer ;
2523import org .eclipse .jface .text .source .projection .ProjectionAnnotation ;
2624import org .eclipse .jface .text .source .projection .ProjectionViewer ;
2725import org .eclipse .jface .util .IPropertyChangeListener ;
2826import org .eclipse .lsp4e .LSPEclipseUtils ;
27+ import org .eclipse .lsp4j .Command ;
2928import org .eclipse .lsp4j .Range ;
3029import org .eclipse .swt .SWT ;
3130import org .eclipse .swt .custom .StyledText ;
3635import com .microsoft .copilot .eclipse .core .CopilotCore ;
3736import com .microsoft .copilot .eclipse .core .events .CopilotEventConstants ;
3837import com .microsoft .copilot .eclipse .core .lsp .CopilotLanguageServerConnection ;
38+ import com .microsoft .copilot .eclipse .core .lsp .protocol .DidShowInlineEditParams ;
3939import com .microsoft .copilot .eclipse .core .lsp .protocol .NextEditSuggestionsResult .CopilotInlineEdit ;
40- import com .microsoft .copilot .eclipse .core .lsp .protocol .NotifyAcceptedParams ;
41- import com .microsoft .copilot .eclipse .core .lsp .protocol .NotifyRejectedParams ;
42- import com .microsoft .copilot .eclipse .core .lsp .protocol .NotifyShownParams ;
4340import com .microsoft .copilot .eclipse .core .nes .NextEditSuggestionListener ;
4441import com .microsoft .copilot .eclipse .core .nes .NextEditSuggestionProvider ;
42+ import com .microsoft .copilot .eclipse .core .utils .FileUtils ;
4543import com .microsoft .copilot .eclipse .ui .CopilotUi ;
4644import com .microsoft .copilot .eclipse .ui .utils .CompletionUtils ;
4745import com .microsoft .copilot .eclipse .ui .utils .SwtUtils ;
@@ -88,6 +86,7 @@ public boolean isPureInsert() {
8886 private Range lastRange ; // precise range of current suggestion
8987 private IFile lastFile ; // track file for extension-based fallback
9088 private String currentSuggestionUuid ; // UUID for telemetry
89+ private Command currentSuggestionCommand ; // Command for acceptance
9190 private int suggestionDocumentVersion = -1 ; // document version when suggestion was received
9291 private Position suggestionStartPosition ; // start offset of suggestion range
9392 private Position suggestionEndPosition ; // end offset of suggestion range
@@ -332,6 +331,7 @@ private void clearSuggestionData() {
332331 diffModel = null ;
333332 lastRange = null ;
334333 currentSuggestionUuid = null ;
334+ currentSuggestionCommand = null ;
335335 suggestionDocumentVersion = -1 ;
336336 }
337337
@@ -343,8 +343,6 @@ public void clearSuggestion() {
343343 return ;
344344 }
345345 nesProvider .cancelCurrentRequest ();
346- notifyRejected ();
347-
348346 SwtUtils .invokeOnDisplayThread (() -> {
349347 clearSuggestionUi ();
350348 clearSuggestionData ();
@@ -505,6 +503,7 @@ public void onNextEditSuggestion(IFile file, CopilotInlineEdit edit) {
505503 this .lastFile = file ;
506504 this .lastRange = range ;
507505 this .currentSuggestionUuid = edit .getUuid ();
506+ this .currentSuggestionCommand = edit .getCommand ();
508507 this .suggestionDocumentVersion = edit .getTextDocument () != null && edit .getTextDocument ().getVersion () != null
509508 ? edit .getTextDocument ().getVersion ()
510509 : -1 ;
@@ -533,7 +532,7 @@ public void onNextEditSuggestion(IFile file, CopilotInlineEdit edit) {
533532
534533 private boolean isCurrentDocument (IDocument doc , IFile file ) {
535534 URI currentDocUri = LSPEclipseUtils .toUri (doc );
536- String fileUriString = file != null ? com . microsoft . copilot . eclipse . core . utils . FileUtils .getResourceUri (file )
535+ String fileUriString = file != null ? FileUtils .getResourceUri (file )
537536 : null ;
538537 return currentDocUri != null && fileUriString != null && currentDocUri .toString ().equals (fileUriString );
539538 }
@@ -769,6 +768,8 @@ public void acceptSuggestion() {
769768 diffPopup .hideAndClearIndent (text , viewer , indentLinePosition );
770769 }, text );
771770
771+ notifyAccepted ();
772+
772773 // Apply replacement (document operation)
773774 String replacement = diffModel .replacement == null ? "" : diffModel .replacement ;
774775 String lineDelimiter = CompletionUtils .getDocumentLineDelimiter (doc , startOff );
@@ -785,9 +786,8 @@ public void acceptSuggestion() {
785786 clearSuggestionUi ();
786787 }, text );
787788
788- // Clear data and notify (non-UI operations)
789+ // Clear data
789790 clearSuggestionData ();
790- notifyAccepted ();
791791 scheduleNextSuggestionRequest (doc , currentFile , newCaretOffset );
792792
793793 } catch (BadLocationException ex ) {
@@ -909,8 +909,8 @@ private void notifyShown() {
909909 return ;
910910 }
911911 try {
912- NotifyShownParams params = new NotifyShownParams (currentSuggestionUuid );
913- lsConnection .notifyShown (params );
912+ DidShowInlineEditParams params = DidShowInlineEditParams . fromUuid (currentSuggestionUuid );
913+ lsConnection .didShowInlineEdit (params );
914914 } catch (Exception e ) {
915915 CopilotCore .LOGGER .error ("Failed to notify shown telemetry" , e );
916916 }
@@ -920,31 +920,13 @@ private void notifyShown() {
920920 * Notify Language Server that suggestion is accepted (telemetry).
921921 */
922922 private void notifyAccepted () {
923- if (currentSuggestionUuid == null || lsConnection == null ) {
923+ if (currentSuggestionCommand == null || lsConnection == null ) {
924924 return ;
925925 }
926926 try {
927- NotifyAcceptedParams params = new NotifyAcceptedParams (currentSuggestionUuid );
928- lsConnection .notifyAccepted (params );
929- currentSuggestionUuid = null ; // Clear after accepting
927+ lsConnection .acceptNextEditSuggestion (currentSuggestionCommand );
930928 } catch (Exception e ) {
931929 CopilotCore .LOGGER .error ("Failed to notify accepted telemetry" , e );
932930 }
933931 }
934-
935- /**
936- * Notify Language Server that suggestion is rejected (telemetry).
937- */
938- private void notifyRejected () {
939- if (currentSuggestionUuid == null || lsConnection == null ) {
940- return ;
941- }
942- try {
943- NotifyRejectedParams params = new NotifyRejectedParams (Collections .singletonList (currentSuggestionUuid ));
944- lsConnection .notifyRejected (params );
945- currentSuggestionUuid = null ; // Clear after rejecting
946- } catch (Exception e ) {
947- CopilotCore .LOGGER .error ("Failed to notify rejected telemetry" , e );
948- }
949- }
950932}
0 commit comments