Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature #365 Show RAG prompt placeholder when turned on #366

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "com.devoxx.genie"
version = "0.4.1"
version = "0.4.2"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.devoxx.genie.model.CustomPrompt;
import com.devoxx.genie.service.DevoxxGenieSettingsService;
import com.devoxx.genie.ui.listener.CustomPromptChangeListener;
import com.devoxx.genie.ui.listener.RAGStateListener;
import com.devoxx.genie.ui.settings.DevoxxGenieStateService;
import com.devoxx.genie.ui.topic.AppTopics;
import com.intellij.openapi.application.ApplicationManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,62 @@
package com.devoxx.genie.ui.component.input;

import com.devoxx.genie.ui.listener.PromptInputFocusListener;
import com.devoxx.genie.ui.listener.RAGStateListener;
import com.devoxx.genie.ui.panel.SearchOptionsPanel;
import com.devoxx.genie.ui.settings.DevoxxGenieStateService;
import com.devoxx.genie.ui.topic.AppTopics;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.ui.JBColor;
import com.intellij.util.messages.MessageBusConnection;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;

public class PromptInputArea extends JPanel {
private final CommandAutoCompleteTextField inputField;
private final transient Project project;
private final transient ResourceBundle resourceBundle;

public PromptInputArea(@NotNull ResourceBundle resourceBundle, Project project) {
super(new BorderLayout());

this.resourceBundle = resourceBundle;
this.project = project;

// Create main input area panel
JPanel inputAreaPanel = new JPanel(new BorderLayout());
inputField = new CommandAutoCompleteTextField(project);
inputField.setLineWrap(true);
inputField.setWrapStyleWord(true);
inputField.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
inputField.addFocusListener(new PromptInputFocusListener(inputField));
inputField.setPlaceholder(resourceBundle.getString("prompt.placeholder"));

if (Boolean.TRUE.equals(DevoxxGenieStateService.getInstance().getRagActivated())) {
inputField.setPlaceholder(resourceBundle.getString("rag.prompt.placeholder"));
} else {
inputField.setPlaceholder(resourceBundle.getString("prompt.placeholder"));
}

inputField.setRows(3);

// Add components to main panel
inputAreaPanel.add(new SearchOptionsPanel(), BorderLayout.NORTH);
inputAreaPanel.add(new SearchOptionsPanel(project), BorderLayout.NORTH);
inputAreaPanel.add(inputField, BorderLayout.CENTER);

add(inputAreaPanel, BorderLayout.CENTER);

this.subscribeToRagStateChanges();
}

public void subscribeToRagStateChanges() {
MessageBusConnection connection = project.getMessageBus().connect();
connection.subscribe(AppTopics.RAG_ACTIVATED_CHANGED_TOPIC,
(RAGStateListener) isEnabled ->
inputField.setPlaceholder(
isEnabled ? resourceBundle.getString("rag.prompt.placeholder") : resourceBundle.getString("prompt.placeholder")
));
}

public String getText() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.devoxx.genie.ui.listener;

public interface RAGStateListener {
void onRAGStateChanged(boolean enabled);
}

This file was deleted.

38 changes: 23 additions & 15 deletions src/main/java/com/devoxx/genie/ui/panel/SearchOptionsPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

import com.devoxx.genie.ui.component.InputSwitch;
import com.devoxx.genie.ui.listener.GitDiffStateListener;
import com.devoxx.genie.ui.listener.SemanticSearchStateListener;
import com.devoxx.genie.ui.listener.RAGStateListener;
import com.devoxx.genie.ui.listener.WebSearchStateListener;
import com.devoxx.genie.ui.settings.DevoxxGenieStateService;
import com.devoxx.genie.ui.topic.AppTopics;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.util.messages.MessageBusConnection;
import com.intellij.util.ui.JBUI;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import java.awt.*;
Expand All @@ -19,15 +21,16 @@
public class SearchOptionsPanel extends JPanel {
private final List<InputSwitch> switches = new ArrayList<>();
private static final int DEFAULT_HEIGHT = JBUI.scale(30);
private Project project;

public SearchOptionsPanel() {
public SearchOptionsPanel(Project project) {
super(new FlowLayout(FlowLayout.LEFT, JBUI.scale(10), 0));
setOpaque(false);

DevoxxGenieStateService stateService = DevoxxGenieStateService.getInstance();

// Create switches
InputSwitch semanticSearchSwitch = new InputSwitch(
InputSwitch ragSwitch = new InputSwitch(
"RAG",
"Enable RAG-enabled code search"
);
Expand All @@ -43,26 +46,31 @@ public SearchOptionsPanel() {
);

// Add switches to our list for tracking
switches.add(semanticSearchSwitch);
switches.add(ragSwitch);
switches.add(gitDiffSwitch);
switches.add(webSearchSwitch);

// Initialize visibility based on state service
updateInitialVisibility(stateService);

// Load saved state for enabled switches
semanticSearchSwitch.setSelected(stateService.getRagEnabled());
ragSwitch.setSelected(stateService.getRagEnabled());
gitDiffSwitch.setSelected(stateService.getGitDiffEnabled());
webSearchSwitch.setSelected(stateService.getEnableWebSearch());

// Ensure only one switch is initially active
enforceInitialSingleSelection();

// Add state change listeners with mutual exclusion
semanticSearchSwitch.addEventSelected(selected -> {
ragSwitch.addEventSelected(selected -> {
if (selected) {
deactivateOtherSwitches(semanticSearchSwitch);
deactivateOtherSwitches(ragSwitch);
}

project.getMessageBus()
.syncPublisher(AppTopics.RAG_ACTIVATED_CHANGED_TOPIC)
.onRAGStateChanged(selected);

stateService.setRagActivated(selected);
updatePanelVisibility();
});
Expand All @@ -87,7 +95,7 @@ public SearchOptionsPanel() {
setupMessageBusListeners();

// Add components
add(semanticSearchSwitch);
add(ragSwitch);
add(gitDiffSwitch);
add(webSearchSwitch);

Expand All @@ -113,7 +121,7 @@ public Dimension getPreferredSize() {
}

private boolean shouldBeVisible() {
return switches.stream().anyMatch(sw -> sw.isVisible());
return switches.stream().anyMatch(Component::isVisible);
}

private void updatePanelVisibility() {
Expand All @@ -122,7 +130,7 @@ private void updatePanelVisibility() {
repaint();
}

private void updateInitialVisibility(DevoxxGenieStateService stateService) {
private void updateInitialVisibility(@NotNull DevoxxGenieStateService stateService) {
// Set initial visibility based on state service
switches.get(0).setVisible(stateService.getRagEnabled());
switches.get(1).setVisible(stateService.getGitDiffEnabled());
Expand All @@ -137,11 +145,11 @@ private void setupMessageBusListeners() {
MessageBusConnection connect = application.getMessageBus().connect();

// Subscribe to state changes and update both visibility and selection
connect.subscribe(AppTopics.SEMANTIC_SEARCH_STATE_TOPIC,
(SemanticSearchStateListener) enabled -> {
InputSwitch semanticSwitch = switches.get(0);
semanticSwitch.setVisible(enabled);
semanticSwitch.setSelected(enabled);
connect.subscribe(AppTopics.RAG_STATE_TOPIC,
(RAGStateListener) enabled -> {
InputSwitch ragSwitch = switches.get(0);
ragSwitch.setVisible(enabled);
ragSwitch.setSelected(enabled);
updatePanelVisibility();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public void apply() {

if (oldValue != newValue) {
ApplicationManager.getApplication().getMessageBus()
.syncPublisher(AppTopics.SEMANTIC_SEARCH_STATE_TOPIC)
.onSemanticSearchStateChanged(newValue);
.syncPublisher(AppTopics.RAG_STATE_TOPIC)
.onRAGStateChanged(newValue);
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/devoxx/genie/ui/topic/AppTopics.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ public class AppTopics {
public static final Topic<ConversationEventListener> CONVERSATION_TOPIC =
Topic.create("NewConversation", ConversationEventListener.class);

public static final Topic<SemanticSearchStateListener> SEMANTIC_SEARCH_STATE_TOPIC =
Topic.create("SemanticSearchState", SemanticSearchStateListener.class);
public static final Topic<RAGStateListener> RAG_STATE_TOPIC =
Topic.create("RAGStateEnabled", RAGStateListener.class);

public static final Topic<WebSearchStateListener> WEB_SEARCH_STATE_TOPIC =
Topic.create("WebSearchState", WebSearchStateListener.class);

public static final Topic<GitDiffStateListener> GITDIFF_STATE_TOPIC =
Topic.create("GitDiffState", GitDiffStateListener.class);

public static final Topic<RAGStateListener> RAG_ACTIVATED_CHANGED_TOPIC =
Topic.create("RagStateActivated", RAGStateListener.class);
}
5 changes: 5 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
]]></description>

<change-notes><![CDATA[
<h2>v0.4.2</h2>
<UL>
<LI>Feature #364: Show specific RAG prompt placeholder when turned on</LI>
<LI>Feature: Glowing border now around panel to make it more obvious when running</LI>
</UL>
<h2>v0.4.1</h2>
<UL>
<LI>Fix #352 : Restore horizontal scrolling in chat response panel</LI>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Tue Dec 10 15:40:30 CET 2024
#Wed Dec 11 09:40:59 CET 2024
version=0.4.1
1 change: 1 addition & 0 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ welcome.tip=You can modify the endpoints for different LLM providers and the def
welcome.enjoy=Enjoy!

prompt.placeholder=Shift+Enter to submit prompt or type /help
rag.prompt.placeholder=Submit RAG-enabled prompt or /find for semantic search
Loading