Skip to content

Commit 06d06d2

Browse files
authored
refactor: Enhance EasyApiSettingAI layout (#1209)
1 parent e5f0b25 commit 06d06d2

File tree

10 files changed

+116
-22
lines changed

10 files changed

+116
-22
lines changed

idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/core/RequestClassExporter.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,6 @@ abstract class RequestClassExporter : ClassExporter {
803803
-> {
804804
logger.info("try infer return type of method[" + PsiClassUtils.fullNameOfMethod(method.psi()) + "]")
805805
methodReturnInferHelper!!.inferReturn(method.psi())
806-
// actionContext!!.callWithTimeout(20000) { methodReturnInferHelper.inferReturn(method) }
807806
}
808807

809808
else -> psiClassHelper!!.getTypeObject(

idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/infer/MethodInferHelperFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class MethodInferHelperFactory {
3333
*/
3434
fun getMethodInferHelper(): MethodInferHelper {
3535
// Check if AI inference is enabled in settings
36-
if (aiSettingsHelper.aiEnable) {
36+
if (aiSettingsHelper.methodInferEnabled) {
3737
try {
3838
LOG.info("Using AI-based method inference")
3939
return aiMethodInferHelperProvider.get()

idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/EasyApiSettingAIGUI.form

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.itangcent.idea.plugin.dialog.EasyApiSettingAIGUI">
3-
<grid id="27dc6" binding="rootPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
3+
<grid id="27dc6" binding="rootPanel" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="0" left="0" bottom="0" right="0"/>
55
<constraints>
66
<xy x="20" y="20" width="500" height="3568"/>
77
</constraints>
88
<properties/>
99
<border type="none"/>
1010
<children>
11-
<grid id="e7a0a" layout-manager="GridLayoutManager" row-count="4" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
12-
<margin top="0" left="0" bottom="0" right="0"/>
11+
<!-- Panel 1: General AI Settings -->
12+
<grid id="e7a0a" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
13+
<margin top="10" left="10" bottom="10" right="10"/>
1314
<constraints>
1415
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
1516
</constraints>
1617
<properties/>
17-
<border type="none" title="AI Integration Settings"/>
18+
<border type="etched" title="General AI Settings"/>
1819
<children>
1920
<component id="c5a5a" class="javax.swing.JCheckBox" binding="aiEnableCheckBox">
2021
<constraints>
21-
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
22+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
2223
</constraints>
2324
<properties>
2425
<text value="Enable AI Integration (beta)"/>
@@ -27,24 +28,36 @@
2728
</component>
2829
<component id="f6b7c" class="javax.swing.JCheckBox" binding="aiEnableCacheCheckBox">
2930
<constraints>
30-
<grid row="0" column="2" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
31+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
3132
</constraints>
3233
<properties>
3334
<text value="Enable API Response Caching"/>
3435
<toolTipText value="Cache AI API responses to reduce API calls for identical requests"/>
3536
</properties>
3637
</component>
38+
</children>
39+
</grid>
40+
41+
<!-- Panel 2: Provider Settings -->
42+
<grid id="p2q3r" layout-manager="GridLayoutManager" row-count="2" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
43+
<margin top="10" left="10" bottom="10" right="10"/>
44+
<constraints>
45+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
46+
</constraints>
47+
<properties/>
48+
<border type="etched" title="AI Provider Configuration"/>
49+
<children>
3750
<component id="a8c9c" class="javax.swing.JLabel">
3851
<constraints>
39-
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
52+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
4053
</constraints>
4154
<properties>
42-
<text value="AI Type:"/>
55+
<text value="AI Provider:"/>
4356
</properties>
4457
</component>
4558
<component id="b7d1c" class="javax.swing.JComboBox" binding="aiProviderComboBox">
4659
<constraints>
47-
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
60+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
4861
</constraints>
4962
<properties>
5063
<model/>
@@ -53,15 +66,15 @@
5366
</component>
5467
<component id="d3e4f" class="javax.swing.JLabel">
5568
<constraints>
56-
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
69+
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
5770
</constraints>
5871
<properties>
5972
<text value="Model:"/>
6073
</properties>
6174
</component>
6275
<component id="f5g6h" class="javax.swing.JComboBox" binding="aiModelComboBox">
6376
<constraints>
64-
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
77+
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
6578
</constraints>
6679
<properties>
6780
<model/>
@@ -70,25 +83,37 @@
7083
</component>
7184
<component id="e7f8g" class="javax.swing.JLabel">
7285
<constraints>
73-
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
86+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
7487
</constraints>
7588
<properties>
7689
<text value="API Key:"/>
7790
</properties>
7891
</component>
7992
<component id="e5a5a" class="javax.swing.JPasswordField" binding="aiApiKeyField">
8093
<constraints>
81-
<grid row="2" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
94+
<grid row="1" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
8295
<preferred-size width="150" height="-1"/>
8396
</grid>
8497
</constraints>
8598
<properties>
8699
<toolTipText value="Your AI service API key"/>
87100
</properties>
88101
</component>
102+
</children>
103+
</grid>
104+
105+
<!-- Panel 3: Translation Settings -->
106+
<grid id="s4t5u" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
107+
<margin top="10" left="10" bottom="10" right="10"/>
108+
<constraints>
109+
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
110+
</constraints>
111+
<properties/>
112+
<border type="etched" title="Translation Settings"/>
113+
<children>
89114
<component id="h8i9j" class="javax.swing.JCheckBox" binding="aiTranslationEnabledCheckBox">
90115
<constraints>
91-
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
116+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
92117
</constraints>
93118
<properties>
94119
<text value="Enable API Translation"/>
@@ -97,15 +122,15 @@
97122
</component>
98123
<component id="k1l2m" class="javax.swing.JLabel">
99124
<constraints>
100-
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
125+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
101126
</constraints>
102127
<properties>
103128
<text value="Target Language:"/>
104129
</properties>
105130
</component>
106131
<component id="n3o4p" class="javax.swing.JComboBox" binding="translationTargetLanguageComboBox">
107132
<constraints>
108-
<grid row="3" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
133+
<grid row="0" column="2" row-span="1" col-span="2" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
109134
</constraints>
110135
<properties>
111136
<model/>
@@ -114,9 +139,31 @@
114139
</component>
115140
</children>
116141
</grid>
142+
143+
<!-- Panel 4: Method Inference Settings -->
144+
<grid id="t6u7v" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
145+
<margin top="10" left="10" bottom="10" right="10"/>
146+
<constraints>
147+
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
148+
</constraints>
149+
<properties/>
150+
<border type="etched" title="Method Inference Settings"/>
151+
<children>
152+
<component id="w9x0y" class="javax.swing.JCheckBox" binding="aiMethodInferEnabledCheckBox">
153+
<constraints>
154+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
155+
</constraints>
156+
<properties>
157+
<text value="Enable AI for Method Return Type Inference"/>
158+
<toolTipText value="Use AI to infer method return types for better API documentation"/>
159+
</properties>
160+
</component>
161+
</children>
162+
</grid>
163+
117164
<vspacer id="q5r6s">
118165
<constraints>
119-
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
166+
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
120167
</constraints>
121168
</vspacer>
122169
</children>

idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/EasyApiSettingAIGUI.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class EasyApiSettingAIGUI : AbstractEasyApiSettingGUI() {
2222
private var aiEnableCacheCheckBox: JCheckBox? = null
2323
private var aiTranslationEnabledCheckBox: JCheckBox? = null
2424
private var translationTargetLanguageComboBox: JComboBox<DisplayItem<Language>>? = null
25+
private var aiMethodInferEnabledCheckBox: JCheckBox? = null
2526

2627
// Store the last selected AI Provider to detect changes
2728
private var lastSelectedAIProvider: AIProvider? = null
@@ -115,6 +116,9 @@ class EasyApiSettingAIGUI : AbstractEasyApiSettingGUI() {
115116
settings.aiTranslationTargetLanguage = translationTargetLanguageComboBox?.let {
116117
SwingUtils.getSelectedItem(it)?.code
117118
}
119+
120+
// Method inference settings
121+
settings.aiMethodInferEnabled = aiMethodInferEnabledCheckBox?.isSelected == true
118122
}
119123

120124
/**
@@ -170,5 +174,8 @@ class EasyApiSettingAIGUI : AbstractEasyApiSettingGUI() {
170174
SwingUtils.setSelectedItem(translationTargetLanguageComboBox!!, Language.getDefault()) { a, b -> a.code == b.code }
171175
}
172176
}
177+
178+
// Method inference settings
179+
aiMethodInferEnabledCheckBox?.isSelected = settings.aiMethodInferEnabled
173180
}
174181
}

idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/rule/ScriptRuleParser.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,8 @@ abstract class ScriptRuleParser : AbstractRuleParser() {
13241324
}
13251325

13261326
open fun returnObject(
1327-
needInfer: Boolean = false, readGetter: Boolean = true,
1327+
needInfer: Boolean = false,
1328+
readGetter: Boolean = true,
13281329
readSetter: Boolean = true,
13291330
): Any? {
13301331
val psiType = psiMethod.getResolvedReturnType() ?: return null

idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/settings/Settings.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ class Settings : ProjectSettingsSupport, ApplicationSettingsSupport {
153153
* Target language for API translation
154154
*/
155155
override var aiTranslationTargetLanguage: String? = null
156+
157+
/**
158+
* Enable AI for method return type inference
159+
*/
160+
override var aiMethodInferEnabled: Boolean = false
156161

157162
//endregion AI integration--------------------------
158163

@@ -218,6 +223,7 @@ class Settings : ProjectSettingsSupport, ApplicationSettingsSupport {
218223
if (aiEnableCache != other.aiEnableCache) return false
219224
if (aiTranslationEnabled != other.aiTranslationEnabled) return false
220225
if (aiTranslationTargetLanguage != other.aiTranslationTargetLanguage) return false
226+
if (aiMethodInferEnabled != other.aiMethodInferEnabled) return false
221227

222228
return true
223229
}
@@ -272,6 +278,7 @@ class Settings : ProjectSettingsSupport, ApplicationSettingsSupport {
272278
result = 31 * result + aiEnableCache.hashCode()
273279
result = 31 * result + aiTranslationEnabled.hashCode()
274280
result = 31 * result + (aiTranslationTargetLanguage?.hashCode() ?: 0)
281+
result = 31 * result + aiMethodInferEnabled.hashCode()
275282
return result
276283
}
277284

@@ -307,7 +314,8 @@ class Settings : ProjectSettingsSupport, ApplicationSettingsSupport {
307314
"aiModel=$aiModel, " +
308315
"aiEnableCache=$aiEnableCache, " +
309316
"aiTranslationEnabled=$aiTranslationEnabled, " +
310-
"aiTranslationTargetLanguage=$aiTranslationTargetLanguage)"
317+
"aiTranslationTargetLanguage=$aiTranslationTargetLanguage, " +
318+
"aiMethodInferEnabled=$aiMethodInferEnabled)"
311319
}
312320

313321
companion object {

idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/settings/helper/AISettingsHelper.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ class AISettingsHelper {
4747
aiEnable && aiTranslationEnabled && aiTranslationTargetLanguage != null
4848
}
4949

50+
/**
51+
* Check if AI method inference is enabled
52+
*/
53+
val methodInferEnabled: Boolean
54+
get() = settingBinder.read().run {
55+
aiEnable && aiMethodInferEnabled
56+
}
57+
5058
/**
5159
* Get the target language for API translation
5260
* Returns the language name (e.g., "English") instead of the language code (e.g., "en")

idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/settings/helper/IntelligentSettingsHelper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class IntelligentSettingsHelper {
2828
}
2929

3030
fun inferEnable(): Boolean {
31-
return settingBinder.read().inferEnable
31+
return settingBinder.read().run { inferEnable or aiMethodInferEnabled }
3232
}
3333

3434
fun inferMaxDeep(): Int {

idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/settings/xml/ApplicationSettings.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ interface ApplicationSettingsSupport {
6363
// API Translation
6464
var aiTranslationEnabled: Boolean
6565
var aiTranslationTargetLanguage: String?
66+
67+
// AI Method Inference
68+
var aiMethodInferEnabled: Boolean
6669

6770
fun copyTo(newSetting: ApplicationSettingsSupport) {
6871
newSetting.postmanToken = this.postmanToken
@@ -110,6 +113,7 @@ interface ApplicationSettingsSupport {
110113
newSetting.aiEnableCache = this.aiEnableCache
111114
newSetting.aiTranslationEnabled = this.aiTranslationEnabled
112115
newSetting.aiTranslationTargetLanguage = this.aiTranslationTargetLanguage
116+
newSetting.aiMethodInferEnabled = this.aiMethodInferEnabled
113117
}
114118
}
115119

@@ -227,6 +231,9 @@ class ApplicationSettings : ApplicationSettingsSupport {
227231
// API Translation
228232
override var aiTranslationEnabled: Boolean = false
229233
override var aiTranslationTargetLanguage: String? = null
234+
235+
// AI Method Inference
236+
override var aiMethodInferEnabled: Boolean = false
230237

231238
fun copy(): ApplicationSettings {
232239
val applicationSettings = ApplicationSettings()

idea-plugin/src/test/kotlin/com/itangcent/idea/plugin/api/infer/MethodInferHelperFactoryTest.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class MethodInferHelperFactoryTest : PluginContextLightCodeInsightFixtureTestCas
2828

2929
fun testGetDefaultMethodInferHelper() {
3030
settings.aiEnable = false
31+
settings.aiMethodInferEnabled = false
3132

3233
// Get the helper from the factory
3334
val helper = methodInferHelperFactory.getMethodInferHelper()
@@ -38,10 +39,26 @@ class MethodInferHelperFactoryTest : PluginContextLightCodeInsightFixtureTestCas
3839

3940
fun testGetAIMethodInferHelper() {
4041
settings.aiEnable = true
42+
settings.aiMethodInferEnabled = true
4143
settings.aiProvider = "OpenAI"
4244
settings.aiModel = "gpt-4"
4345
settings.aiToken = "test-token-123"
4446
// Verify it's the AI helper
4547
assertIs<AIMethodInferHelper>(methodInferHelperFactory.getMethodInferHelper())
4648
}
49+
50+
fun testAIEnabledButMethodInferDisabled() {
51+
// Set AI enabled but method inference disabled
52+
settings.aiEnable = true
53+
settings.aiMethodInferEnabled = false
54+
settings.aiProvider = "OpenAI"
55+
settings.aiModel = "gpt-4"
56+
settings.aiToken = "test-token-123"
57+
58+
// Get the helper from the factory
59+
val helper = methodInferHelperFactory.getMethodInferHelper()
60+
61+
// Verify it's the default helper since method inference is disabled
62+
assertTrue(helper is DefaultMethodInferHelper)
63+
}
4764
}

0 commit comments

Comments
 (0)