public final void onNewSuggestion()

in plugin/src/software/aws/toolkits/eclipse/amazonq/util/QInlineRendererListener.java [60:103]


    public final void onNewSuggestion() {
        if (popup != null) {
            popup.close();
        }
        QInvocationSession session = QInvocationSession.getInstance();
        InlineCompletionItem currentSuggestion = session.getCurrentSuggestion();
        InlineCompletionReference[] referencesForCurrentSuggestion = currentSuggestion.getReferences();
        if (referencesForCurrentSuggestion == null || referencesForCurrentSuggestion.length == 0) {
            return;
        }
        var widget = session.getViewer().getTextWidget();
        popup = new PopupDialog(widget.getShell(), PopupDialog.INFOPOPUPRESIZE_SHELLSTYLE, false, false, false, false, false,
                null, null) {
            @Override
            protected Point getInitialLocation(final Point initialSize) {
                Point location = widget.getLocationAtOffset(session.getInvocationOffset());
                location.y -= widget.getLineHeight() * 1.1;
                return widget.toDisplay(location);
            }

            @Override
            protected Control createDialogArea(final Composite parent) {
                Composite composite = (Composite) super.createDialogArea(parent);

                // Add a label to display the message
                Label infoLabel = new Label(composite, SWT.NONE);
                StringBuffer licenseNames = new StringBuffer();
                for (int i = 0; i < referencesForCurrentSuggestion.length; i++) {
                    licenseNames.append(referencesForCurrentSuggestion[i].getLicenseName());
                    if (i != referencesForCurrentSuggestion.length - 1) {
                        licenseNames.append(" + ");
                    }
                }
                int currentSuggestionNumber = session.getCurrentSuggestionNumber();
                int totalNumberOfSuggestions = session.getNumberOfSuggestions();
                String tipToDisplay = "Suggestion (License: " + licenseNames.toString() + ") " + currentSuggestionNumber
                        + " / " + totalNumberOfSuggestions;
                infoLabel.setText(tipToDisplay);

                return composite;
            }
        };
        popup.open();
    }