Skip to content

Commit

Permalink
Merge pull request #88 from jeddict/feature
Browse files Browse the repository at this point in the history
Add AI Inline Completion Shortcut Option
  • Loading branch information
jGauravGupta authored Feb 25, 2025
2 parents d82da1f + 5efdc88 commit daff6d9
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ public CompletionTask createTask(int type, JTextComponent component) {
if (!prefsManager.isSmartCodeEnabled()) {
return null;
}
if (type == COMPLETION_QUERY_TYPE) {
if ((prefsManager.isCompletionAllQueryType() && type == COMPLETION_ALL_QUERY_TYPE)
|| (!prefsManager.isCompletionAllQueryType() && type == COMPLETION_QUERY_TYPE)) {
return new AsyncCompletionTask(new JeddictCompletionQuery(type, component.getSelectionStart()), component);
}
return null;
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/io/github/jeddict/ai/settings/AIAssistancePanel.form
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
-->

<Form version="1.9" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<NonVisualComponents>
<Component class="javax.swing.ButtonGroup" name="aiInlineCompletionShortcutGroup">
</Component>
</NonVisualComponents>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
Expand Down Expand Up @@ -1156,6 +1160,51 @@
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JLayeredPane" name="snippetPane1">

<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout">
<Property name="alignment" type="int" value="0"/>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="aiInlineCompletionShortcutLabel">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="io/github/jeddict/ai/settings/Bundle.properties" key="AIAssistancePanel.aiInlineCompletionShortcutLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="io/github/jeddict/ai/settings/Bundle.properties" key="AIAssistancePanel.aiInlineCompletionShortcut.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JRadioButton" name="ctrlSpaceRadioButton">
<Properties>
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
<ComponentRef name="aiInlineCompletionShortcutGroup"/>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="io/github/jeddict/ai/settings/Bundle.properties" key="AIAssistancePanel.ctrlSpaceRadioButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="io/github/jeddict/ai/settings/Bundle.properties" key="AIAssistancePanel.aiInlineCompletionShortcut.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JRadioButton" name="ctrlAltSpaceRadioButton">
<Properties>
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
<ComponentRef name="aiInlineCompletionShortcutGroup"/>
</Property>
<Property name="selected" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="io/github/jeddict/ai/settings/Bundle.properties" key="AIAssistancePanel.ctrlAltSpaceRadioButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="io/github/jeddict/ai/settings/Bundle.properties" key="AIAssistancePanel.aiInlineCompletionShortcut.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JLayeredPane" name="snippetPane">

<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout">
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/io/github/jeddict/ai/settings/AIAssistancePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ final class AIAssistancePanel extends javax.swing.JPanel {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

aiInlineCompletionShortcutGroup = new javax.swing.ButtonGroup();
jTabbedPane1 = new javax.swing.JTabbedPane();
providersPane = new javax.swing.JLayeredPane();
providerParentPane = new javax.swing.JLayeredPane();
Expand Down Expand Up @@ -166,6 +167,10 @@ private void initComponents() {
varContextLabel = new javax.swing.JLabel();
varContextHelp = new javax.swing.JLabel();
varContextComboBox = new javax.swing.JComboBox<>();
snippetPane1 = new javax.swing.JLayeredPane();
aiInlineCompletionShortcutLabel = new javax.swing.JLabel();
ctrlSpaceRadioButton = new javax.swing.JRadioButton();
ctrlAltSpaceRadioButton = new javax.swing.JRadioButton();
snippetPane = new javax.swing.JLayeredPane();
showDescriptionCheckBox = new javax.swing.JCheckBox();
cachePane = new javax.swing.JLayeredPane();
Expand Down Expand Up @@ -689,6 +694,25 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {

inlineCompletionPane.add(varContextPane);

snippetPane1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

org.openide.awt.Mnemonics.setLocalizedText(aiInlineCompletionShortcutLabel, org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.aiInlineCompletionShortcutLabel.text")); // NOI18N
aiInlineCompletionShortcutLabel.setToolTipText(org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.aiInlineCompletionShortcut.toolTipText")); // NOI18N
snippetPane1.add(aiInlineCompletionShortcutLabel);

aiInlineCompletionShortcutGroup.add(ctrlSpaceRadioButton);
org.openide.awt.Mnemonics.setLocalizedText(ctrlSpaceRadioButton, org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.ctrlSpaceRadioButton.text")); // NOI18N
ctrlSpaceRadioButton.setToolTipText(org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.aiInlineCompletionShortcut.toolTipText")); // NOI18N
snippetPane1.add(ctrlSpaceRadioButton);

aiInlineCompletionShortcutGroup.add(ctrlAltSpaceRadioButton);
ctrlAltSpaceRadioButton.setSelected(true);
org.openide.awt.Mnemonics.setLocalizedText(ctrlAltSpaceRadioButton, org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.ctrlAltSpaceRadioButton.text")); // NOI18N
ctrlAltSpaceRadioButton.setToolTipText(org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.aiInlineCompletionShortcut.toolTipText")); // NOI18N
snippetPane1.add(ctrlAltSpaceRadioButton);

inlineCompletionPane.add(snippetPane1);

snippetPane.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

org.openide.awt.Mnemonics.setLocalizedText(showDescriptionCheckBox, org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.showDescriptionCheckBox.text")); // NOI18N
Expand Down Expand Up @@ -1109,6 +1133,8 @@ void load() {

providerComboBox.setSelectedItem(preferencesManager.getProvider());
modelComboBox.setSelectedItem(preferencesManager.getModel());
ctrlSpaceRadioButton.setSelected(!preferencesManager.isCompletionAllQueryType());
ctrlAltSpaceRadioButton.setSelected(preferencesManager.isCompletionAllQueryType());
showDescriptionCheckBox.setSelected(preferencesManager.isDescriptionEnabled());
fileExtField.setText(preferencesManager.getFileExtensionToInclude());
excludeJavadocCommentsCheckBox.setSelected(preferencesManager.isExcludeJavadocEnabled());
Expand Down Expand Up @@ -1144,6 +1170,7 @@ void store() {
preferencesManager.setInlineHintEnabled(enableInlineHintCheckBox.isSelected());
preferencesManager.setHintsEnabled(enableHintsCheckBox.isSelected());
preferencesManager.setSmartCodeEnabled(enableSmartCodeCheckBox.isSelected());
preferencesManager.setCompletionAllQueryType(ctrlAltSpaceRadioButton.isSelected());
preferencesManager.setDescriptionEnabled(showDescriptionCheckBox.isSelected());
preferencesManager.setFileExtensionToInclude(fileExtField.getText());
preferencesManager.setExcludeDirs(getCommaSeparatedValues(excludeTableModel));
Expand Down Expand Up @@ -1340,6 +1367,8 @@ boolean valid() {
private javax.swing.JLayeredPane activationPane;
private javax.swing.JLayeredPane activationParentPane;
private javax.swing.JCheckBox aiAssistantActivationCheckBox;
private javax.swing.ButtonGroup aiInlineCompletionShortcutGroup;
private javax.swing.JLabel aiInlineCompletionShortcutLabel;
private javax.swing.JCheckBox allowCodeExecution;
private javax.swing.JPasswordField apiKeyField;
private javax.swing.JLabel apiKeyInfo;
Expand All @@ -1361,6 +1390,8 @@ boolean valid() {
private javax.swing.JLayeredPane classContextPane;
private javax.swing.JButton cleanDataButton;
private javax.swing.JLayeredPane commonSettingsParentPane1;
private javax.swing.JRadioButton ctrlAltSpaceRadioButton;
private javax.swing.JRadioButton ctrlSpaceRadioButton;
private javax.swing.JLayeredPane customHeadersPane;
private javax.swing.JScrollPane customHeadersScrollPane;
private javax.swing.JTable customHeadersTable;
Expand Down Expand Up @@ -1433,6 +1464,7 @@ boolean valid() {
private javax.swing.JLayeredPane seedPane;
private javax.swing.JCheckBox showDescriptionCheckBox;
private javax.swing.JLayeredPane snippetPane;
private javax.swing.JLayeredPane snippetPane1;
private javax.swing.JCheckBox stream;
private javax.swing.JTextField temperature;
private javax.swing.JLabel temperatureLabel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,14 @@ public void setSmartCodeEnabled(boolean enabled) {
preferences.putBoolean("enableSmartCode", enabled);
}

public boolean isCompletionAllQueryType() {
return preferences.getBoolean("enableCompletionAllQueryType", true);
}

public void setCompletionAllQueryType(boolean enabled) {
preferences.putBoolean("enableCompletionAllQueryType", enabled);
}

public boolean isDescriptionEnabled() {
return preferences.getBoolean("showDecription", true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,7 @@ AIAssistancePanel.maxRetries.toolTipText=Maximum number of retries for failed AP
AIAssistancePanel.headerKey.text=Custom Header Key
AIAssistancePanel.headerValue.text=Custom Header Value
AIAssistancePanel.customHeadersTable.toolTipText=Custom headers can be to send specific metadata or authentication token
AIAssistancePanel.aiInlineCompletionShortcut.toolTipText=Select the keyboard shortcut to trigger AI-powered inline code completions.
AIAssistancePanel.aiInlineCompletionShortcutLabel.text=AI-Powered Inline Completion Shortcut:
AIAssistancePanel.ctrlSpaceRadioButton.text=CTRL+SPACE
AIAssistancePanel.ctrlAltSpaceRadioButton.text=CTRL+ALT+SPACE

0 comments on commit daff6d9

Please sign in to comment.