diff --git a/common-api/build.gradle b/common-api/build.gradle index fb1632b74..b59194fa2 100644 --- a/common-api/build.gradle +++ b/common-api/build.gradle @@ -26,7 +26,7 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" - implementation('com.itangcent:commons:1.2.4') { + implementation('com.itangcent:commons:1.2.5') { exclude group: 'com.google.inject' exclude group: 'com.google.code.gson' } diff --git a/idea-plugin/build.gradle b/idea-plugin/build.gradle index 6c81c298d..b8eec5d18 100644 --- a/idea-plugin/build.gradle +++ b/idea-plugin/build.gradle @@ -78,17 +78,17 @@ dependencies { // implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation('com.itangcent:intellij-idea:1.2.4') { + implementation('com.itangcent:intellij-idea:1.2.5') { exclude group: 'com.google.inject' exclude group: 'com.google.code.gson' } - implementation('com.itangcent:intellij-kotlin-support:1.2.4') { + implementation('com.itangcent:intellij-kotlin-support:1.2.5') { exclude group: 'com.google.inject' exclude group: 'com.google.code.gson' } -// implementation('com.itangcent:intellij-scala-support:1.2.4') { +// implementation('com.itangcent:intellij-scala-support:1.2.5') { // exclude group: 'com.google.inject' // exclude group: 'com.google.code.gson' // } @@ -122,7 +122,7 @@ dependencies { // https://mvnrepository.com/artifact/org.mockito/mockito-inline testImplementation group: 'org.mockito', name: 'mockito-inline', version: '3.11.0' - testImplementation('com.itangcent:intellij-idea-test:1.2.4') { + testImplementation('com.itangcent:intellij-idea-test:1.2.5') { exclude group: 'com.nhaarman.mockitokotlin2', module: 'mockito-kotlin' } } diff --git a/idea-plugin/src/main/kotlin/com/itangcent/condition/AnnotatedCondition.kt b/idea-plugin/src/main/kotlin/com/itangcent/condition/AnnotatedCondition.kt index 5ff227a64..17f652c50 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/condition/AnnotatedCondition.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/condition/AnnotatedCondition.kt @@ -57,5 +57,5 @@ abstract class AnnotatedCondition : Condition, ConditionSupporte throw IllegalArgumentException("failed get condition class of ${this::class}") } - abstract protected fun matches(actionContext: ActionContext, annotation: T): Boolean + protected abstract fun matches(actionContext: ActionContext, annotation: T): Boolean } diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/ApiCallAction.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/ApiCallAction.kt index b181a8825..fd1d6c24c 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/ApiCallAction.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/ApiCallAction.kt @@ -4,14 +4,10 @@ import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.project.Project import com.itangcent.idea.plugin.api.cache.CachedRequestClassExporter import com.itangcent.idea.plugin.api.call.ApiCaller -import com.itangcent.idea.plugin.api.export.ExportChannel import com.itangcent.idea.plugin.api.export.ExportDoc -import com.itangcent.idea.plugin.api.export.condition.ConditionOnSimple import com.itangcent.idea.plugin.api.export.core.ClassExporter import com.itangcent.idea.plugin.api.export.core.CompositeClassExporter import com.itangcent.idea.plugin.api.export.core.EasyApiConfigReader -import com.itangcent.idea.plugin.api.export.generic.GenericRequestClassExporter -import com.itangcent.idea.plugin.api.export.spring.SpringRequestClassExporter import com.itangcent.idea.plugin.config.RecommendConfigReader import com.itangcent.intellij.config.ConfigReader import com.itangcent.intellij.context.ActionContext @@ -35,7 +31,7 @@ class ApiCallAction : ApiExportAction("Call Api") { } builder.bindInstance(ExportDoc::class, ExportDoc.of("request")) - + builder.bind(ClassExporter::class) { it.with(CachedRequestClassExporter::class).singleton() } builder.bind(ConfigReader::class, "delegate_config_reader") { it.with(EasyApiConfigReader::class).singleton() } @@ -44,7 +40,6 @@ class ApiCallAction : ApiExportAction("Call Api") { builder.bind(HttpClientProvider::class) { it.with(ConfigurableHttpClientProvider::class).singleton() } builder.bind(ApiCaller::class) { it.singleton() } - } override fun actionPerformed(actionContext: ActionContext, project: Project?, anActionEvent: AnActionEvent) { diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/ApiExportAction.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/ApiExportAction.kt index 16029d07d..f6210eb35 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/ApiExportAction.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/ApiExportAction.kt @@ -1,6 +1,7 @@ package com.itangcent.idea.plugin.actions import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.project.Project import com.itangcent.idea.plugin.api.cache.DefaultFileApiCacheRepository import com.itangcent.idea.plugin.api.cache.FileApiCacheRepository import com.itangcent.idea.plugin.api.cache.ProjectCacheRepository @@ -12,10 +13,12 @@ import com.itangcent.idea.utils.RuleComputeListenerRegistry import com.itangcent.intellij.config.rule.RuleComputeListener import com.itangcent.intellij.config.rule.RuleParser import com.itangcent.intellij.context.ActionContext +import com.itangcent.intellij.extend.findCurrentMethod import com.itangcent.intellij.extend.guice.singleton import com.itangcent.intellij.extend.guice.with import com.itangcent.intellij.file.LocalFileRepository import com.itangcent.intellij.jvm.PsiClassHelper +import com.itangcent.intellij.util.ActionUtils abstract class ApiExportAction(text: String) : BasicAnAction(text) { @@ -33,4 +36,9 @@ abstract class ApiExportAction(text: String) : BasicAnAction(text) { it.with(ProjectCacheRepository::class).singleton() } } + + override fun actionPerformed(actionContext: ActionContext, project: Project?, anActionEvent: AnActionEvent) { + super.actionPerformed(actionContext, project, anActionEvent) + actionContext.findCurrentMethod() + } } \ No newline at end of file diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/MarkdownExportAction.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/MarkdownExportAction.kt index 35d1cc041..e1e0d081f 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/MarkdownExportAction.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/MarkdownExportAction.kt @@ -5,9 +5,7 @@ import com.intellij.openapi.project.Project import com.itangcent.idea.plugin.api.export.ExportChannel import com.itangcent.idea.plugin.api.export.ExportDoc import com.itangcent.idea.plugin.api.export.condition.ConditionOnSimple -import com.itangcent.idea.plugin.api.export.core.ClassExporter -import com.itangcent.idea.plugin.api.export.core.CompositeClassExporter -import com.itangcent.idea.plugin.api.export.core.EasyApiConfigReader +import com.itangcent.idea.plugin.api.export.core.* import com.itangcent.idea.plugin.api.export.generic.GenericMethodDocClassExporter import com.itangcent.idea.plugin.api.export.generic.GenericRequestClassExporter import com.itangcent.idea.plugin.api.export.markdown.MarkdownApiExporter @@ -34,7 +32,9 @@ class MarkdownExportAction : ApiExportAction("Export Markdown") { builder.bindInstance(ExportChannel::class, ExportChannel.of("markdown")) builder.bindInstance(ExportDoc::class, ExportDoc.of("request", "methodDoc")) - + + builder.bind(MethodFilter::class) { it.with(ConfigurableMethodFilter::class).singleton() } + //always not read api from cache builder.bindInstance("class.exporter.read.cache", false) diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/PostmanExportAction.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/PostmanExportAction.kt index f310830d2..3c87710b4 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/PostmanExportAction.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/PostmanExportAction.kt @@ -37,6 +37,8 @@ class PostmanExportAction : ApiExportAction("Export Postman") { builder.bindInstance(ExportDoc::class, ExportDoc.of("request")) builder.bind(RequestBuilderListener::class) { it.with(CompositeRequestBuilderListener::class).singleton() } + + builder.bind(MethodFilter::class) { it.with(ConfigurableMethodFilter::class).singleton() } //always not read api from cache builder.bindInstance("class.exporter.read.cache", false) diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/SuvExportAction.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/SuvExportAction.kt index e7a6c7b06..c0042b64a 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/SuvExportAction.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/SuvExportAction.kt @@ -7,9 +7,7 @@ import com.intellij.openapi.project.Project import com.itangcent.idea.plugin.DataEventCollector import com.itangcent.idea.plugin.api.export.ExportDoc import com.itangcent.idea.plugin.api.export.condition.markAsSimple -import com.itangcent.idea.plugin.api.export.core.ClassExporter -import com.itangcent.idea.plugin.api.export.core.CompositeClassExporter -import com.itangcent.idea.plugin.api.export.core.EasyApiConfigReader +import com.itangcent.idea.plugin.api.export.core.* import com.itangcent.idea.plugin.api.export.postman.PostmanApiHelper import com.itangcent.idea.plugin.api.export.postman.PostmanCachedApiHelper import com.itangcent.idea.plugin.api.export.suv.SuvApiExporter @@ -54,6 +52,8 @@ class SuvExportAction : ApiExportAction("Export Api") { builder.bind(SuvApiExporter::class) { it.singleton() } + builder.bind(MethodFilter::class) { it.with(ConfigurableMethodFilter::class).singleton() } + builder.cache("DATA_EVENT_COLLECTOR", dataEventCollector) dataEventCollector = null @@ -68,6 +68,7 @@ class SuvExportAction : ApiExportAction("Export Api") { dataContext.getData(CommonDataKeys.NAVIGATABLE_ARRAY) dataContext.getData(CommonDataKeys.NAVIGATABLE) dataContext.getData(CommonDataKeys.EDITOR) + dataContext.getData(CommonDataKeys.PSI_ELEMENT) } override fun actionPerformed(actionContext: ActionContext, project: Project?, anActionEvent: AnActionEvent) { diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/YapiExportAction.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/YapiExportAction.kt index 4f92d651a..991f9b842 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/YapiExportAction.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/YapiExportAction.kt @@ -40,6 +40,8 @@ class YapiExportAction : ApiExportAction("Export Yapi") { builder.bind(RequestBuilderListener::class) { it.with(CompositeRequestBuilderListener::class).singleton() } builder.bind(MethodDocBuilderListener::class) { it.with(CompositeMethodDocBuilderListener::class).singleton() } + builder.bind(MethodFilter::class) { it.with(ConfigurableMethodFilter::class).singleton() } + builder.bindInstance("file.save.default", "yapi.json") builder.bindInstance("file.save.last.location.key", "com.itangcent.yapi.export.path") diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/core/MethodFilter.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/core/MethodFilter.kt index b0be434c1..d9a8b6c29 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/core/MethodFilter.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/core/MethodFilter.kt @@ -1,8 +1,12 @@ package com.itangcent.idea.plugin.api.export.core import com.google.inject.ImplementedBy +import com.google.inject.Inject import com.google.inject.Singleton import com.intellij.psi.PsiMethod +import com.itangcent.idea.plugin.settings.helper.IntelligentSettingsHelper +import com.itangcent.intellij.context.ActionContext +import com.itangcent.intellij.extend.findCurrentMethod @ImplementedBy(EmptyMethodFilter::class) interface MethodFilter { @@ -14,5 +18,22 @@ class EmptyMethodFilter : MethodFilter { override fun checkMethod(method: PsiMethod): Boolean { return true } +} + +@Singleton +class ConfigurableMethodFilter : MethodFilter { + @Inject + private lateinit var intelligentSettingsHelper: IntelligentSettingsHelper + + private val selectedMethod by lazy { + return@lazy ActionContext.getContext()?.findCurrentMethod() + } + + override fun checkMethod(method: PsiMethod): Boolean { + if (intelligentSettingsHelper.selectedOnly()) { + return selectedMethod == null || selectedMethod == method + } + return true + } } \ No newline at end of file diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/suv/SuvApiExporter.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/suv/SuvApiExporter.kt index 8ea1d1cb3..4a8c2bf84 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/suv/SuvApiExporter.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/suv/SuvApiExporter.kt @@ -4,6 +4,7 @@ import com.google.inject.Inject import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.DataContext import com.intellij.openapi.project.Project +import com.intellij.psi.PsiElement import com.intellij.psi.PsiMethod import com.itangcent.common.logger.traceError import com.itangcent.common.model.Doc @@ -30,10 +31,7 @@ import com.itangcent.idea.plugin.rule.SuvRuleParser import com.itangcent.idea.plugin.script.GroovyActionExtLoader import com.itangcent.idea.plugin.script.LoggerBuffer import com.itangcent.idea.plugin.settings.SettingBinder -import com.itangcent.idea.plugin.settings.helper.MarkdownSettingsHelper -import com.itangcent.idea.plugin.settings.helper.PostmanSettingsHelper -import com.itangcent.idea.plugin.settings.helper.YapiSettingsHelper -import com.itangcent.idea.plugin.settings.helper.YapiTokenChecker +import com.itangcent.idea.plugin.settings.helper.* import com.itangcent.idea.psi.PsiResource import com.itangcent.idea.swing.MessagesHelper import com.itangcent.idea.utils.CustomizedPsiClassHelper @@ -45,6 +43,7 @@ import com.itangcent.intellij.config.rule.RuleComputeListener import com.itangcent.intellij.config.rule.RuleParser import com.itangcent.intellij.constant.EventKey import com.itangcent.intellij.context.ActionContext +import com.itangcent.intellij.extend.findCurrentMethod import com.itangcent.intellij.extend.guice.singleton import com.itangcent.intellij.extend.guice.with import com.itangcent.intellij.extend.withBoundary @@ -73,10 +72,10 @@ open class SuvApiExporter { private lateinit var actionContext: ActionContext @Inject - private val classExporter: ClassExporter? = null + private lateinit var classApiExporterHelper: ClassApiExporterHelper @Inject - private lateinit var classApiExporterHelper: ClassApiExporterHelper + private lateinit var intelligentSettingsHelper: IntelligentSettingsHelper @Suppress("UNCHECKED_CAST") fun showExportWindow() { @@ -98,11 +97,11 @@ open class SuvApiExporter { multipleApiExportDialog.setOnChannelChanged { channel -> if (channel == null) { - multipleApiExportDialog.updateRequestList(docs) + multipleApiExportDialog.updateRequestListToUI(docs) return@setOnChannelChanged } val apiExporterAdapter = channel as ApiExporterWrapper - multipleApiExportDialog.updateRequestList(docs + multipleApiExportDialog.updateRequestListToUI(docs .filter { apiExporterAdapter.support(it.docType) } .toList()) } @@ -118,6 +117,21 @@ open class SuvApiExporter { } } + private fun SuvApiExportDialog.updateRequestListToUI(docs: List) { + this.updateRequestList(docs) + if (intelligentSettingsHelper.selectedOnly()) { + val currentMethod = actionContext.findCurrentMethod() + if (currentMethod != null) { + docs.firstOrNull { it.resourceMethod() == currentMethod } + ?.let { + this.selectMethod(it) + return + } + } + } + this.selectAll() + } + private var customActionExtLoader: ((String, ActionContext.ActionContextBuilder) -> Unit)? = null fun setCustomActionExtLoader(customActionExtLoader: (String, ActionContext.ActionContextBuilder) -> Unit) { @@ -151,6 +165,10 @@ open class SuvApiExporter { } } + fun DocWrapper.resourceMethod(): PsiMethod? { + return (this.resource as? PsiResource)?.resource() as? PsiMethod + } + abstract class ApiExporterAdapter { @Inject(optional = true) diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/EasyApiSettingGUI.form b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/EasyApiSettingGUI.form index 9821193d1..cc92d4953 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/EasyApiSettingGUI.form +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/EasyApiSettingGUI.form @@ -1137,7 +1137,7 @@ - + @@ -1277,7 +1277,16 @@ - + + + + + + + + + + diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/EasyApiSettingGUI.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/EasyApiSettingGUI.kt index ccdef688b..4f8f17473 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/EasyApiSettingGUI.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/EasyApiSettingGUI.kt @@ -131,6 +131,8 @@ class EasyApiSettingGUI : AbstractEasyApiSettingGUI() { private var inferEnableCheckBox: JCheckBox? = null + private var selectedOnlyCheckBox: JCheckBox? = null + private var maxDeepTextField: JTextField? = null private var readGetterCheckBox: JCheckBox? = null @@ -268,6 +270,7 @@ class EasyApiSettingGUI : AbstractEasyApiSettingGUI() { this.feignEnableCheckBox!!.isSelected = settings.feignEnable this.jaxrsEnableCheckBox!!.isSelected = settings.jaxrsEnable this.inferEnableCheckBox!!.isSelected = settings.inferEnable + this.selectedOnlyCheckBox!!.isSelected = settings.selectedOnly this.readGetterCheckBox!!.isSelected = settings.readGetter this.readSetterCheckBox!!.isSelected = settings.readSetter this.formExpandedCheckBox!!.isSelected = settings.formExpanded @@ -581,6 +584,7 @@ class EasyApiSettingGUI : AbstractEasyApiSettingGUI() { settings.readGetter = readGetterCheckBox!!.isSelected settings.readSetter = readSetterCheckBox!!.isSelected settings.inferEnable = inferEnableCheckBox!!.isSelected + settings.selectedOnly = selectedOnlyCheckBox!!.isSelected settings.inferMaxDeep = maxDeepTextField!!.text.toIntOrNull() ?: Settings.DEFAULT_INFER_MAX_DEEP settings.yapiServer = yapiServerTextField!!.text settings.yapiTokens = yapiTokenTextArea!!.text diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/SuvApiExportDialog.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/SuvApiExportDialog.kt index 4268a150d..3d62a4282 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/SuvApiExportDialog.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/SuvApiExportDialog.kt @@ -1,7 +1,7 @@ package com.itangcent.idea.plugin.dialog -import com.google.inject.Inject import com.intellij.ide.util.PropertiesComponent +import com.intellij.psi.PsiMethod import com.intellij.ui.components.JBCheckBox import com.itangcent.common.logger.traceError import com.itangcent.common.utils.GsonUtils @@ -9,7 +9,6 @@ import com.itangcent.common.utils.notNullOrEmpty import com.itangcent.idea.icons.EasyIcons import com.itangcent.idea.icons.iconOnly import com.itangcent.idea.utils.SwingUtils -import com.itangcent.intellij.jvm.PsiClassHelper import java.awt.event.KeyEvent import java.awt.event.WindowAdapter import java.awt.event.WindowEvent @@ -32,9 +31,6 @@ class SuvApiExportDialog : ContextDialog() { private var onChannelChanged: ((Any?) -> Unit)? = null - @Inject - var psiClassHelper: PsiClassHelper? = null - init { this.isUndecorated = false this.isResizable = false @@ -61,14 +57,18 @@ class SuvApiExportDialog : ContextDialog() { EasyIcons.OK.iconOnly(this.buttonOK) // call onCancel() on ESCAPE - contentPane!!.registerKeyboardAction({ onCancel() }, + contentPane!!.registerKeyboardAction( + { onCancel() }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) + JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT + ) // call onCallClick() on ENTER - contentPane!!.registerKeyboardAction({ onOK() }, + contentPane!!.registerKeyboardAction( + { onOK() }, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) + JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT + ) selectAllCheckBox!!.addChangeListener { onSelectedAll() @@ -90,12 +90,20 @@ class SuvApiExportDialog : ContextDialog() { fun updateRequestList(requestList: List<*>) { this.docList = requestList this.apiList!!.model = DefaultComboBoxModel(requestList.toTypedArray()) + } + fun selectAll(){ this.selectAllCheckBox!!.isSelected = true - onSelectedAll() } + fun selectMethod(api: Any?){ + this.selectAllCheckBox!!.isSelected = false + this.docList?.indexOf(api)?.let { + apiList!!.selectedIndex = it + } + } + fun setChannels(channels: List<*>) { this.channelComboBox!!.model = DefaultComboBoxModel(channels.toTypedArray()) diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/settings/Settings.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/settings/Settings.kt index 20ba23b67..784a88492 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/settings/Settings.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/settings/Settings.kt @@ -47,6 +47,8 @@ class Settings : ProjectSettingsSupport, ApplicationSettingsSupport { override var inferMaxDeep: Int = DEFAULT_INFER_MAX_DEEP + override var selectedOnly: Boolean = false + //endregion //yapi @@ -112,11 +114,11 @@ class Settings : ProjectSettingsSupport, ApplicationSettingsSupport { other as Settings - if (pullNewestDataBefore != other.pullNewestDataBefore) return false if (methodDocEnable != other.methodDocEnable) return false if (genericEnable != other.genericEnable) return false if (feignEnable != other.feignEnable) return false if (jaxrsEnable != other.jaxrsEnable) return false + if (pullNewestDataBefore != other.pullNewestDataBefore) return false if (postmanToken != other.postmanToken) return false if (postmanWorkspace != other.postmanWorkspace) return false if (postmanExportMode != other.postmanExportMode) return false @@ -130,6 +132,7 @@ class Settings : ProjectSettingsSupport, ApplicationSettingsSupport { if (readSetter != other.readSetter) return false if (inferEnable != other.inferEnable) return false if (inferMaxDeep != other.inferMaxDeep) return false + if (selectedOnly != other.selectedOnly) return false if (yapiServer != other.yapiServer) return false if (yapiTokens != other.yapiTokens) return false if (enableUrlTemplating != other.enableUrlTemplating) return false @@ -138,6 +141,7 @@ class Settings : ProjectSettingsSupport, ApplicationSettingsSupport { if (yapiReqBodyJson5 != other.yapiReqBodyJson5) return false if (yapiResBodyJson5 != other.yapiResBodyJson5) return false if (httpTimeOut != other.httpTimeOut) return false + if (!trustHosts.contentEquals(other.trustHosts)) return false if (useRecommendConfig != other.useRecommendConfig) return false if (recommendConfigs != other.recommendConfigs) return false if (logLevel != other.logLevel) return false @@ -146,17 +150,16 @@ class Settings : ProjectSettingsSupport, ApplicationSettingsSupport { if (outputCharset != other.outputCharset) return false if (markdownFormatType != other.markdownFormatType) return false if (builtInConfig != other.builtInConfig) return false - if (!trustHosts.contentEquals(other.trustHosts)) return false return true } override fun hashCode(): Int { - var result = pullNewestDataBefore.hashCode() - result = 31 * result + methodDocEnable.hashCode() + var result = methodDocEnable.hashCode() result = 31 * result + genericEnable.hashCode() result = 31 * result + feignEnable.hashCode() result = 31 * result + jaxrsEnable.hashCode() + result = 31 * result + pullNewestDataBefore.hashCode() result = 31 * result + (postmanToken?.hashCode() ?: 0) result = 31 * result + (postmanWorkspace?.hashCode() ?: 0) result = 31 * result + (postmanExportMode?.hashCode() ?: 0) @@ -170,6 +173,7 @@ class Settings : ProjectSettingsSupport, ApplicationSettingsSupport { result = 31 * result + readSetter.hashCode() result = 31 * result + inferEnable.hashCode() result = 31 * result + inferMaxDeep + result = 31 * result + selectedOnly.hashCode() result = 31 * result + (yapiServer?.hashCode() ?: 0) result = 31 * result + (yapiTokens?.hashCode() ?: 0) result = 31 * result + enableUrlTemplating.hashCode() @@ -178,6 +182,7 @@ class Settings : ProjectSettingsSupport, ApplicationSettingsSupport { result = 31 * result + yapiReqBodyJson5.hashCode() result = 31 * result + yapiResBodyJson5.hashCode() result = 31 * result + httpTimeOut + result = 31 * result + trustHosts.contentHashCode() result = 31 * result + useRecommendConfig.hashCode() result = 31 * result + recommendConfigs.hashCode() result = 31 * result + logLevel @@ -185,13 +190,12 @@ class Settings : ProjectSettingsSupport, ApplicationSettingsSupport { result = 31 * result + outputDemo.hashCode() result = 31 * result + outputCharset.hashCode() result = 31 * result + markdownFormatType.hashCode() - result = 31 * result + builtInConfig.hashCode() - result = 31 * result + trustHosts.hashCode() + result = 31 * result + (builtInConfig?.hashCode() ?: 0) return result } override fun toString(): String { - return "Settings(methodDocEnable=$methodDocEnable, genericEnable=$genericEnable, feignEnable=$feignEnable, jaxrsEnable=$jaxrsEnable, pullNewestDataBefore=$pullNewestDataBefore, postmanToken=$postmanToken, postmanWorkspace=$postmanWorkspace, postmanExportMode=$postmanExportMode, postmanCollections=$postmanCollections, wrapCollection=$wrapCollection, autoMergeScript=$autoMergeScript, postmanJson5FormatType='$postmanJson5FormatType', queryExpanded=$queryExpanded, formExpanded=$formExpanded, readGetter=$readGetter, readSetter=$readSetter, inferEnable=$inferEnable, inferMaxDeep=$inferMaxDeep, yapiServer=$yapiServer, yapiTokens=$yapiTokens, enableUrlTemplating=$enableUrlTemplating, switchNotice=$switchNotice, loginMode=$loginMode, yapiReqBodyJson5=$yapiReqBodyJson5, yapiResBodyJson5=$yapiResBodyJson5, httpTimeOut=$httpTimeOut, trustHosts=${trustHosts.contentToString()}, useRecommendConfig=$useRecommendConfig, recommendConfigs='$recommendConfigs', logLevel=$logLevel, logCharset='$logCharset', outputDemo=$outputDemo, outputCharset='$outputCharset', markdownFormatType='$markdownFormatType', builtInConfig=$builtInConfig)" + return "Settings(methodDocEnable=$methodDocEnable, genericEnable=$genericEnable, feignEnable=$feignEnable, jaxrsEnable=$jaxrsEnable, pullNewestDataBefore=$pullNewestDataBefore, postmanToken=$postmanToken, postmanWorkspace=$postmanWorkspace, postmanExportMode=$postmanExportMode, postmanCollections=$postmanCollections, wrapCollection=$wrapCollection, autoMergeScript=$autoMergeScript, postmanJson5FormatType='$postmanJson5FormatType', queryExpanded=$queryExpanded, formExpanded=$formExpanded, readGetter=$readGetter, readSetter=$readSetter, inferEnable=$inferEnable, inferMaxDeep=$inferMaxDeep, selectedOnly=$selectedOnly, yapiServer=$yapiServer, yapiTokens=$yapiTokens, enableUrlTemplating=$enableUrlTemplating, switchNotice=$switchNotice, loginMode=$loginMode, yapiReqBodyJson5=$yapiReqBodyJson5, yapiResBodyJson5=$yapiResBodyJson5, httpTimeOut=$httpTimeOut, trustHosts=${trustHosts.contentToString()}, useRecommendConfig=$useRecommendConfig, recommendConfigs='$recommendConfigs', logLevel=$logLevel, logCharset='$logCharset', outputDemo=$outputDemo, outputCharset='$outputCharset', markdownFormatType='$markdownFormatType', builtInConfig=$builtInConfig)" } companion object { diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/settings/helper/IntelligentSettingsHelper.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/settings/helper/IntelligentSettingsHelper.kt index d800d7baa..05f7874ff 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/settings/helper/IntelligentSettingsHelper.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/settings/helper/IntelligentSettingsHelper.kt @@ -35,6 +35,10 @@ class IntelligentSettingsHelper { return settingBinder.read().inferMaxDeep } + fun selectedOnly(): Boolean { + return settingBinder.read().selectedOnly + } + fun jsonOptionForInput(jsonOption: Int): Int { return if (readSetter()) { jsonOption.or(JsonOption.READ_SETTER) diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/settings/xml/ApplicationSettings.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/settings/xml/ApplicationSettings.kt index cc6cdf29f..edef372d3 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/settings/xml/ApplicationSettings.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/settings/xml/ApplicationSettings.kt @@ -22,6 +22,8 @@ interface ApplicationSettingsSupport { var readSetter: Boolean var inferEnable: Boolean var inferMaxDeep: Int + var selectedOnly: Boolean + var yapiServer: String? var yapiTokens: String? var enableUrlTemplating: Boolean @@ -60,6 +62,7 @@ interface ApplicationSettingsSupport { newSetting.readSetter = this.readSetter newSetting.inferEnable = this.inferEnable newSetting.inferMaxDeep = this.inferMaxDeep + newSetting.selectedOnly = this.selectedOnly newSetting.yapiServer = this.yapiServer newSetting.yapiTokens = this.yapiTokens newSetting.enableUrlTemplating = this.enableUrlTemplating @@ -116,6 +119,8 @@ class ApplicationSettings : ApplicationSettingsSupport { override var inferMaxDeep: Int = Settings.DEFAULT_INFER_MAX_DEEP + override var selectedOnly: Boolean = false + //endregion //yapi diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/utils/DefaultFileSaveHelper.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/utils/DefaultFileSaveHelper.kt index 10e60bdf9..e4c9b2e87 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/utils/DefaultFileSaveHelper.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/utils/DefaultFileSaveHelper.kt @@ -9,6 +9,7 @@ import com.itangcent.intellij.context.ActionContext import com.itangcent.intellij.logger.Logger import com.itangcent.intellij.util.FileUtils import com.itangcent.intellij.util.ToolUtils +import com.itangcent.utils.localPath import java.awt.HeadlessException import java.io.File import java.nio.charset.Charset @@ -74,7 +75,7 @@ class DefaultFileSaveHelper : FileSaveHelper { var filePath = "${file.path}${File.separator}$defaultFile" filePath = availablePath(filePath) FileUtils.forceSave(filePath, content.toByteArray(charset)) - onSaveSuccess(filePath) + onSaveSuccess(filePath.localPath()) } catch (e: Exception) { onSaveFailed(e.message) actionContext.runAsync { @@ -84,7 +85,7 @@ class DefaultFileSaveHelper : FileSaveHelper { } else { try { FileUtils.forceSave(file, content.toByteArray(charset)) - onSaveSuccess(file.path) + onSaveSuccess(file.path.localPath()) } catch (e: Exception) { onSaveFailed(e.message) actionContext.runAsync { diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/utils/IdeaFileChooserHelper.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/utils/IdeaFileChooserHelper.kt index ecdfa4f7e..01cd0e504 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/utils/IdeaFileChooserHelper.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/utils/IdeaFileChooserHelper.kt @@ -48,22 +48,24 @@ class IdeaFileChooserHelper private constructor( onSelect: (VirtualFile) -> Unit, onCancel: () -> Unit, ) { + var toSelect: VirtualFile? = null + val lastLocation = PropertiesComponent.getInstance().getValue(getLastImportedLocation()) + if (lastLocation != null) { + toSelect = LocalFileSystem.getInstance().refreshAndFindFileByPath(lastLocation) + } actionContext.runInSwingUI { val chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, project, null) - var toSelect: VirtualFile? = null - val lastLocation = PropertiesComponent.getInstance().getValue(getLastImportedLocation()) - if (lastLocation != null) { - toSelect = LocalFileSystem.getInstance().refreshAndFindFileByPath(lastLocation) - } val files = chooser.choose(project, toSelect) if (files.isNotEmpty()) { - actionContext.runInWriteUI { - val file = files[0] - PropertiesComponent.getInstance().setValue(getLastImportedLocation(), file.path) + val file = files[0] + PropertiesComponent.getInstance().setValue(getLastImportedLocation(), file.path) + actionContext.runAsync { onSelect(file) } } else { - onCancel() + actionContext.runAsync { + onCancel() + } } } } diff --git a/idea-plugin/src/main/kotlin/com/itangcent/intellij/extend/ActionContextKit.kt b/idea-plugin/src/main/kotlin/com/itangcent/intellij/extend/ActionContextKit.kt index a49cc9744..d47e53a6e 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/intellij/extend/ActionContextKit.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/intellij/extend/ActionContextKit.kt @@ -1,11 +1,19 @@ package com.itangcent.intellij.extend +import com.intellij.openapi.actionSystem.CommonDataKeys +import com.intellij.openapi.actionSystem.DataContext +import com.intellij.psi.PsiClass +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiMethod +import com.intellij.psi.util.PsiTreeUtil import com.itangcent.common.concurrent.ValueHolder import com.itangcent.common.logger.traceError import com.itangcent.common.utils.TimeSpanUtils +import com.itangcent.common.utils.cast import com.itangcent.intellij.context.ActionContext import com.itangcent.intellij.context.ThreadFlag import com.itangcent.intellij.logger.Logger +import com.itangcent.intellij.util.ActionUtils import java.util.concurrent.TimeUnit import java.util.concurrent.TimeoutException import java.util.concurrent.atomic.AtomicInteger @@ -96,6 +104,7 @@ fun ActionContext.runWithContext(action: () -> Unit) { action() } } + fun ActionContext.runInNormalThread(action: () -> Unit) { val flag = ActionContext.getFlag() if (flag == ThreadFlag.ASYNC.value) { @@ -103,4 +112,10 @@ fun ActionContext.runInNormalThread(action: () -> Unit) { } else { this.runAsync(action) } -} \ No newline at end of file +} + +fun ActionContext.findCurrentMethod(): PsiMethod? { + return this.cacheOrCompute("_currentMethod") { + ActionUtils.findCurrentMethod() + } +} diff --git a/idea-plugin/src/main/kotlin/com/itangcent/utils/FileKit.kt b/idea-plugin/src/main/kotlin/com/itangcent/utils/FileKit.kt new file mode 100644 index 000000000..f96bc41a9 --- /dev/null +++ b/idea-plugin/src/main/kotlin/com/itangcent/utils/FileKit.kt @@ -0,0 +1,10 @@ +package com.itangcent.utils + +import java.io.File + +fun String.localPath(): String { + if (File.separatorChar != '/') { + return this.replace('/', File.separatorChar) + } + return this +} \ No newline at end of file diff --git a/plugin-script/test.sh b/plugin-script/test.sh new file mode 100644 index 000000000..696b4abc8 --- /dev/null +++ b/plugin-script/test.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +# + +SOURCE="$0" +while [[ -h "$SOURCE" ]]; do # resolve $SOURCE until the file is no longer a symlink + scriptDir="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ ${SOURCE} != /* ]] && SOURCE="$scriptDir/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +scriptDir="$( cd -P "$( dirname "$SOURCE" )" && pwd )" +basedir=${scriptDir%/*} +echo "baseDir:"${basedir} + +cd ${basedir} + +./gradlew clean test --stacktrace