-
Notifications
You must be signed in to change notification settings - Fork 42
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
[BUG] RAG is always turned on #382
Comments
Gemini Exp 1206 response: Okay, I understand the issue. You're using an Here's a breakdown of why this is happening and how to fix it, along with code examples based on your provided project context: Why the RAG Setting Isn't Persisting The problem lies in how you're initializing and saving the RAG enabled state. Currently, you're likely initializing the Solution You need to do two things:
Code Modifications Here's how you can modify your package com.devoxx.genie.ui.panel;
import com.devoxx.genie.ui.component.InputSwitch;
import com.devoxx.genie.ui.listener.GitDiffStateListener;
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.*;
import java.util.ArrayList;
import java.util.List;
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(Project project) {
super(new FlowLayout(FlowLayout.LEFT, JBUI.scale(10), 0));
setOpaque(false);
this.project = project;
DevoxxGenieStateService stateService = DevoxxGenieStateService.getInstance();
// Create switches
InputSwitch ragSwitch = new InputSwitch(
"RAG",
"Enable RAG-enabled code search"
);
InputSwitch gitDiffSwitch = new InputSwitch(
"Git Diff",
"Show Git diff window to compare and merge code suggestions"
);
InputSwitch webSearchSwitch = new InputSwitch(
"Web",
"Search the web for additional information"
);
// Add switches to our list for tracking
switches.add(ragSwitch);
switches.add(gitDiffSwitch);
switches.add(webSearchSwitch);
// Initialize visibility based on state service
updateInitialVisibility(stateService);
// Load saved state for enabled switches
ragSwitch.setSelected(stateService.getRagEnabled()); // Initialize from settings
gitDiffSwitch.setSelected(stateService.getGitDiffEnabled());
webSearchSwitch.setSelected(stateService.getEnableWebSearch());
// Ensure only one switch is initially active
enforceInitialSingleSelection();
// Add state change listeners with mutual exclusion
ragSwitch.addEventSelected(selected -> {
if (selected) {
deactivateOtherSwitches(ragSwitch);
}
project.getMessageBus()
.syncPublisher(AppTopics.RAG_ACTIVATED_CHANGED_TOPIC)
.onRAGStateChanged(selected);
stateService.setRagEnabled(selected); // Save the state
stateService.setRagActivated(selected);
updatePanelVisibility();
});
gitDiffSwitch.addEventSelected(selected -> {
if (selected) {
deactivateOtherSwitches(gitDiffSwitch);
}
stateService.setGitDiffActivated(selected);
updatePanelVisibility();
});
webSearchSwitch.addEventSelected(selected -> {
if (selected) {
deactivateOtherSwitches(webSearchSwitch);
}
stateService.setWebSearchActivated(selected);
updatePanelVisibility();
});
// Set up message bus listeners for visibility changes
setupMessageBusListeners();
// Add components
add(ragSwitch);
add(gitDiffSwitch);
add(webSearchSwitch);
// Add some padding
setBorder(JBUI.Borders.empty(5, 10));
// Update panel visibility based on initial state
updatePanelVisibility();
}
@Override
public Dimension getMinimumSize() {
return new Dimension(0, shouldBeVisible() ? DEFAULT_HEIGHT : 0);
}
@Override
public Dimension getPreferredSize() {
if (!shouldBeVisible()) {
return new Dimension(0, 0);
}
Dimension size = super.getPreferredSize();
return new Dimension(size.width, DEFAULT_HEIGHT);
}
private boolean shouldBeVisible() {
return switches.stream().anyMatch(Component::isVisible);
}
private void updatePanelVisibility() {
setVisible(shouldBeVisible());
revalidate();
repaint();
}
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());
switches.get(2).setVisible(stateService.getEnableWebSearch());
// Update panel visibility
updatePanelVisibility();
}
private void setupMessageBusListeners() {
Application application = ApplicationManager.getApplication();
MessageBusConnection connect = application.getMessageBus().connect();
// Subscribe to state changes and update both visibility and selection
connect.subscribe(AppTopics.RAG_STATE_TOPIC,
(RAGStateListener) enabled -> {
InputSwitch ragSwitch = switches.get(0);
ragSwitch.setVisible(enabled);
ragSwitch.setSelected(enabled);
updatePanelVisibility();
});
connect.subscribe(AppTopics.GITDIFF_STATE_TOPIC,
(GitDiffStateListener) enabled -> {
InputSwitch gitDiffSwitch = switches.get(1);
gitDiffSwitch.setVisible(enabled);
gitDiffSwitch.setSelected(enabled);
updatePanelVisibility();
});
connect.subscribe(AppTopics.WEB_SEARCH_STATE_TOPIC,
(WebSearchStateListener) enabled -> {
InputSwitch webSearchSwitch = switches.get(2);
webSearchSwitch.setVisible(enabled);
webSearchSwitch.setSelected(enabled);
updatePanelVisibility();
});
}
private void deactivateOtherSwitches(InputSwitch activeSwitch) {
switches.stream()
.filter(sw -> sw != activeSwitch && sw.isVisible())
.forEach(sw -> sw.setSelected(false));
}
private void enforceInitialSingleSelection() {
// Find the first active and visible switch
switches.stream()
.filter(sw -> sw.isSelected() && sw.isVisible())
.findFirst()
.ifPresent(this::deactivateOtherSwitches);
}
} Explanation of Changes
Important Considerations
Additional Tips
By making these changes, your RAG setting should now persist correctly across IntelliJ IDEA restarts, and the |
The actual fix is this. It needs to use the Activation state instead of the Enable/Disable feature state
|
Fix #382: Restore the correct switch button states
v0.4.2
Features enabled: RAG / Git Diff / Web
Turn all three off in the chat window
Close IntelliJ
Start IntelliJ
RAG is turned on automatically every time IntelliJ starts
The text was updated successfully, but these errors were encountered: