diff --git a/CHANGELOG.md b/CHANGELOG.md index 239174cc..66361bbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,18 +2,33 @@ ## Unreleased -## [4.4.0] - 2024-05-25 +## [4.7.0] - 2024-07-03 -- Fix the problem of stuck idea or Android studio -- 修复as或者idea卡死的问题 +- Reconstructed the `json to freezed class code gen` tool, +- Optimize the repair logic of `package` new version detection +- Removed some third-party dependencies and reduced the plug-in package to 1M +- If you encounter problems during use, please submit an issue +- This is the last updated version below `2023.*`. If you want to receive subsequent updates, please update your idea to + version `2024.*` and `above`. -## [4.3.1] - 2024-05-24 +## [4.6.0] - 2024-06-18 -- Optimize dart package version replacement logic -- Fix the bug that modifying the file pubspec.yaml may cause unresponsiveness +- After optimizing the terminal running logic, windows will no longer be created repeatedly. +- Add `part of libarary` autocomplete command +- Optimize the automatic completion popup timing of **_freezed from json_** +- Fix the problem that **_@Freezed_** does not display the freezed function + +## [4.5.2] - 2024-05-30 -## [4.2.5] - 2024-05-23 +- Optimize dart file inlay detection performance +- Optimize some known bugs +## [4.5.0] - 2024-05-25 + +- Fix the problem of stuck idea or Android studio +- Upgrade kotlin version to `2.0.0` to `support k2 compiler` +- Optimize dart package version replacement logic +- Fix the bug that modifying the file pubspec.yaml may cause unresponsiveness - Fix the problem of `flutter upgrade` and `flutter pub run build_runner build` command execution failure(idea **241+**) - New terminal adapted to `IDEA 2024.1+` - Fix some operation error reports. Slow operations are prohibited on EDT. See diff --git a/build.gradle.kts b/build.gradle.kts index 2e18aec8..22419ec8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,5 @@ import org.jetbrains.changelog.Changelog +import org.jetbrains.intellij.tasks.RunPluginVerifierTask import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.dsl.KotlinVersion @@ -11,16 +12,15 @@ val pluginVersion: String by project val type: String by project plugins { - id("org.jetbrains.kotlin.jvm") version "2.0.0" - id("org.jetbrains.intellij") version "1.16.1" - idea + kotlin("jvm") version "2.0.0" + id("org.jetbrains.intellij") version "1.17.4" id("org.jetbrains.changelog") version "2.2.0" } + group = "shop.itbug" version = pluginVersion + type repositories { - mavenLocal() mavenCentral() google() maven { url = uri("https://maven.pkg.jetbrains.space/public/p/compose/dev") } @@ -38,6 +38,7 @@ val pluginList = mutableListOf( ) + intellij { version.set(ideaVersion) if (ideaType.trim().isNotBlank()) { @@ -45,6 +46,7 @@ intellij { } plugins.set(pluginList) } + kotlin { sourceSets.all { languageSettings { @@ -54,10 +56,7 @@ kotlin { } dependencies { - implementation("cn.hutool:hutool-http:latest.release") implementation("org.smartboot.socket:aio-pro:latest.release") - implementation("com.alibaba.fastjson2:fastjson2:latest.release") - testImplementation(kotlin("test")) } val pushToken: String? = System.getenv("idea_push_token") @@ -121,12 +120,7 @@ tasks { } configurations.all { - } - verifyPlugin { - } - - verifyPluginConfiguration { } } @@ -137,3 +131,7 @@ changelog { path = file("CHANGELOG.md").canonicalPath groups.empty() } + +tasks.withType(RunPluginVerifierTask::class.java) { + ideVersions.set(listOf("2024.1.3", "2024.1.2")) +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 7d32e5d5..a3cb318c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,8 +1,5 @@ -kotlin.stdlib.default.dependency=true -kotlin.incremental.useClasspathSnapshot=false -#kotlin.experimental.tryK2=true -kapt.use.k2=true -pluginVersion=4.4.0. +kotlin.stdlib.default.dependency=false +pluginVersion=4.7.0. #===============================> 231 #dartVersion=231.9411 #sinceBuildVersion=231 @@ -32,9 +29,14 @@ pluginVersion=4.4.0. #ideaType= #type=241 #========================================242 idea -dartVersion=242.10180.28 +dartVersion=242.19533.43 sinceBuildVersion=242 untilBuildVersion=242.* ideaVersion=242-EAP-SNAPSHOT ideaType= -type=242 \ No newline at end of file +type=242 +# proxy +systemProp.http.proxyHost=127.0.0.1 +systemProp.http.proxyPort=7890 +systemProp.https.proxyHost=127.0.0.1 +systemProp.https.proxyPort=7890 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 943f0cbf..d64cd491 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ed2bbdfb..a4413138 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=file\:///Users/ldd/gradle/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 65dcd68d..1aa94a42 100755 --- a/gradlew +++ b/gradlew @@ -83,10 +83,8 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,10 +131,13 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. @@ -144,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -152,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -197,11 +198,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/ApiCopyAll.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/ApiCopyAll.kt index b24f44d7..5c170634 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/ApiCopyAll.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/ApiCopyAll.kt @@ -1,17 +1,15 @@ package shop.itbug.fluttercheckversionx.actions -import com.alibaba.fastjson2.JSON -import com.alibaba.fastjson2.JSONWriter +import com.google.gson.Gson import com.intellij.openapi.actionSystem.ActionUpdateThread import com.intellij.openapi.actionSystem.AnActionEvent import shop.itbug.fluttercheckversionx.common.MyAction import shop.itbug.fluttercheckversionx.document.copyTextToClipboard -class ApiCopyAll:MyAction({"Copy All"}) { +class ApiCopyAll : MyAction({ "Copy All" }) { override fun actionPerformed(e: AnActionEvent) { - val api = e.api()!! val dataMap = mutableMapOf( "url" to api.url, @@ -20,28 +18,28 @@ class ApiCopyAll:MyAction({"Copy All"}) { ) api.queryParams?.apply { - if(this.isNotEmpty()){ + if (this.isNotEmpty()) { dataMap["queryParams"] = this } } api.body?.apply { - if(this is Map<*, *> && this.isNotEmpty()){ + if (this is Map<*, *> && this.isNotEmpty()) { dataMap["body"] = this } } dataMap["responseStatusCode"] = api.statusCode - dataMap["response"] = api.getDataJson() + dataMap["response"] = api.getDataJson() dataMap["requestTime"] = api.createDate dataMap["timestamp"] = api.timestamp - val toJSONString = JSON.toJSONString(dataMap, JSONWriter.Feature.PrettyFormat) - toJSONString.copyTextToClipboard() + val string = Gson().toJson(dataMap) + string.copyTextToClipboard() } override fun update(e: AnActionEvent) { - e.presentation.isEnabled = e.api()!=null + e.presentation.isEnabled = e.api() != null super.update(e) } diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/ApiCopyPathAction.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/ApiCopyPathAction.kt index 15865dad..d1aa50c2 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/ApiCopyPathAction.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/ApiCopyPathAction.kt @@ -1,18 +1,18 @@ package shop.itbug.fluttercheckversionx.actions -import cn.hutool.core.util.URLUtil import com.intellij.openapi.actionSystem.ActionUpdateThread import com.intellij.openapi.actionSystem.AnActionEvent import shop.itbug.fluttercheckversionx.common.MyAction import shop.itbug.fluttercheckversionx.document.copyTextToClipboard import shop.itbug.fluttercheckversionx.util.toast +import java.net.URL ///复制路径 -class ApiCopyPathAction: MyAction({"Copy Path"}) { +class ApiCopyPathAction : MyAction({ "Copy Path" }) { override fun actionPerformed(e: AnActionEvent) { val url = e.api()!!.url - val path = URLUtil.getPath(url) + val path = URL(url).path path.copyTextToClipboard().apply { e.project?.toast("Copy succeeded!") @@ -20,7 +20,7 @@ class ApiCopyPathAction: MyAction({"Copy Path"}) { } override fun update(e: AnActionEvent) { - e.presentation.isEnabled = e.api()!=null + e.presentation.isEnabled = e.api() != null super.update(e) } diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/DartFileGroupAction.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/DartFileGroupAction.kt index 2a55cb7f..9a51a240 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/DartFileGroupAction.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/DartFileGroupAction.kt @@ -12,8 +12,8 @@ import com.intellij.ui.components.fields.ExtendableTextComponent import com.intellij.ui.components.fields.ExtendableTextField import com.intellij.util.ui.FormBuilder import com.jetbrains.lang.dart.DartFileType -import icons.DartIcons import shop.itbug.fluttercheckversionx.common.MyDumbAwareAction +import shop.itbug.fluttercheckversionx.icons.MyIcons import java.awt.event.KeyAdapter import java.awt.event.KeyEvent import javax.swing.BorderFactory @@ -30,12 +30,12 @@ class DartFileGroupAction : MyDumbAwareAction() { private lateinit var project: Project private lateinit var virtualFile: VirtualFile private val popup = JBPopupFactory.getInstance().createComponentPopupBuilder(showForm, null) - .setRequestFocus(true) - .setTitle("文件名") - .setCancelKeyEnabled(true) - .setResizable(true) - .setMovable(true) - .createPopup() + .setRequestFocus(true) + .setTitle("文件名") + .setCancelKeyEnabled(true) + .setResizable(true) + .setMovable(true) + .createPopup() init { fileNameTextFiled.border = BorderFactory.createEmptyBorder() @@ -111,7 +111,7 @@ class DartFileGroupAction : MyDumbAwareAction() { ///图标 class TextfiledExtends : ExtendableTextComponent.Extension { override fun getIcon(hovered: Boolean): Icon { - return DartIcons.Dart_file + return MyIcons.dartPackageIcon } override fun isIconBeforeText(): Boolean { diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/DioWindowAnActionEx.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/DioWindowAnActionEx.kt index 7b1c21cf..0786d346 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/DioWindowAnActionEx.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/DioWindowAnActionEx.kt @@ -1,20 +1,24 @@ package shop.itbug.fluttercheckversionx.actions -import com.alibaba.fastjson2.JSON +import com.google.gson.Gson import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.components.service import shop.itbug.fluttercheckversionx.form.socket.Request import shop.itbug.fluttercheckversionx.socket.service.AppService -fun Request.getDataJson() : Any { - if(data is Map<*, *>) { +fun Request.getDataJson(): Any { + if (data is Map<*, *>) { return data } - if(data is String && JSON.isValid(data)) { - return JSON.parse(data) + if (data is String) { + return try { + Gson().fromJson(data, Map::class.java) + } catch (e: Exception) { + data + } } - return data ?: "" + return data } ///获取当前选中的项目 diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/JsonToFreezedModelAction.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/JsonToFreezedModelAction.kt index b5c5f079..f5914328 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/JsonToFreezedModelAction.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/JsonToFreezedModelAction.kt @@ -1,7 +1,8 @@ package shop.itbug.fluttercheckversionx.actions -import com.alibaba.fastjson2.JSONObject import com.intellij.openapi.actionSystem.AnActionEvent +import groovy.json.JsonException +import kotlinx.serialization.json.Json import shop.itbug.fluttercheckversionx.common.MyDumbAwareAction import shop.itbug.fluttercheckversionx.common.jsonToFreezedRun import shop.itbug.fluttercheckversionx.i18n.PluginBundle @@ -11,18 +12,26 @@ class JsonToFreezedModelAction(private val text: String) : MyDumbAwareAction() { override fun actionPerformed(e: AnActionEvent) { jsonToFreezedModel(e) } + private fun jsonToFreezedModel(event: AnActionEvent) { val text = text.trim() if (text.isEmpty()) { event.project?.toastWithError(PluginBundle.get("input.your.json")) return } - try { - JSONObject.parseObject(text) - } catch (e: Exception) { + if (!isValidJson(text)) { event.project?.toastWithError(PluginBundle.get("json.format.verification.failed")) return } event.project?.jsonToFreezedRun(text) } +} + +fun isValidJson(jsonString: String): Boolean { + return try { + Json.parseToJsonElement(jsonString) + true + } catch (e: JsonException) { + false + } } \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/bar/SearchPubPluginAction.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/bar/SearchPubPluginAction.kt index e15b4dd9..3bdca22c 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/bar/SearchPubPluginAction.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/bar/SearchPubPluginAction.kt @@ -32,7 +32,7 @@ class SearchPubPluginAction : AnAction() { // run builder class FlutterRunBuilderCommandAction : AnAction() { override fun actionPerformed(e: AnActionEvent) { - e.project?.let { RunUtil.runCommand(it, "FlutterX", "flutter pub run build_runner build") } + e.project?.let { RunUtil.runCommand(it, "FlutterX run build", "flutter pub run build_runner build") } } override fun getActionUpdateThread(): ActionUpdateThread { diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/riverpod/PsiElementEditorPopupMenulnay.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/riverpod/PsiElementEditorPopupMenulnay.kt index 424e3da9..0bdc49bb 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/riverpod/PsiElementEditorPopupMenulnay.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/riverpod/PsiElementEditorPopupMenulnay.kt @@ -4,12 +4,12 @@ import com.intellij.icons.AllIcons import com.intellij.ide.DataManager import com.intellij.openapi.actionSystem.ActionManager import com.intellij.openapi.actionSystem.DefaultActionGroup +import com.intellij.openapi.editor.Editor import com.intellij.openapi.ui.popup.JBPopupFactory import com.intellij.psi.PsiElement import com.intellij.refactoring.suggested.startOffset import com.intellij.ui.awt.RelativePoint import com.jetbrains.lang.dart.psi.impl.DartClassDefinitionImpl -import kotlinx.coroutines.runBlocking import shop.itbug.fluttercheckversionx.config.PluginSetting import shop.itbug.fluttercheckversionx.constance.MyKeys import shop.itbug.fluttercheckversionx.inlay.HintsInlayPresentationFactory @@ -22,8 +22,8 @@ import java.awt.event.MouseEvent class PsiElementEditorPopupMenuInlay : MyBaseInlay("WidgetCovertToRiverpod") { - override fun needHandle(element: PsiElement, setting: PluginSetting): Boolean { - val config: List = runBlocking { MyPsiElementUtil.getAllPlugins(element.project) } + override fun needHandle(element: PsiElement, setting: PluginSetting, editor: Editor): Boolean { + val config: List = MyPsiElementUtil.getAllPlugins(element.project) return setting.showRiverpodInlay && element is DartClassDefinitionImpl && config.contains("hooks_riverpod") && (element.superclass?.type?.text == "StatelessWidget" || element.superclass?.type?.text == "StatefulWidget") } diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/run/FlutterXRunHotRefresh.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/run/FlutterXRunHotRefresh.kt new file mode 100644 index 00000000..ba2f18c8 --- /dev/null +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/actions/run/FlutterXRunHotRefresh.kt @@ -0,0 +1,10 @@ +package shop.itbug.fluttercheckversionx.actions.run + +import com.intellij.openapi.actionSystem.AnAction +import com.intellij.openapi.actionSystem.AnActionEvent + +class FlutterXRunHotRefresh : AnAction() { + override fun actionPerformed(e: AnActionEvent) { + println("hot refresh") + } +} diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/autoCompletion/DartPartAutoCompletion.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/autoCompletion/DartPartAutoCompletion.kt index b57ae8f1..418bf3d9 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/autoCompletion/DartPartAutoCompletion.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/autoCompletion/DartPartAutoCompletion.kt @@ -1,85 +1,58 @@ package shop.itbug.fluttercheckversionx.autoCompletion import com.intellij.codeInsight.completion.* +import com.intellij.codeInsight.lookup.LookupElement import com.intellij.codeInsight.lookup.LookupElementBuilder -import com.intellij.openapi.module.Module import com.intellij.openapi.project.Project -import com.intellij.openapi.roots.ProjectRootManager -import com.intellij.openapi.vfs.VirtualFile import com.intellij.patterns.PlatformPatterns -import com.intellij.psi.PsiManager -import com.intellij.psi.search.FileTypeIndex -import com.intellij.psi.search.GlobalSearchScope -import com.intellij.psi.util.PsiTreeUtil import com.intellij.util.ProcessingContext -import com.jetbrains.lang.dart.DartFileType import com.jetbrains.lang.dart.DartLanguage -import com.jetbrains.lang.dart.psi.impl.DartLibraryStatementImpl +import com.jetbrains.lang.dart.psi.DartFile import shop.itbug.fluttercheckversionx.icons.MyIcons +import shop.itbug.fluttercheckversionx.services.UserDartLibService import shop.itbug.fluttercheckversionx.util.MyDartPsiElementUtil /** * part lib自动完成提供者 + * 举例: part of dev; */ class DartPartAutoCompletion : CompletionContributor() { - init { - extend(CompletionType.BASIC, - PlatformPatterns.psiElement().withLanguage(DartLanguage.INSTANCE), - object : CompletionProvider() { - override fun addCompletions( - p0: CompletionParameters, - p1: ProcessingContext, - p2: CompletionResultSet - ) { - val project = p0.editor.project!! - val files = FileTypeIndex.getFiles( - DartFileType.INSTANCE, - OnlyProjectFileSearch(project) - ) - files.forEach { file -> - val findFile = PsiManager.getInstance(project).findFile(file)!! - val findChildrenOfAnyType = - PsiTreeUtil.findChildrenOfAnyType(findFile, DartLibraryStatementImpl::class.java) - findChildrenOfAnyType.forEach { lib -> - val ele = - LookupElementBuilder.create("part of ${lib.libraryNameElement?.text ?: ""}").withIcon( - MyIcons.flutter - ).withPsiElement( - MyDartPsiElementUtil.createDartPart( - "part of ${lib.libraryNameElement?.text}", - project - ) - ) - p2.addElement(ele) - } - } - - } - } + init { + extend( + CompletionType.BASIC, + PlatformPatterns.psiElement().withLanguage(DartLanguage.INSTANCE).withSuperParent(6, DartFile::class.java) + .withText(PlatformPatterns.string().startsWith("par")), + Provider() ) } -} - -class OnlyProjectFileSearch(private val myProject: Project) : GlobalSearchScope(myProject) { - - private val fileIndexs = ProjectRootManager.getInstance(myProject).fileIndex - - override fun contains(p0: VirtualFile): Boolean { - val psiFile = PsiManager.getInstance(myProject).findFile(p0) - return fileIndexs.isInSourceContent(p0) && PsiTreeUtil.findChildrenOfAnyType( - psiFile, - DartLibraryStatementImpl::class.java - ).isNotEmpty() + private inner class Provider : CompletionProvider() { + override fun addCompletions( + parameters: CompletionParameters, + context: ProcessingContext, + result: CompletionResultSet + ) { + val project = parameters.editor.project!! + val libNames = UserDartLibService.getInstance(project).getLibraryNames() + libNames.forEach { + val psi = createElement(it, project) + result.addElement(psi) + } + } + + private fun createElement(name: String, project: Project): LookupElement { + return LookupElementBuilder.create("part of $name").withIcon( + MyIcons.flutter + ).withPsiElement( + MyDartPsiElementUtil.createDartPart( + "part of $name", + project + ) + ) + } } - override fun isSearchInModuleContent(p0: Module): Boolean { - return false - } - override fun isSearchInLibraries(): Boolean { - return false - } +} -} \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/common/AnyExtend.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/common/AnyExtend.kt index 7435cb65..7b0e122f 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/common/AnyExtend.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/common/AnyExtend.kt @@ -1,13 +1,11 @@ package shop.itbug.fluttercheckversionx.common -import com.alibaba.fastjson2.JSONObject import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.LocalFileSystem import com.intellij.openapi.vfs.VirtualFile import com.intellij.ui.components.JBScrollPane -import shop.itbug.fluttercheckversionx.dialog.FreezedClassesGenerateDialog -import shop.itbug.fluttercheckversionx.dialog.getParseJsonObject -import shop.itbug.fluttercheckversionx.services.impl.ModelToFreezedModelServiceImpl +import kotlinx.serialization.json.JsonElement +import shop.itbug.fluttercheckversionx.dialog.freezed.StringToFreezedDialog import shop.itbug.fluttercheckversionx.util.toastWithError import javax.swing.JComponent @@ -25,18 +23,20 @@ fun String.getVirtualFile(): VirtualFile? { ///json转 freezed 通用函数 fun Project.jsonToFreezedRun(jsonText: String) { - val jsonObject = jsonText.getParseJsonObject() - jsonObject?.let { - jsonToFreezedRun2(it) - } + StringToFreezedDialog(this, jsonText).show() +// val jsonObject = jsonText.getParseJsonObject() +// jsonObject?.let { +// jsonToFreezedRun2(it) +// } } -private fun Project.jsonToFreezedRun2(jsonObject: JSONObject) { +private fun Project.jsonToFreezedRun2(jsonObject: JsonElement) { try { - val jsonObjectToFreezedCovertModelList = - ModelToFreezedModelServiceImpl().jsonObjectToFreezedCovertModelList(jsonObject) - FreezedClassesGenerateDialog(this, jsonObjectToFreezedCovertModelList).show() + +// val jsonObjectToFreezedCovertModelList = +// ModelToFreezedModelServiceImpl().jsonObjectToFreezedCovertModelList(jsonObject) +// FreezedClassesGenerateDialog(this, jsonObjectToFreezedCovertModelList).show() } catch (e: Exception) { println("json to freezed error:$e") toastWithError("$e") diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/common/MyDialogWrapper.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/common/MyDialogWrapper.kt index 814035d2..751af765 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/common/MyDialogWrapper.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/common/MyDialogWrapper.kt @@ -1,22 +1,10 @@ package shop.itbug.fluttercheckversionx.common -import cn.hutool.core.swing.ScreenUtil import com.intellij.openapi.project.Project import com.intellij.openapi.ui.DialogWrapper -abstract class MyDialogWrapper(open val project: Project): DialogWrapper(project) { - - constructor(project: Project,title:String):this(project){ - super.setTitle(title) - } - - - fun setBaseSize() { - setSize(width - 200, height-200) - setLocation(100,100) +abstract class MyDialogWrapper(open val project: Project) : DialogWrapper(project) { + init { + super.init() } - - - val width: Int get() = ScreenUtil.getWidth() - val height: Int get() = ScreenUtil.getHeight() } \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/config/DoxListingUiConfig.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/config/DoxListingUiConfig.kt index 5ac8d0ff..519860f1 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/config/DoxListingUiConfig.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/config/DoxListingUiConfig.kt @@ -47,7 +47,10 @@ data class DoxListeningSetting( var showProjectName: Boolean = true, ///项目启动时是否检测flutter新版本 - var checkFlutterVersion: Boolean = true + var checkFlutterVersion: Boolean = true, + + ///显示数据大小 + var showDataSize: Boolean = true ) diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/config/JsonToFreezedSetting.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/config/JsonToFreezedSetting.kt index b8050bea..6d2cae44 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/config/JsonToFreezedSetting.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/config/JsonToFreezedSetting.kt @@ -36,11 +36,10 @@ class JsonToFreezedSettingModelConfig : PersistentStateComponent() + private var service: AppService = AppService.getInstance() private var status: StateMachineEnum? = service.dioServerStatus private var threadIsAlive = false - init { super.init() title = "Dio Listen to server status" @@ -61,7 +60,7 @@ class DioListenServerStateDialog(val project: Project) : DialogWrapper(project) button("检测") { checkDioThread() } - label(if(threadIsAlive) "活跃状态" else "已关闭") + label(if (threadIsAlive) "活跃状态" else "已关闭") } } diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/dialog/FreezedClassesGenerateDialog.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/dialog/FreezedClassesGenerateDialog.kt index 849f4657..54f4f371 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/dialog/FreezedClassesGenerateDialog.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/dialog/FreezedClassesGenerateDialog.kt @@ -1,6 +1,5 @@ package shop.itbug.fluttercheckversionx.dialog -import cn.hutool.core.swing.ScreenUtil import com.intellij.openapi.application.runWriteAction import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory import com.intellij.openapi.fileEditor.FileEditorManager @@ -27,7 +26,6 @@ import shop.itbug.fluttercheckversionx.util.RunUtil import shop.itbug.fluttercheckversionx.util.toast import shop.itbug.fluttercheckversionx.util.toastWithError import shop.itbug.fluttercheckversionx.widget.FreezedCovertModelWidget -import java.awt.Dimension import javax.swing.BorderFactory import javax.swing.JComponent import javax.swing.SwingUtilities @@ -193,8 +191,4 @@ class FreezedClassesGenerateDialog( return sb.toString() } - - override fun getPreferredSize(): Dimension { - return ScreenUtil.dimension - } } diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/dialog/JsonToFreezedInputDialog.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/dialog/JsonToFreezedInputDialog.kt index b5ccef1e..5ba63158 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/dialog/JsonToFreezedInputDialog.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/dialog/JsonToFreezedInputDialog.kt @@ -1,15 +1,13 @@ package shop.itbug.fluttercheckversionx.dialog -import com.alibaba.fastjson2.JSON -import com.alibaba.fastjson2.JSONObject import com.intellij.openapi.project.Project import com.intellij.openapi.ui.DialogWrapper import com.intellij.openapi.ui.ValidationInfo import com.intellij.ui.components.JBScrollPane +import kotlinx.serialization.json.Json import shop.itbug.fluttercheckversionx.common.jsonToFreezedRun import shop.itbug.fluttercheckversionx.i18n.PluginBundle import shop.itbug.fluttercheckversionx.tools.emptyBorder -import shop.itbug.fluttercheckversionx.util.findPropertiesMaxLenObject import shop.itbug.fluttercheckversionx.widget.JsonEditorTextPanel import javax.swing.JComponent @@ -54,36 +52,14 @@ class JsonToFreezedInputDialog(val project: Project) : DialogWrapper(project) { } -/** - * 获取可以转换的 json object - */ -fun String.getParseJsonObject(): JSONObject? { - if (this.validParseToFreezed()) { - val isArr = JSON.isValidArray(this) - if (isArr) { - val parseArray = JSON.parseArray(this) - val json = parseArray.findPropertiesMaxLenObject() //属性最多的那一个对象 - return json - } else { - val isJson = JSON.isValidObject(this) - if (isJson) { - return JSONObject.parse(this) - } - } - - } - return null -} - - /** * 判断是否可以转换为 freezed */ fun String.validParseToFreezed(): Boolean { - var isJson = JSON.isValidObject(this) - if (isJson) { - return true + return try { + Json.parseToJsonElement(this) + true + } catch (e: Exception) { + false } - isJson = JSON.isValidArray(this) - return isJson } \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/dialog/SearchDialog.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/dialog/SearchDialog.kt index 82042b33..47ea213c 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/dialog/SearchDialog.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/dialog/SearchDialog.kt @@ -1,8 +1,10 @@ package shop.itbug.fluttercheckversionx.dialog import PluginVersionModel -import cn.hutool.http.HttpRequest import com.google.gson.Gson +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.progress.ProgressIndicator +import com.intellij.openapi.progress.Task import com.intellij.openapi.project.Project import com.intellij.openapi.ui.ComboBox import com.intellij.openapi.ui.DialogWrapper @@ -10,6 +12,7 @@ import com.intellij.ui.components.JBLabel import com.intellij.ui.components.JBList import com.intellij.ui.components.JBScrollPane import com.intellij.ui.components.JBTextField +import com.intellij.util.io.HttpRequests import com.intellij.util.ui.components.BorderLayoutPanel import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.GlobalScope @@ -21,6 +24,7 @@ import java.awt.Component import java.awt.Dimension import java.awt.event.KeyAdapter import java.awt.event.KeyEvent +import java.util.concurrent.Callable import javax.swing.* import javax.swing.event.ListSelectionEvent import javax.swing.event.ListSelectionListener @@ -43,7 +47,7 @@ class SearchDialog(val project: Project) : DialogWrapper(project) { private var selectLabel: JLabel = JLabel() - private var versionSelect: VersionSelect = VersionSelect() + private var versionSelect: VersionSelect = VersionSelect(project) private var bottomPanel = Box.createHorizontalBox() private val resultList = SearchListResultShow { myOKAction.isEnabled = false @@ -158,8 +162,10 @@ class MySearchField(val handle: SearchResultHandle) : JPanel() { searchButton.text = "${PluginBundle.get("search")}..." val keyWorlds = searchTextField.text try { - val response = HttpRequest.get("https://pub.dartlang.org/api/search?q=${keyWorlds}").execute() - val result = Gson().fromJson(response.body(), PubSearchResult::class.java) + val url = "https://pub.dartlang.org/api/search?q=${keyWorlds}" + val future = ApplicationManager.getApplication() + .executeOnPooledThread(Callable { HttpRequests.request(url).readString() }) + val result = Gson().fromJson(future.get(), PubSearchResult::class.java) handle(result) } catch (_: Exception) { } @@ -217,7 +223,7 @@ class ReultItemRender : ListCellRenderer { } -class VersionSelect : ComboBox() { +class VersionSelect(val project: Project) : ComboBox() { init { isEnabled = false @@ -225,14 +231,28 @@ class VersionSelect : ComboBox() { } fun doRequest(pluginName: String) { - model = VersionSelectModel(emptyList()) try { - val response = HttpRequest.get("https://pub.dartlang.org/packages/$pluginName.json").execute() - val result = Gson().fromJson(response.body(), PluginVersionModel::class.java) - model = VersionSelectModel(versions = result.versions) - isEnabled = true - model.selectedItem = result.versions.first() + + + val task = object : Task.Backgroundable(project, PluginBundle.get("get_package_verion_task_title")) { + override fun run(indicator: ProgressIndicator) { + try { + val response = + HttpRequests.request("https://pub.dartlang.org/packages/$pluginName.json") + .readString(indicator) + val result = Gson().fromJson(response, PluginVersionModel::class.java) + model = VersionSelectModel(versions = result.versions) + isEnabled = true + model.selectedItem = result.versions.first() + } catch (e: Exception) { + e.printStackTrace() + } + } + } + task.queue() + + } catch (e: Exception) { println("搜索失败") } @@ -244,7 +264,7 @@ class VersionSelectModel(val versions: List) : DefaultComboBoxModel = MyJsonParseTool.parseJson(jsonString).filterIsInstance() + .mapIndexed { index, t -> t.copy(index = index) } + private val tabs = JBTabbedPane() + private val panels = objects.map { RustEditorPanel(project, it, disposable) } + private val generateConfig = FreezedClassConfigStateService.getInstance(project).state + private val alarm = Alarm(disposable) + private lateinit var settingPanel: DialogPanel + private lateinit var filenameField: Cell + private lateinit var dirField: Cell + + init { + super.init() + title = "FlutterX Freezed Code Generate Tool" + panels.forEach { + tabs.add(it.dartClass.className, it) + } + SwingUtilities.invokeLater { + listenChange() + } + } + + private fun listenChange() { + alarm.addRequest({ + println(settingPanel.isModified()) + if (settingPanel.isModified()) { + settingPanel.apply() + FreezedClassConfigStateService.getInstance(project).loadState(generateConfig) + panels.forEach { it.changeText(generateConfig) } + } + listenChange() + }, 1000) + } + + override fun createCenterPanel(): JComponent { + settingPanel = panel { + row { + panel { + group(PluginBundle.get("freezed.gen.group.title") + ":") { + row { + checkBox(PluginBundle.get("freezed.gen.group.add.structure.fun")).bindSelected( + generateConfig::addStructureFunction + ) + } + row { + checkBox(PluginBundle.get("freezed.gen.group.add.fromjson.fun") + "(FromJson)").bindSelected( + generateConfig::addFromJsonFunction + ) + } + row { + checkBox(PluginBundle.get("freezed.gen.base.set.default.value")).bindSelected(generateConfig.propsConfig::setDefaultValue) + } + } + }.gap(RightGap.COLUMNS).align(AlignY.TOP).resizableColumn() + panel { + group(PluginBundle.get("save.to.directory")) { + row(PluginBundle.get("g.2")) { + filenameField = textField().align(Align.FILL).bindText(generateConfig::saveFileName) + filenameField.addValidationRule(VerifyFileDir.ENTER_YOU_FILE_NAME) { + it.text.trim().isBlank() + } + filenameField.validationOnInput { + println("text:${it.text}") + if (it.text.trim().isBlank()) { + return@validationOnInput error(VerifyFileDir.ENTER_YOU_FILE_NAME) + } + return@validationOnInput null + } + } + row(PluginBundle.get("g.3")) { + dirField = textFieldWithBrowseButton( + "Select Dir", project, FileChooserDescriptorFactory.createSingleFolderDescriptor() + ) { it.path }.bindText(generateConfig::saveDirectory).align(Align.FILL) + .addValidationRule(VerifyFileDir.ERROR_MSG) { + VerifyFileDir.validDirByComponent(it) + } + dirField.validationOnInput { + if (VerifyFileDir.validDirByComponent(dirField.component)) { + return@validationOnInput ValidationInfoBuilder(it.textField).error(VerifyFileDir.ERROR_MSG) + } + return@validationOnInput null + } + } + row { + checkBox("${PluginBundle.get("automatic.operation.command")} flutter pub run build_runner build").bindSelected( + generateConfig::runBuildCommand + ) + } + row { + checkBox(PluginBundle.get("freezed.gen.base.open.in.editor")).bindSelected(generateConfig::openInEditor) + } + } + }.align(AlignY.TOP).resizableColumn() + } + + collapsibleGroup(PluginBundle.get("freezed.gen.base.opt")) { + buttonsGroup(PluginBundle.get("freezed.gen.formatname.classname") + ":") { + row { + NameFormat.values().forEach { + radioButton(it.title, it) + contextHelp(it.example, PluginBundle.get("freezed.gen.formatname.example")) + } + } + }.bind(generateConfig::classNameFormat) + buttonsGroup(PluginBundle.get("freezed.gen.formatname.properties") + ":") { + row { + NameFormat.values().forEach { + radioButton(it.title, it) + contextHelp(it.example, PluginBundle.get("freezed.gen.formatname.example")) + } + } + }.bind(generateConfig::propertyNameFormat) + buttonsGroup("fromJson ${PluginBundle.get("freezed.gen.formatname.fromjson.type")}:") { + row { + FormJsonType.values().forEach { + radioButton(it.value, it) + } + } + }.bind(generateConfig::formJsonType) + } + + collapsibleGroup("Hive ${PluginBundle.get("freezed.gen.base.setting")}") { + row { + checkBox("Enable").bindSelected(generateConfig.hiveSetting::enable) + intTextField().bindIntText(generateConfig.hiveSetting::hiveId).label("HiveType id") + } + } + } + settingPanel.registerValidators(disposable) + return BorderLayoutPanel().addToCenter(tabs).addToBottom(settingPanel) + } + + override fun doValidate(): ValidationInfo? { + val d = VerifyFileDir.validDirByPath(generateConfig.saveDirectory) + if (d) { + return ValidationInfoBuilder(dirField.component).error(VerifyFileDir.ERROR_MSG) + } + return super.doValidate() + } + + override fun doOKAction() { + settingPanel.apply() + doCreateFile { super.doOKAction() } + } + + ///创建文件并添加 + private fun doCreateFile(onSuccess: () -> Unit) { + val sb = StringBuilder() + val fileName = generateConfig.saveFileName + val dirPath = generateConfig.saveDirectory + sb.appendLine("import 'package:freezed_annotation/freezed_annotation.dart';") + sb.appendLine("part '$fileName.freezed.dart';") + if (generateConfig.addFromJsonFunction) { + sb.appendLine("part '$fileName.g.dart';") + } + panels.forEach { + sb.appendLine("") + sb.appendLine(it.getObjectClassText()) + sb.appendLine() + } + val dirVirtualFile = VirtualFileManager.getInstance().findFileByNioPath(Path(dirPath)) + if (dirVirtualFile != null) { + val findDirectory = PsiManager.getInstance(project).findDirectory(dirVirtualFile) + if (findDirectory != null) { + val createDartFile = PsiFileFactory.getInstance(project) + .createFileFromText("$fileName.dart", DartFileType.INSTANCE, sb.toString()) + try { + val psiElement = ApplicationManager.getApplication() + .runWriteAction(Computable { findDirectory.add(createDartFile) }) + if (generateConfig.openInEditor) { + FileEditorManager.getInstance(project).openFile(psiElement.containingFile.virtualFile) + } + if (generateConfig.runBuildCommand) { + RunUtil.runFlutterBuildCommand(project) + } + onSuccess.invoke() + } catch (e: Exception) { + showErrorMessage("${PluginBundle.get("freezed.gen.create.error")}:${e.localizedMessage}") + } + } + } + } + + private fun showErrorMessage(msg: String) { + val groupId = "json_to_freezed_tooltip" + NotificationGroupManager.getInstance().getNotificationGroup(groupId) + .createNotification(msg, NotificationType.ERROR).notify(project) + } +} + + +private class RustEditorPanel(val project: Project, val dartClass: MyChildObject, val parentDispose: Disposable) : + BorderLayoutPanel() { + private val rustEditor = DartEditorTextPanel(project, dartClass.getFreezedClass()) + private val newDispose = Disposer.newDisposable().apply { Disposer.register(parentDispose, this) } + private val alarm = Alarm(newDispose) + var globalConfig = FreezedClassConfig() + var config = FreezedPropertiesConfig() + private val settingPanel = panel { + row("Class Name") { + textField().bindText(dartClass::className) + } + } + + init { + addToCenter(rustEditor) + addToBottom(settingPanel) + SwingUtilities.invokeLater { + listenChange() + } + } + + private fun listenChange() { + if (project.isDisposed || isDisplayable) { + return + } + alarm.addRequest({ + if (settingPanel.isModified()) { + settingPanel.apply() + globalConfig = globalConfig.copy(propsConfig = config) + changeText(globalConfig) + } + listenChange() + }, 1000) + } + + fun changeText(config: FreezedClassConfig) { + globalConfig = config + rustEditor.text = dartClass.getFreezedClass(config) + } + + fun getObjectClassText() = rustEditor.text + + +} \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/document/YamlDocument.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/document/YamlDocument.kt index 8f6a19f5..1113f679 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/document/YamlDocument.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/document/YamlDocument.kt @@ -2,16 +2,17 @@ package shop.itbug.fluttercheckversionx.document import com.intellij.lang.documentation.DocumentationMarkup import com.intellij.lang.documentation.DocumentationProvider +import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.editor.Editor import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile import com.intellij.psi.impl.source.tree.LeafPsiElement -import kotlinx.coroutines.runBlocking import org.jetbrains.yaml.psi.impl.YAMLKeyValueImpl import shop.itbug.fluttercheckversionx.document.Helper.Companion.addKeyValueSection import shop.itbug.fluttercheckversionx.model.PubVersionDataModel import shop.itbug.fluttercheckversionx.services.PubService import shop.itbug.fluttercheckversionx.util.isDartPluginElement +import java.util.concurrent.Callable /** @@ -26,7 +27,7 @@ class YamlDocument : DocumentationProvider { element?.let { - val isPluginElement = runBlocking { element.isDartPluginElement() } + val isPluginElement = element.isDartPluginElement() originalElement?.let { var pluginName = "" @@ -38,15 +39,22 @@ class YamlDocument : DocumentationProvider { pluginName = element.text } if (pluginName.isNotEmpty()) { - val detail: PubVersionDataModel? = PubService.callPluginDetails(pluginName) - if (detail != null) { - return renderFullDoc( - pluginName = detail.name, - lastVersion = detail.latest.version, - githubUrl = detail.latest.pubspec.homepage, - desc = detail.latest.pubspec.description, - lastUpdate = detail.latest.published - ) + + val future = ApplicationManager.getApplication() + .executeOnPooledThread(Callable { PubService.callPluginDetails(pluginName) }) + try { + val detail: PubVersionDataModel? = future.get() + if (detail != null) { + return renderFullDoc( + pluginName = detail.name, + lastVersion = detail.latest.version, + githubUrl = detail.latest.pubspec.homepage, + desc = detail.latest.pubspec.description, + lastUpdate = detail.latest.published + ) + } + } catch (e: Exception) { + e.printStackTrace() } } @@ -65,7 +73,7 @@ class YamlDocument : DocumentationProvider { targetOffset: Int ): PsiElement? { if (contextElement != null) { - val isDartPluginElement = runBlocking { contextElement.isDartPluginElement() } + val isDartPluginElement = contextElement.isDartPluginElement() if (isDartPluginElement) { return contextElement } diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/dsl/RequestDetailPanel.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/dsl/RequestDetailPanel.kt index 9d0846dd..8ae4cd4c 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/dsl/RequestDetailPanel.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/dsl/RequestDetailPanel.kt @@ -1,7 +1,6 @@ package shop.itbug.fluttercheckversionx.dsl -import com.alibaba.fastjson2.JSONObject -import com.alibaba.fastjson2.JSONWriter +import com.google.gson.Gson import com.intellij.json.JsonLanguage import com.intellij.openapi.project.Project import com.intellij.openapi.ui.DialogPanel @@ -21,14 +20,14 @@ fun requestDetailPanel(request: Request, project: Project): DialogPanel { val p = panel { row("Url") { - label(request.url?: "") + label(request.url ?: "") } row("Method") { - label(request.method ?:"") + label(request.method ?: "") } row("Time") { label("${request.timestamp}ms").apply { - if (request.timestamp!=null && request.timestamp!! > 2000) { + if (request.timestamp > 2000) { component.foreground = JBColor.ORANGE } else { component.foreground = UIUtil.getLabelInfoForeground() @@ -49,7 +48,7 @@ fun requestDetailPanel(request: Request, project: Project): DialogPanel { LanguageTextField( JsonLanguage.INSTANCE, project, - JSONObject.toJSONString(request.headers, JSONWriter.Feature.PrettyFormat), + Gson().toJson(request.headers), false ).apply { border = BorderFactory.createEmptyBorder() @@ -65,7 +64,7 @@ fun requestDetailPanel(request: Request, project: Project): DialogPanel { LanguageTextField( JsonLanguage.INSTANCE, project, - JSONObject.toJSONString(request.responseHeaders, JSONWriter.Feature.PrettyFormat), + Gson().toJson(request.responseHeaders), false ).apply { border = BorderFactory.createEmptyBorder() diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/dsl/RequestItemLayout.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/dsl/RequestItemLayout.kt index 7680db8b..0abdf49c 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/dsl/RequestItemLayout.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/dsl/RequestItemLayout.kt @@ -30,14 +30,14 @@ fun removePortFromUrl(url: String): String { //获取 URL 显示 fun Request.formatUrl(setting: DoxListeningSetting): String { - val uri = URI(url ?: "") + val uri = URI(url) var host = uri.host ?: "" val scheme = uri.scheme + "://" if (host.isEmpty()) { - host = extractIpAddressFromUrl(url ?: "") + host = extractIpAddressFromUrl(url) } val param = uri.rawQuery - var string = this.url ?: "" + var string = this.url if (setting.showHost.not()) { string = string.replace(host, "").replace(scheme, "") if (string.startsWith(":${uri.port}")) { @@ -88,7 +88,7 @@ fun requestDetailLayout(request: Request, isSelected: Boolean): DialogPanel { // isOpaque = true } // (在紧凑模式下有效,状态码) - label("${request.statusCode ?: -1}").visible(setting.uiStyle == DioRequestUIStyle.CompactStyle && setting.showStatusCode).component.apply { + label("${request.statusCode}").visible(setting.uiStyle == DioRequestUIStyle.CompactStyle && setting.showStatusCode).component.apply { font = JBFont.medium() foreground = if (request.statusCode == 200) UIUtil.getLabelSuccessForeground() else UIUtil.getErrorForeground() @@ -109,26 +109,35 @@ fun requestDetailLayout(request: Request, isSelected: Boolean): DialogPanel { } } - //其他一些次要的 (在紧凑模式下显示) - label(request.timestamp!!.toString() + "ms").visible(setting.showTimestamp && setting.uiStyle == DioRequestUIStyle.CompactStyle).component.apply { + label(request.calculateSize()).visible(setting.uiStyle == DioRequestUIStyle.CompactStyle && setting.showDataSize).component.apply { font = JBFont.small() foreground = color } - label(request.createDate).visible(setting.showDate && setting.uiStyle == DioRequestUIStyle.CompactStyle).component.apply { + + label(request.timestamp.toString() + "ms").visible(setting.showTimestamp && setting.uiStyle == DioRequestUIStyle.CompactStyle).component.apply { font = JBFont.small() foreground = color } - label( - request.projectName - ).visible(setting.uiStyle == DioRequestUIStyle.CompactStyle && setting.showProjectName).component.apply { - font = JBFont.small() - foreground = color + request.createDate.let { + label(it).visible(setting.showDate && setting.uiStyle == DioRequestUIStyle.CompactStyle).component.apply { + font = JBFont.small() + foreground = color + } + } + request.projectName.let { + label( + it + ).visible(setting.uiStyle == DioRequestUIStyle.CompactStyle && setting.showProjectName).component.apply { + font = JBFont.small() + foreground = color + } } + } //如果是紧凑模式,这些数据就不要显示了 if (setting.uiStyle == DioRequestUIStyle.DefaultStyle) row { - label(request.statusCode!!.toString()).visible(setting.showStatusCode).component.apply { + label(request.statusCode.toString()).visible(setting.showStatusCode).component.apply { font = JBFont.small() foreground = if (request.statusCode == 200) UIUtil.getLabelInfoForeground() else UIUtil.getErrorForeground() @@ -137,19 +146,28 @@ fun requestDetailLayout(request: Request, isSelected: Boolean): DialogPanel { font = JBFont.small() foreground = color } - label(request.timestamp!!.toString() + "ms").visible(setting.showTimestamp).component.apply { + label(request.calculateSize()).visible(setting.showDataSize).component.apply { font = JBFont.small() foreground = color } - label(request.createDate).visible(setting.showDate).component.apply { + label(request.timestamp.toString() + "ms").visible(setting.showTimestamp).component.apply { font = JBFont.small() foreground = color } - label(request.projectName).visible(setting.showProjectName).component.apply { - font = JBFont.small() - foreground = color + request.createDate.let { + label(it).visible(setting.showDate).component.apply { + font = JBFont.small() + foreground = color + } } - }.visible(setting.showStatusCode || setting.showMethod || setting.showTimestamp || setting.showDate || setting.showProjectName) + request.projectName.let { + label(it).visible(setting.showProjectName).component.apply { + font = JBFont.small() + foreground = color + } + } + + }.visible(setting.showStatusCode || setting.showMethod || setting.showTimestamp || setting.showDate || setting.showProjectName || setting.showDataSize) } p.background = if (isSelected) UIUtil.getListBackground(true, false) else UIUtil.getPanelBackground() return p.withBorder(BorderFactory.createEmptyBorder(0, 12, 0, 12)) diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/dsl/SettingPanel.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/dsl/SettingPanel.kt index 59ec42fb..c01de3c1 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/dsl/SettingPanel.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/dsl/SettingPanel.kt @@ -1,7 +1,6 @@ package shop.itbug.fluttercheckversionx.dsl import com.intellij.openapi.Disposable -import com.intellij.openapi.project.ProjectManager import com.intellij.openapi.ui.DialogPanel import com.intellij.openapi.util.Disposer import com.intellij.ui.dsl.builder.* @@ -9,7 +8,6 @@ import com.intellij.util.Alarm import shop.itbug.fluttercheckversionx.config.DoxListeningSetting import shop.itbug.fluttercheckversionx.i18n.PluginBundle import shop.itbug.fluttercheckversionx.services.AppStateModel -import shop.itbug.fluttercheckversionx.util.MyNotificationUtil import javax.swing.SwingUtilities /** @@ -72,6 +70,9 @@ fun settingPanel( twoColumnsRow({ checkBox(PluginBundle.get("bold.link")).bindSelected(dioxSetting::urlBold) }, {}) + row { + checkBox(PluginBundle.get("dio.setting.show.data.size")).bindSelected(dioxSetting::showDataSize) + } } } diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/form/actions/ProjectFilter.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/form/actions/ProjectFilter.kt index 1f44ebc2..1dca134d 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/form/actions/ProjectFilter.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/form/actions/ProjectFilter.kt @@ -26,7 +26,7 @@ class ProjectFilter : MyComboActionNew.ComboBoxSettingAction() { override val availableOptions: MutableList - get() = appService.flutterProjects.keys.toMutableList() + get() = appService.flutterProjects.keys.filterNotNull().toMutableList() /// diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/form/components/ApiListPanel.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/form/components/ApiListPanel.kt index 815f3d9c..8184455d 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/form/components/ApiListPanel.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/form/components/ApiListPanel.kt @@ -1,6 +1,6 @@ package shop.itbug.fluttercheckversionx.form.components -import com.alibaba.fastjson2.JSONObject +import com.google.gson.Gson import com.intellij.ide.BrowserUtil import com.intellij.ide.DataManager import com.intellij.openapi.actionSystem.ActionGroup @@ -124,7 +124,7 @@ class ApiListPanel(val project: Project) : JBList(), ListSelectionListe */ private fun doSearch(keyword: String) { val allRequest = appService.getAllRequest() - val results = allRequest.filter { it.url?.uppercase()?.contains(keyword.uppercase()) ?: false } + val results = allRequest.filter { it.url.uppercase().contains(keyword.uppercase()) } if (results.isNotEmpty()) { listModel().apply { clear() @@ -215,8 +215,9 @@ class ApiListPanel(val project: Project) : JBList(), ListSelectionListe override fun handleModel(model: ProjectSocketService.SocketResponseModel) { + println("处理模型:${model.url}") try { - MyLoggerEvent.fire(MyLogInfo(message = JSONObject.toJSONString(model), key = LogKeys.dioLog)) + MyLoggerEvent.fire(MyLogInfo(message = Gson().toJson(model), key = LogKeys.dioLog)) } catch (_: Exception) { } changeApisModel(appService.getCurrentProjectAllRequest().toMutableList()) diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/form/components/ChangeDioRequestItemUi.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/form/components/ChangeDioRequestItemUi.kt index 13d8e973..da5fda9d 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/form/components/ChangeDioRequestItemUi.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/form/components/ChangeDioRequestItemUi.kt @@ -1,12 +1,12 @@ package shop.itbug.fluttercheckversionx.form.components -import shop.itbug.fluttercheckversionx.config.DioRequestUIStyle import shop.itbug.fluttercheckversionx.config.DioListingUiConfig +import shop.itbug.fluttercheckversionx.config.DioRequestUIStyle import shop.itbug.fluttercheckversionx.widget.MyComboActionNew ///切换dio请求ui样式 -class ChangeDioRequestItemUi() : - MyComboActionNew.ToggleActionGroup(DioRequestUIStyle.entries.toTypedArray()) { +class ChangeDioRequestItemUi : + MyComboActionNew.ToggleActionGroup(DioRequestUIStyle.values()) { var setting = DioListingUiConfig.setting override var value: DioRequestUIStyle diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/form/components/DioUiSettingsMenu.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/form/components/DioUiSettingsMenu.kt index 608cd43c..ef435455 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/form/components/DioUiSettingsMenu.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/form/components/DioUiSettingsMenu.kt @@ -15,14 +15,16 @@ enum class DioUiSettingMenu(val title: String) { Status(PluginBundle.get("display.status.code")), Time(PluginBundle.get("display.time")), RequestTime(PluginBundle.get("time")), - ProjectName(PluginBundle.get("dio.setting.project.name.show.option")) + ProjectName(PluginBundle.get("dio.setting.project.name.show.option")), + DataSize(PluginBundle.get("dio.setting.show.data.size")) + } internal class DioUIShowActionGroup : DumbAware, ActionGroup() { override fun getChildren(e: AnActionEvent?): Array { val actions = ArrayList() - actions.addAll(DioUiSettingMenu.entries.map { DioUiRenderOption(it) }) + actions.addAll(DioUiSettingMenu.values().map { DioUiRenderOption(it) }) return actions.toTypedArray() } } @@ -40,6 +42,7 @@ private class DioUiRenderOption(val menu: DioUiSettingMenu) : DumbAwareToggleAct DioUiSettingMenu.Time -> setting.showTimestamp DioUiSettingMenu.RequestTime -> setting.showDate DioUiSettingMenu.ProjectName -> setting.showProjectName + DioUiSettingMenu.DataSize -> setting.showDataSize } } @@ -52,6 +55,7 @@ private class DioUiRenderOption(val menu: DioUiSettingMenu) : DumbAwareToggleAct DioUiSettingMenu.Time -> DioListingUiConfig.changeSetting { it.copy(showTimestamp = state) } DioUiSettingMenu.RequestTime -> DioListingUiConfig.changeSetting { it.copy(showDate = state) } DioUiSettingMenu.ProjectName -> DioListingUiConfig.changeSetting { it.copy(showProjectName = state) } + DioUiSettingMenu.DataSize -> DioListingUiConfig.changeSetting { it.copy(showDataSize = state) } } } diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/form/socket/SocketRequestForm.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/form/socket/SocketRequestForm.kt index 7df1270e..ea8e26c3 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/form/socket/SocketRequestForm.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/form/socket/SocketRequestForm.kt @@ -1,7 +1,6 @@ package shop.itbug.fluttercheckversionx.form.socket -import com.alibaba.fastjson2.JSON -import com.alibaba.fastjson2.JSONObject +import com.google.gson.Gson import com.intellij.openapi.actionSystem.ActionManager import com.intellij.openapi.actionSystem.DefaultActionGroup import com.intellij.openapi.application.ApplicationManager @@ -13,6 +12,7 @@ import com.intellij.util.ui.JBUI import com.intellij.util.ui.components.BorderLayoutPanel import shop.itbug.fluttercheckversionx.common.scroll import shop.itbug.fluttercheckversionx.config.DioListingUiConfig +import shop.itbug.fluttercheckversionx.dialog.validParseToFreezed import shop.itbug.fluttercheckversionx.form.actions.DioRequestSearch import shop.itbug.fluttercheckversionx.form.components.ApiListPanel import shop.itbug.fluttercheckversionx.form.components.RightDetailPanel @@ -27,7 +27,7 @@ fun SocketResponseModel.isParseToJson(): Boolean { data?.let { when (it) { is String -> { - return JSON.isValid(it) + return it.validParseToFreezed() } is Map<*, *> -> { @@ -48,8 +48,8 @@ fun SocketResponseModel.getDataString(): String { data?.let { return when (it) { is String -> it - is Map<*, *> -> JSONObject.toJSONString(it) - is List<*> -> JSONObject.toJSONString(it) + is Map<*, *> -> Gson().toJson(it) + is List<*> -> Gson().toJson(it) else -> "$it" } } @@ -67,7 +67,6 @@ class SocketRequestForm(val project: Project, private val toolWindow: ToolWindow private val leftPanel = LeftPanel() - //右侧面板 private val rightFirstPanel = RightDetailPanel(project) diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/form/sub/CustomListRender.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/form/sub/CustomListRender.kt deleted file mode 100644 index 689e0e03..00000000 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/form/sub/CustomListRender.kt +++ /dev/null @@ -1,73 +0,0 @@ -package shop.itbug.fluttercheckversionx.form.sub - -import com.intellij.openapi.project.Project -import com.intellij.util.ui.UIUtil -import shop.itbug.fluttercheckversionx.socket.ProjectSocketService -import java.awt.Dimension -import javax.swing.Box -import javax.swing.BoxLayout -import javax.swing.JLabel -import javax.swing.JPanel - -///jlist自定义渲染 -class CustomListRender(private val model: ProjectSocketService.SocketResponseModel, val project: Project) : JPanel(){ - - - init { - initComponentUi() - } - - private fun initComponentUi(){ - - - val dimension = Dimension() - dimension.height = 100 - - layout = BoxLayout(this,BoxLayout.PAGE_AXIS) - - - add(StringValueRender("Url",model.url?:"")) - add(Box.createVerticalStrut(6)) - add(StringValueRender("Methed",model.method?:"")) - add(Box.createVerticalStrut(6)) - add(StringValueRender("Status Code",model.statusCode.toString())) - if(model.data!=null){ - add(Box.createVerticalStrut(6)) - add(JsonValueRender(project)) - } - add(Box.createVerticalStrut(6)) - add(JsonValueRender(project)) - add(Box.createVerticalStrut(6)) - add(JsonValueRender(project)) - } - - - /** - * 渲染普通类型的值 - */ - class StringValueRender(title: String, value: String): JPanel() { - - init { - - - layout = BoxLayout(this,BoxLayout.PAGE_AXIS) - - val jLabel = JLabel(title) - add(jLabel) - add(Box.createVerticalStrut(6)) - - val valueLabel = JLabel(value) - if(value == "200"){ - valueLabel.foreground = UIUtil.getLabelInfoForeground() - }else if(value == "500"){ - valueLabel.foreground = UIUtil.getErrorForeground() - valueLabel.text = "500 (服务器错误)" - } - add(valueLabel) - - } - - } - - -} \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/form/sub/JsonValueRender.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/form/sub/JsonValueRender.kt index a2936ed2..0dc571f4 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/form/sub/JsonValueRender.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/form/sub/JsonValueRender.kt @@ -1,11 +1,13 @@ package shop.itbug.fluttercheckversionx.form.sub -import com.alibaba.fastjson2.JSON -import com.alibaba.fastjson2.JSONWriter +import com.google.gson.GsonBuilder +import com.google.gson.JsonParser +import com.google.gson.JsonSyntaxException import com.intellij.openapi.command.WriteCommandAction import com.intellij.openapi.project.Project import shop.itbug.fluttercheckversionx.widget.JsonEditorTextPanel + /** * json viewer * @@ -30,25 +32,44 @@ open class JsonValueRender(p: Project) : JsonEditorTextPanel(p) { } } + private fun isValidJson(jsonString: String?): Boolean { + try { + JsonParser.parseString(jsonString) + return true + } catch (e: JsonSyntaxException) { + return false + } + } + /** * 改变显示内容 * * 返回要显示的json string */ private fun changeJson(json: Any): String { - val isJson = if (json is String) JSON.isValid(json) else false - return if (isJson) { - return JSON.toJSONString( - JSON.parseObject(json.toString(), Map::class.java), - JSONWriter.Feature.PrettyFormat - ) - } else { + val builder = GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create() + if (json is String) { try { - JSON.toJSONString(json, JSONWriter.Feature.PrettyFormat) - } catch (_: Exception) { - json.toString() + if (isValidJson(json)) { + val map = builder.fromJson(json, Map::class.java) + return builder.toJson(map) + } + } catch (e: Exception) { + println("尝试String转json失败:${e.localizedMessage} \n String is $json") } } + if (json is Map<*, *>) { + try { + return builder.toJson(json) + } catch (e: Exception) { + e.printStackTrace() + } + } + try { + return builder.toJson(json) + } catch (_: Exception) { + } + return json.toString() } } diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/hints/AssetsFilePathAutoComplate.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/hints/AssetsFilePathAutoComplate.kt index fbe9e8ad..c10527ae 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/hints/AssetsFilePathAutoComplate.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/hints/AssetsFilePathAutoComplate.kt @@ -2,27 +2,45 @@ package shop.itbug.fluttercheckversionx.hints import com.intellij.codeInsight.completion.* import com.intellij.codeInsight.lookup.LookupElementBuilder +import com.intellij.openapi.project.DumbAware +import com.intellij.openapi.project.Project +import com.intellij.openapi.startup.ProjectActivity import com.intellij.patterns.PlatformPatterns -import com.intellij.psi.util.elementType import com.intellij.util.ProcessingContext import com.jetbrains.lang.dart.DartLanguage -import com.jetbrains.lang.dart.DartTokenTypes +import com.jetbrains.lang.dart.psi.impl.DartStringLiteralExpressionImpl import shop.itbug.fluttercheckversionx.icons.MyIcons import shop.itbug.fluttercheckversionx.services.AppStateModel +import shop.itbug.fluttercheckversionx.services.FlutterAssetsService import shop.itbug.fluttercheckversionx.services.PluginStateService -import shop.itbug.fluttercheckversionx.util.MyFileUtil -import shop.itbug.fluttercheckversionx.util.fileNameWith + + +class FlutterAssetsStartHandle : ProjectActivity, DumbAware { + + override suspend fun execute(project: Project) { + if (project.isDisposed) { + return + } + val setting: AppStateModel = PluginStateService.getInstance().state ?: AppStateModel() + FlutterAssetsService.getInstance(project).init(setting.assetScanFolderName) + } +} /** * 资源文件路径自动补全 */ class AssetsFilePathAutoComplete : CompletionContributor() { + private var setting: AppStateModel = PluginStateService.getInstance().state ?: AppStateModel() init { + println(setting) extend( CompletionType.BASIC, - PlatformPatterns.psiElement().withLanguage(DartLanguage.INSTANCE), - AssetsFilePathAutoCompleteProvider() + PlatformPatterns.psiElement() + .withLanguage(DartLanguage.INSTANCE) + .withParents(DartStringLiteralExpressionImpl::class.java) + .withText(PlatformPatterns.string().startsWith(setting.assetCompilationTriggerString)), + AssetsFilePathAutoCompleteProvider(setting) ) } @@ -33,33 +51,19 @@ class AssetsFilePathAutoComplete : CompletionContributor() { /** * 资产文件自动补全 */ -class AssetsFilePathAutoCompleteProvider : CompletionProvider() { - private var setting = PluginStateService.getInstance().state ?: AppStateModel() +class AssetsFilePathAutoCompleteProvider(val setting: AppStateModel) : CompletionProvider() { + override fun addCompletions( parameters: CompletionParameters, context: ProcessingContext, result: CompletionResultSet ) { - val file = parameters.originalFile - file.findElementAt(parameters.offset)?.apply { - if (prevSibling.elementType == DartTokenTypes.REGULAR_STRING_PART) { - val strEle = prevSibling.text - if (strEle.length >= setting.assetCompilationTriggerLen && (strEle.startsWith(setting.assetCompilationTriggerString))) { - doHandle(parameters, result) - } + parameters.editor.project?.let { + FlutterAssetsService.getInstance(it).allAssets().forEach { filePath -> + result.addElement(LookupElementBuilder.create(filePath).withIcon(MyIcons.flutter)) } } } - private fun doHandle(parameters: CompletionParameters, result: CompletionResultSet) { - parameters.editor.project?.apply { - MyFileUtil.onFolderEachWithProject(this, setting.assetScanFolderName) { virtualFile -> - val withIcon = - LookupElementBuilder.create(virtualFile.fileNameWith("assets")).withIcon(MyIcons.diandianLogoIcon) - result.addElement(withIcon) - } - } - } - } diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/hints/FreezedPartAutoComplicate.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/hints/FreezedPartAutoComplicate.kt index 690cdfae..5ef97be7 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/hints/FreezedPartAutoComplicate.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/hints/FreezedPartAutoComplicate.kt @@ -5,10 +5,12 @@ import com.intellij.codeInsight.lookup.LookupElementBuilder import com.intellij.patterns.PlatformPatterns import com.intellij.util.ProcessingContext import com.jetbrains.lang.dart.DartLanguage +import com.jetbrains.lang.dart.psi.DartFile import com.jetbrains.lang.dart.psi.impl.DartClassBodyImpl import com.jetbrains.lang.dart.psi.impl.DartClassDefinitionImpl import groovy.util.logging.Slf4j import shop.itbug.fluttercheckversionx.icons.MyIcons +import shop.itbug.fluttercheckversionx.manager.myManagerFun import shop.itbug.fluttercheckversionx.util.DartPsiElementUtil @Slf4j @@ -17,21 +19,38 @@ class FreezedPartAutoComplicate : CompletionContributor() { init { extend( CompletionType.BASIC, - PlatformPatterns.psiElement().withLanguage(DartLanguage.INSTANCE), + PlatformPatterns.psiElement().withLanguage(DartLanguage.INSTANCE) + .withSuperParent(6, DartFile::class.java), FreezedPartAutoComplicateProvider() ) extend( CompletionType.BASIC, PlatformPatterns.psiElement() - .withSuperParent(7,DartClassBodyImpl::class.java) - .withLanguage(DartLanguage.INSTANCE), + .withLanguage(DartLanguage.INSTANCE).withSuperParent(7, DartClassBodyImpl::class.java) + .withSuperParent(8, DartClassDefinitionImpl::class.java), object : CompletionProvider() { - override fun addCompletions(parameters: CompletionParameters, context: ProcessingContext, result: CompletionResultSet) { - val className = parameters.getDartClassName() - result.withPrefixMatcher("ff").addElement(LookupElementBuilder.create("factory $className.fromJson(Map json) => _\$${className}FromJson(json);").withIcon(MyIcons.diandianLogoIcon)) + override fun addCompletions( + parameters: CompletionParameters, + context: ProcessingContext, + result: CompletionResultSet + ) { + val cls = parameters.getDartClassDefine() + val manager = cls?.myManagerFun() + if (manager?.hasFreezeMetadata() == true) { + val className = cls.getDartClassName() + className?.let { + result.withPrefixMatcher("ff").addElement( + LookupElementBuilder.create("factory $className.fromJson(Map json) => _\$${className}FromJson(json);") + .withIcon(MyIcons.flutter) + ) + + result.withPrefixMatcher("fc") + .addElement(LookupElementBuilder.create("${className}._();").withIcon(MyIcons.flutter)) + } + } + - result.withPrefixMatcher("fc").addElement(LookupElementBuilder.create("${className}._();").withIcon(MyIcons.diandianLogoIcon)) } } @@ -66,9 +85,14 @@ class FreezedPartAutoComplicateProvider : CompletionProvider(), DioApiService.NativeMessageProcessing, Lis } - override fun handleFlutterAppMessage(nativeMessage: String, jsonObject: JSONObject?, aio: AioSession?) { + override fun handleFlutterAppMessage(nativeMessage: String, jsonObject: Map?, aio: AioSession?) { + println("处理Hive盒子消息:$jsonObject") jsonObject?.apply { - val type = getString("type") + val type = this["type"] if (type == "getBoxList") { - val arr = getJSONArray("data").map { it.toString() } - model = ItemModel(arr) + val data = jsonObject["data"] + data?.let { + if (data is ArrayList<*>) { + model = ItemModel(data.map { it.toString() }) + } + } + } } } @@ -115,12 +120,14 @@ class HiveKeysList(private val boxList: JBList) : JBList(), DioA register() } - override fun handleFlutterAppMessage(nativeMessage: String, jsonObject: JSONObject?, aio: AioSession?) { + override fun handleFlutterAppMessage(nativeMessage: String, jsonObject: Map?, aio: AioSession?) { jsonObject?.apply { - val type = getString("type") + val type = jsonObject["type"] if (type == "getKeys") { - val arr = getJSONArray("data").map { it.toString() } - model = ItemModel(arr) + val data = jsonObject["data"] + if (data is ArrayList<*>) { + model = ItemModel(data.map { it.toString() }) + } } } } diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/hive/component/HiveValueComponent.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/hive/component/HiveValueComponent.kt index 0ba796d3..e8af38e9 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/hive/component/HiveValueComponent.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/hive/component/HiveValueComponent.kt @@ -1,6 +1,5 @@ package shop.itbug.fluttercheckversionx.hive.component -import com.alibaba.fastjson2.JSONObject import com.intellij.openapi.project.Project import com.intellij.util.ui.components.BorderLayoutPanel import org.smartboot.socket.transport.AioSession @@ -24,12 +23,11 @@ class HiveValueComponent(project: Project) : BorderLayoutPanel(), DioApiService. jsonEditor.changeValue(value) } - override fun handleFlutterAppMessage(nativeMessage: String, jsonObject: JSONObject?, aio: AioSession?) { + override fun handleFlutterAppMessage(nativeMessage: String, jsonObject: Map?, aio: AioSession?) { + println("处理Hive值:$jsonObject") jsonObject?.apply { - val type = getString("type") - if (type == "getValue" && get("data") != null) { + if (get("data") != null && get("type") == "getValue") { changeJsonValue(get("data")) - } } } diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/i18n/PluginBundle.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/i18n/PluginBundle.kt index 8fcbbb00..5cd5b0c4 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/i18n/PluginBundle.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/i18n/PluginBundle.kt @@ -5,13 +5,13 @@ const val pathToBundleKey = "messages.pluginBundle" /** * 国际化配置 */ -object PluginBundle: DynamicPluginBundle(pathToBundleKey) { +object PluginBundle : DynamicPluginBundle(pathToBundleKey) { - fun get(key: String, vararg params: Any) : String { - return getMessage(key, params) + fun get(key: String, vararg params: Any): String { + return getMessage(key.trim(), params) } } -fun String.i18n() : String { +fun String.i18n(): String { return PluginBundle.get(this) } \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/inlay/DartLibraryInlay.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/inlay/DartLibraryInlay.kt index da1f9bf7..322cf489 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/inlay/DartLibraryInlay.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/inlay/DartLibraryInlay.kt @@ -1,34 +1,36 @@ package shop.itbug.fluttercheckversionx.inlay +import com.intellij.openapi.editor.Editor import com.intellij.psi.PsiElement import com.intellij.refactoring.suggested.startOffset +import com.jetbrains.lang.dart.psi.impl.DartPartOfStatementImpl import shop.itbug.fluttercheckversionx.config.PluginSetting +import shop.itbug.fluttercheckversionx.i18n.PluginBundle import shop.itbug.fluttercheckversionx.inlay.base.MyBaseInlay import shop.itbug.fluttercheckversionx.inlay.base.MyBaseInlayModel -import shop.itbug.fluttercheckversionx.tools.LibTools +import shop.itbug.fluttercheckversionx.services.UserDartLibService class DartLibraryInlay : MyBaseInlay("Dart Library Tips") { - override fun needHandle(element: PsiElement, setting: PluginSetting): Boolean { - return element.text.trim().contains("part of") + + override fun needHandle(element: PsiElement, setting: PluginSetting, editor: Editor): Boolean { + val text = editor.document.getText(element.textRange) + return element is DartPartOfStatementImpl && text.trim() + .startsWith("part of ") && UserDartLibService.getInstance(element.project).getLibraryNames() + .isNotEmpty() } override fun handle(element: PsiElement, myFactory: HintsInlayPresentationFactory, model: MyBaseInlayModel) { - val libs = LibTools.getLibraryFiles(element.project).joinToString( - separator = ",", postfix = "." - ) - model.sink.addBlockElement( - element.startOffset, + val libs = UserDartLibService.getInstance(element.project).getLibraryNames().joinToString() + model.sink.addBlockElement(element.startOffset, relatesToPrecedingText = true, showAbove = true, priority = 1, presentation = myFactory.simpleText( - libs, - null + "${PluginBundle.get("find_the_project_dart_lib_names")}: $libs", null ) { _, _ -> run { } - } - ) + }) } } \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/inlay/HintsInlayPresentationFactory.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/inlay/HintsInlayPresentationFactory.kt index 906f82c3..b0b25e14 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/inlay/HintsInlayPresentationFactory.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/inlay/HintsInlayPresentationFactory.kt @@ -37,6 +37,7 @@ fun Editor.getLineStart(element: PsiElement): Int { /** * 获取缩进长度 + * 或者可以参考@[EditorUtil#getPlainSpaceWidth] */ fun Editor.getIndent(element: PsiElement): Int { val offset = element.textRange.startOffset @@ -156,7 +157,7 @@ class HintsInlayPresentationFactory(private val factory: PresentationFactory) { private fun pluginMenusActionPopup(itemSelected: (key: String) -> Unit): BaseListPopupStep = - MyPluginMenusAvtionPopup(actionMenus, itemSelected) + MyPluginMenusActionPopup(actionMenus, itemSelected) fun getImageWithPath(path: String, basePath: String): InlayPresentation? { @@ -173,7 +174,7 @@ class HintsInlayPresentationFactory(private val factory: PresentationFactory) { } /// 自定义菜单弹窗 - class MyPluginMenusAvtionPopup(private val items: List, private val itemSelected: (key: String) -> Unit) : + class MyPluginMenusActionPopup(private val items: List, private val itemSelected: (key: String) -> Unit) : BaseListPopupStep() { init { diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/inlay/base/MyBaseInlay.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/inlay/base/MyBaseInlay.kt index b5c61c64..31beea76 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/inlay/base/MyBaseInlay.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/inlay/base/MyBaseInlay.kt @@ -40,8 +40,7 @@ abstract class MyBaseInlay(private val inlayName: String) : InlayHintsProvider

{ data class AddPartInlaySetting(var show: Boolean = true) override val key: SettingsKey - get() = SettingsKey("part action inlay") + get() = SettingsKey("Part action inlay") override val name: String - get() = "part action" + get() = "Part action" override val previewText: String get() = """ part of "test.dart" @@ -46,21 +47,25 @@ class AddPartInlay : InlayHintsProvider { override fun collect(element: PsiElement, editor: Editor, sink: InlayHintsSink): Boolean { val myFactory = HintsInlayPresentationFactory(factory) if (element is DartPartOfStatementImpl) { - - val files = element.libraryFiles if (files.isNotEmpty()) { val first = files.first() - val libFilePsi: PsiFile? = PsiManager.getInstance(element.project).findFile(first) + val libFilePsi: PsiFile? = + runReadAction { PsiManager.getInstance(element.project).findFile(first) } if (libFilePsi != null) { val parts = - PsiTreeUtil.findChildrenOfAnyType(libFilePsi, DartPartStatementImpl::class.java) + runReadAction { + PsiTreeUtil.findChildrenOfAnyType( + libFilePsi, + DartPartStatementImpl::class.java + ) + } if (parts.isNotEmpty()) { val lastPart = parts.last() ///最后一个 part val p1 = lastPart.containingFile.virtualFile.path val p2 = element.containingFile.virtualFile.path val rl = getRelativeOrFileName(p1, p2) - val createPartOf = createPartOf("$rl", project = element.project) + val createPartOf = createPartOf(rl, project = element.project) ///如果存在了就不要显示了 val findPart = @@ -70,7 +75,7 @@ class AddPartInlay : InlayHintsProvider { val inlayPresentation = myFactory.simpleText( "FlutterX: inset part \"${rl}\" to library ${element.libraryName}", null - ) { p1, p2 -> + ) { _, _ -> createPartOf?.let { WriteCommandAction.runWriteCommandAction(element.project) { lastPart.addAfter(createPartOf, null) @@ -98,7 +103,7 @@ class AddPartInlay : InlayHintsProvider { override fun createComponent(listener: ChangeListener): JComponent { return panel { row("action") { - checkBox("enable").bindSelected(settings::show) + checkBox("Enable").bindSelected(settings::show) } } } @@ -129,6 +134,6 @@ fun getRelativeOrFileName(path1: String, path2: String): String { return targetPath.fileName.toString() } else { val relativePath = basePath.relativize(targetPath).toString() - return if (relativePath.isNotEmpty()) relativePath else "./${targetPath.fileName}" + return relativePath.ifEmpty { "./${targetPath.fileName}" } } } \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/inlay/freezed/FreezedInlay.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/inlay/freezed/FreezedInlay.kt index 39057f43..f696e06b 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/inlay/freezed/FreezedInlay.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/inlay/freezed/FreezedInlay.kt @@ -11,7 +11,6 @@ import com.intellij.openapi.editor.Editor import com.intellij.openapi.ui.popup.JBPopupFactory import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile -import com.intellij.psi.PsiRecursiveElementVisitor import com.intellij.refactoring.suggested.endOffset import com.intellij.ui.awt.RelativePoint import com.intellij.ui.dsl.builder.panel @@ -23,10 +22,10 @@ import shop.itbug.fluttercheckversionx.dialog.JsonToFreezedInputDialog import shop.itbug.fluttercheckversionx.i18n.PluginBundle import shop.itbug.fluttercheckversionx.inlay.HintsInlayPresentationFactory import shop.itbug.fluttercheckversionx.manager.DartClassManager +import shop.itbug.fluttercheckversionx.manager.myManagerFun import shop.itbug.fluttercheckversionx.util.MyDartPsiElementUtil import shop.itbug.fluttercheckversionx.util.MyPsiElementUtil import shop.itbug.fluttercheckversionx.util.RunUtil -import shop.itbug.fluttercheckversionx.util.dart.DartClassUtil import shop.itbug.fluttercheckversionx.util.toast import shop.itbug.fluttercheckversionx.widget.WidgetUtil import java.awt.event.MouseEvent @@ -66,12 +65,10 @@ class FreezedInlayCollector(val edit: Editor) : FactoryInlayHintsCollector(edit) private val inlayFactory = HintsInlayPresentationFactory(factory) override fun collect(element: PsiElement, editor: Editor, sink: InlayHintsSink): Boolean { - - val isFreezedClass = - DartClassUtil.hasMetadata(element, "freezed") || DartClassUtil.hasMetadata(element, "Freezed") + val isFreezedClass = element is DartClassDefinitionImpl && element.myManagerFun().hasFreezeMetadata() if (isFreezedClass) { val manager = DartClassManager(psiElement = element as DartClassDefinitionImpl) - val freezedElement = manager.findMataDataByText("freezed") ?: manager.findMataDataByText("Freezed") + val freezedElement = manager.findFreezedMetadata() freezedElement?.let { sink.addInlineElement( it.endOffset, @@ -93,8 +90,6 @@ class FreezedInlayCollector(val edit: Editor) : FactoryInlayHintsCollector(edit) //显示操作菜单 private fun showFreezedActionMenu(mouseEvent: MouseEvent, psiElement: PsiElement) { - - val popupCreate = JBPopupFactory.getInstance().createActionGroupPopup( "Freezed Actions", createFreezedActionGroup(psiElement, mouseEvent), DataContext.EMPTY_CONTEXT, JBPopupFactory.ActionSelectionAid.MNEMONICS, true @@ -222,7 +217,7 @@ class FreezedInlayCollector(val edit: Editor) : FactoryInlayHintsCollector(edit) }) add(object : MyAction({ "Run build runner" }) { override fun actionPerformed(e: AnActionEvent) { - RunUtil.runCommand(psiElement.project, "FlutterX", "flutter pub run build_runner build") + RunUtil.runCommand(psiElement.project, "FlutterX run build", "flutter pub run build_runner build") } }) @@ -236,39 +231,4 @@ class FreezedInlayPanel : ImmediateConfigurable { return panel { } } -} - -// -//public void replaceTextInSubElements(PsiElement rootElement, Class targetClass, String oldText, String newText) { -// rootElement.accept(new PsiRecursiveElementWalkingVisitor() { -// @Override -// public void visitElement(PsiElement element) { -// super.visitElement(element); -// -// if (targetClass.isInstance(element) && element.getText().equals(oldText)) { -// element.replace(element.getManager().getElementFactory().createCommentFromText(newText, element)); -// // 或者,如果你想替换整个元素的文本而非注释: -// // element.replace(element.getManager().getElementFactory().createDummyHolder(newText, element.getLanguage())); -// } -// } -// }); -//} - -private fun replaceTextInSubElement( - root: PsiElement, - targetClass: Class, - oldText: String, - newComp: T -) { - - root.accept(object : PsiRecursiveElementVisitor() { - override fun visitElement(element: PsiElement) { - if (targetClass.isInstance(element) && element.text == oldText) { - WriteCommandAction.runWriteCommandAction(root.project) { - element.replace(newComp) - } - } - super.visitElement(element) - } - }) } \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/manager/DartClassManager.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/manager/DartClassManager.kt index 9f7d8f86..ded204e9 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/manager/DartClassManager.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/manager/DartClassManager.kt @@ -20,11 +20,15 @@ import shop.itbug.fluttercheckversionx.util.* typealias IfExistsFun = (element: PsiElement) -> Unit +fun DartClassDefinitionImpl.myManagerFun(): DartClassManager = DartClassManager(this) + /** * 对dart类的一些操作函数 */ class DartClassManager(val className: String, private val psiElement: DartClassDefinitionImpl) { + private val frs = listOf("freezed", "Freezed", "unfreezed") + constructor(psiElement: DartClassDefinitionImpl) : this( className = psiElement.componentName.name ?: "", psiElement = psiElement @@ -107,6 +111,16 @@ class DartClassManager(val className: String, private val psiElement: DartClassD return findTypesByPsiElement().find { it.referenceExpression.text == text } } + fun findFreezedMetadata(): DartMetadataImpl? { + return findTypesByPsiElement().lastOrNull { frs.contains(it.referenceExpression.text) } + } + + fun hasFreezeMetadata(): Boolean { + val eles = findTypesByPsiElement() + val names = eles.map { it.referenceExpression.text } + return names.any { it in frs } + } + /** * 添加part语句 */ diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/manager/DartFactoryConstructorDeclarationImplManager.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/manager/DartFactoryConstructorDeclarationImplManager.kt index e751d355..5820db51 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/manager/DartFactoryConstructorDeclarationImplManager.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/manager/DartFactoryConstructorDeclarationImplManager.kt @@ -374,7 +374,7 @@ class DartDefaultFormalNamedParameterActionManager(val element: DartDefaultForma ///获取 dart 类型 fun getMyDartType(): MyDartType? { - return MyDartType.entries.find { it.dartType == dartType } + return MyDartType.values().find { it.dartType == dartType } } } diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/model/DartClassProperty.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/model/DartClassProperty.kt index 2bd26625..91f41dd7 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/model/DartClassProperty.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/model/DartClassProperty.kt @@ -1,8 +1,8 @@ package shop.itbug.fluttercheckversionx.model -import com.alibaba.fastjson2.JSONArray import com.google.common.base.CaseFormat import com.jetbrains.lang.dart.psi.impl.DartVarDeclarationListImpl +import kotlinx.serialization.json.JsonArray import shop.itbug.fluttercheckversionx.util.DartPsiElementUtil import shop.itbug.fluttercheckversionx.util.formatDartName import java.math.BigDecimal @@ -78,15 +78,13 @@ private fun String.dartNameStandard(): String { private fun String.nomenclatureOfHumps(isEnable: Boolean): String { - - var s = this.replaceFirstChar { it.lowercase() } - if(!isEnable){ + if (!isEnable) { return s } - if(s.contains("_")){ + if (s.contains("_")) { s = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, s) } @@ -94,7 +92,6 @@ private fun String.nomenclatureOfHumps(isEnable: Boolean): String { } - fun DartClassProperty.formatType(useDefaultValue: Boolean, isJson: Boolean = true): String { if (useDefaultValue && isJson) { return type.removeSuffix("?") @@ -106,7 +103,7 @@ fun DartClassProperty.formatType(useDefaultValue: Boolean, isJson: Boolean = tru * 如果为空设置为默认值 */ fun DartClassProperty.getDartDefaultValue(): Any { -// println(">>>$finalPropertyName >> $finalPropertyValue >> ${finalPropertyValue?.javaClass}" ) + println(">>>$finalPropertyName >> $finalPropertyValue >> ${finalPropertyValue?.javaClass}") when (finalPropertyValue) { is String -> { return "\'\'" @@ -128,7 +125,7 @@ fun DartClassProperty.getDartDefaultValue(): Any { return "0.0" } - is JSONArray -> { + is JsonArray -> { return "[]" } diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/model/PubVersionDataModel.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/model/PubVersionDataModel.kt index 34ad430b..cae96b5b 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/model/PubVersionDataModel.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/model/PubVersionDataModel.kt @@ -1,6 +1,6 @@ package shop.itbug.fluttercheckversionx.model -import com.alibaba.fastjson2.annotation.JSONField +import kotlinx.serialization.SerialName import shop.itbug.fluttercheckversionx.util.* @@ -66,7 +66,7 @@ data class PubVersionDataModel( data class Latest( val version: String, val pubspec: Pubspec, - @JSONField(name = "archive_url") val archiveURL: String, + @SerialName("archive_url") val archiveURL: String, val published: String ) @@ -76,7 +76,6 @@ data class Pubspec( val Pubspec.dartPluginModel get() = DartPluginVersionName(name, version) - data class Version( val version: String, val published: String, val pubspec: Pubspec ) diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/model/resource/ResourceCategory.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/model/resource/ResourceCategory.kt index 1c0101c3..e2ffc9af 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/model/resource/ResourceCategory.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/model/resource/ResourceCategory.kt @@ -1,7 +1,5 @@ package shop.itbug.fluttercheckversionx.model.resource -import com.alibaba.fastjson2.JSONObject -import com.intellij.util.xmlb.Converter import java.io.Serializable data class ResourceCategory( @@ -12,15 +10,3 @@ data class ResourceCategory( val name: String, val type: String ) : Serializable - - -class ResourceCategoryCovert : Converter() { - override fun toString(value: ResourceCategory): String? { - return JSONObject.toJSONString(value) - } - - override fun fromString(value: String): ResourceCategory? { - return JSONObject.parseObject(value,ResourceCategory::class.java) - } - -} \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/notif/PubPluginVersionCheckNotification.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/notif/PubPluginVersionCheckNotification.kt index 2deacff0..ecca3621 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/notif/PubPluginVersionCheckNotification.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/notif/PubPluginVersionCheckNotification.kt @@ -16,11 +16,9 @@ import com.jetbrains.lang.dart.DartFileType import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking import shop.itbug.fluttercheckversionx.dialog.SearchDialog import shop.itbug.fluttercheckversionx.i18n.PluginBundle import shop.itbug.fluttercheckversionx.icons.MyIcons -import shop.itbug.fluttercheckversionx.tools.FlutterVersionTool import shop.itbug.fluttercheckversionx.tools.MyToolWindowTools import shop.itbug.fluttercheckversionx.util.MyPsiElementUtil import shop.itbug.fluttercheckversionx.util.getPubspecYAMLFile @@ -36,7 +34,7 @@ class PubPluginVersionCheckNotification : EditorNotificationProvider { ): Function { return Function { - val pub = runBlocking { project.getPubspecYAMLFile() } + val pub = project.getPubspecYAMLFile() pub ?: return@Function null if (file.fileType is DartFileType) { @@ -46,8 +44,6 @@ class PubPluginVersionCheckNotification : EditorNotificationProvider { if (filename != "pubspec.yaml") { return@Function null } - val flutterVersionInfo = runBlocking { FlutterVersionTool.readVersionFromSdkHome(project) } - flutterVersionInfo ?: return@Function null YamlFileNotificationPanel(it, project) } } @@ -118,7 +114,7 @@ class YamlFileNotificationPanel(private val fileEditor: FileEditor, val project: } private fun checkNewVersions() { - val file = runBlocking { project.getPubspecYAMLFile() } + val file = project.getPubspecYAMLFile() file?.containingFile?.let { DaemonCodeAnalyzer.getInstance(project).restart(it) } val component = JBPopupFactory.getInstance() .createComponentPopupBuilder(AllPluginsCheckVersion(project) { diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/run/FlutterXRunConfigOptions.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/run/FlutterXRunConfigOptions.kt new file mode 100644 index 00000000..d8f45f2f --- /dev/null +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/run/FlutterXRunConfigOptions.kt @@ -0,0 +1,6 @@ +package shop.itbug.fluttercheckversionx.run + +import com.intellij.execution.configurations.RunConfigurationOptions + + +data class FlutterXRunConfigOptions(var script: String = "flutter run") : RunConfigurationOptions() \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/run/FlutterXRunConfigType.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/run/FlutterXRunConfigType.kt new file mode 100644 index 00000000..b92b63c1 --- /dev/null +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/run/FlutterXRunConfigType.kt @@ -0,0 +1,16 @@ +package shop.itbug.fluttercheckversionx.run + +import com.intellij.execution.configurations.ConfigurationTypeBase +import shop.itbug.fluttercheckversionx.icons.MyIcons + +class FlutterXRunConfigType : + ConfigurationTypeBase(ID, "Flutter Application (FlutterX Run)", "Run flutter application", MyIcons.flutter) { + + init { + addFactory(FlutterXRunConfigurationFactory(this)) + } + + companion object { + const val ID: String = "FlutterXRunConfiguration" + } +} \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/run/FlutterXRunConfiguration.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/run/FlutterXRunConfiguration.kt new file mode 100644 index 00000000..1be72406 --- /dev/null +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/run/FlutterXRunConfiguration.kt @@ -0,0 +1,43 @@ +package shop.itbug.fluttercheckversionx.run + +import com.intellij.execution.Executor +import com.intellij.execution.configurations.* +import com.intellij.execution.process.ProcessHandler +import com.intellij.execution.process.ProcessHandlerFactory +import com.intellij.execution.process.ProcessTerminatedListener +import com.intellij.execution.runners.ExecutionEnvironment +import com.intellij.openapi.options.SettingsEditor +import com.intellij.openapi.project.Project + +class FlutterXRunConfiguration(project: Project, configurationFactory: ConfigurationFactory, name: String) : + RunConfigurationBase(project, configurationFactory, name) { + + override fun getState(executor: Executor, environment: ExecutionEnvironment): RunProfileState { + return object : CommandLineState(environment) { + override fun startProcess(): ProcessHandler { + val command = GeneralCommandLine(options.script.split(" ")) + command.setWorkDirectory(project.basePath) + val createProcessHandler = ProcessHandlerFactory.getInstance().createProcessHandler(command) + ProcessTerminatedListener.attach(createProcessHandler) + return createProcessHandler + } + } + } + + + override fun getOptions(): FlutterXRunConfigOptions { + return super.getOptions() as FlutterXRunConfigOptions + } + + fun getMyOptions(): FlutterXRunConfigOptions = options + + fun setNewOptions(newOpt: FlutterXRunConfigOptions) { + loadState(newOpt) + } + + override fun getConfigurationEditor(): SettingsEditor { + return FlutterXRunOptionEditor(this) + } + + +} \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/run/FlutterXRunConfigurationFactory.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/run/FlutterXRunConfigurationFactory.kt new file mode 100644 index 00000000..eb5611db --- /dev/null +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/run/FlutterXRunConfigurationFactory.kt @@ -0,0 +1,25 @@ +package shop.itbug.fluttercheckversionx.run + +import com.intellij.execution.configurations.ConfigurationFactory +import com.intellij.execution.configurations.ConfigurationType +import com.intellij.execution.configurations.RunConfiguration +import com.intellij.openapi.components.BaseState +import com.intellij.openapi.project.Project + +class FlutterXRunConfigurationFactory(configurationType: ConfigurationType) : + ConfigurationFactory(configurationType) { + override fun createTemplateConfiguration(project: Project): RunConfiguration { + return FlutterXRunConfiguration(project, this, "FlutterX Run") + } + + + override fun getId(): String { + return FlutterXRunConfigType.ID + } + + + override fun getOptionsClass(): Class { + return FlutterXRunConfigOptions::class.java + } + +} \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/run/FlutterXRunOptionEditor.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/run/FlutterXRunOptionEditor.kt new file mode 100644 index 00000000..0e576f6e --- /dev/null +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/run/FlutterXRunOptionEditor.kt @@ -0,0 +1,33 @@ +package shop.itbug.fluttercheckversionx.run + +import com.intellij.openapi.options.SettingsEditor +import com.intellij.ui.dsl.builder.bindText +import com.intellij.ui.dsl.builder.panel +import javax.swing.JComponent + + +class FlutterXRunOptionEditor(val factory: FlutterXRunConfiguration) : SettingsEditor() { + + val state: FlutterXRunConfigOptions = factory.getMyOptions(); + + private val myPanel = panel { + row("Run Flutter App") { + textField().bindText(state::script) + } + } + + override fun resetEditorFrom(s: FlutterXRunConfiguration) { + s.setNewOptions(s.getMyOptions()) + } + + override fun applyEditorTo(s: FlutterXRunConfiguration) { + myPanel.apply() + s.setNewOptions(state) + } + + override fun createEditor(): JComponent { + return myPanel + } +} + + diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/services/AssetsListeningProjectService.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/services/AssetsListeningProjectService.kt index acfbe9ed..ec267579 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/services/AssetsListeningProjectService.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/services/AssetsListeningProjectService.kt @@ -3,6 +3,7 @@ package shop.itbug.fluttercheckversionx.services import com.intellij.ide.BrowserUtil import com.intellij.notification.NotificationGroupManager import com.intellij.notification.NotificationType +import com.intellij.openapi.Disposable import com.intellij.openapi.actionSystem.ActionUpdateThread import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.components.Service @@ -28,14 +29,11 @@ import shop.itbug.fluttercheckversionx.tools.MyFlutterVersion import shop.itbug.fluttercheckversionx.util.MyDartPsiElementUtil import shop.itbug.fluttercheckversionx.util.RunUtil import shop.itbug.fluttercheckversionx.util.Util -import shop.itbug.fluttercheckversionx.util.projectClosed - class MyAssetGenPostStart : ProjectActivity { override suspend fun execute(project: Project) { AssetsListeningProjectService.getInstance(project).initListening() } - } class MyProjectListening : ProjectManagerListener { @@ -47,35 +45,28 @@ class MyProjectListening : ProjectManagerListener { } @Service(Service.Level.PROJECT) -public final class AssetsListeningProjectService(val project: Project) { - - +class AssetsListeningProjectService(val project: Project) : Disposable { private lateinit var connect: MessageBusConnection - private var checkFlutterVersionTask: CheckFlutterVersionTask = CheckFlutterVersionTask() - companion object { fun getInstance(project: Project): AssetsListeningProjectService { return project.getService(AssetsListeningProjectService::class.java) } } - - ///销毁 - fun dispose() { - project.projectClosed { - if (DioListingUiConfig.setting.checkFlutterVersion) { - checkFlutterVersionTask.onCancel() - } - connect.dispose() + override fun dispose() { + println("generate dispose.....") + checkFlutterVersionTask.onCancel() + if (DioListingUiConfig.setting.checkFlutterVersion) { + checkFlutterVersionTask.onCancel() } + connect.dispose() } ///初始化 fun initListening() { if (DioListingUiConfig.setting.checkFlutterVersion) { - ProgressManager.getInstance().run(checkFlutterVersionTask) } // 通知测试 @@ -93,7 +84,6 @@ public final class AssetsListeningProjectService(val project: Project) { if (project.isDisposed) { return } - val projectPath = project.basePath val setting = GenerateAssetsClassConfig.getGenerateAssetsSetting() if (!setting.autoListenFileChange) { @@ -106,14 +96,10 @@ public final class AssetsListeningProjectService(val project: Project) { } } } - - } - }) } - private fun checkAndAutoGenFile(projectPath: String, file: VirtualFile, project: Project) { var filePath = file.canonicalPath filePath = filePath?.replace("$projectPath/", "") @@ -129,7 +115,6 @@ public final class AssetsListeningProjectService(val project: Project) { override fun run(indicator: ProgressIndicator) { val flutterChannel = Util.getFlutterChannel() val currentFlutterVersion = runBlocking { FlutterVersionTool.readVersionFromSdkHome(project) } - println("flutter channel :$flutterChannel version:$currentFlutterVersion") if (flutterChannel == null) { return } @@ -138,7 +123,6 @@ public final class AssetsListeningProjectService(val project: Project) { version.apply { val hash = version.getCurrentReleaseByChannel(flutterChannel) val release = releases.find { o -> o.hash == hash } - println("找到的版本:$release hash=$hash") release?.let { r -> if (r.version != c.version) { println("has new version") @@ -148,11 +132,11 @@ public final class AssetsListeningProjectService(val project: Project) { } } } - - fun showTestTip(project: Project) { - println("show test tips") - showTip(testRelease, project, MyFlutterVersion("3.22.0"), "stable") - } +// +// fun showTestTip(project: Project) { +// println("show test tips") +// showTip(testRelease, project, MyFlutterVersion("3.22.0"), "stable") +// } /** * 弹出通知 @@ -189,6 +173,16 @@ public final class AssetsListeningProjectService(val project: Project) { }, ) + // --force + createNotification.addAction(object : DumbAwareAction("Flutter upgrade --force") { + override fun actionPerformed(e: AnActionEvent) { + RunUtil.runCommand(project, "flutter upgrade --force", "flutter upgrade --force") + } + + override fun getActionUpdateThread(): ActionUpdateThread { + return ActionUpdateThread.BGT + } + }) ///查看更新日志 createNotification.addAction(object : DumbAwareAction("What's New") { diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/services/DartLibService.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/services/DartLibService.kt new file mode 100644 index 00000000..2c21dcc7 --- /dev/null +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/services/DartLibService.kt @@ -0,0 +1,89 @@ +package shop.itbug.fluttercheckversionx.services + +import com.intellij.openapi.application.runReadAction +import com.intellij.openapi.components.Service +import com.intellij.openapi.components.service +import com.intellij.openapi.module.Module +import com.intellij.openapi.project.DumbAware +import com.intellij.openapi.project.DumbService +import com.intellij.openapi.project.Project +import com.intellij.openapi.roots.ProjectRootManager +import com.intellij.openapi.vfs.LocalFileSystem +import com.intellij.openapi.vfs.VirtualFile +import com.intellij.psi.PsiManager +import com.intellij.psi.search.FileTypeIndex +import com.intellij.psi.search.GlobalSearchScope +import com.intellij.psi.search.GlobalSearchScopes +import com.intellij.psi.util.PsiTreeUtil +import com.jetbrains.lang.dart.DartFileType +import com.jetbrains.lang.dart.psi.impl.DartLibraryStatementImpl + +@Service(Service.Level.PROJECT) +class UserDartLibService(private val project: Project) : DumbAware { + + private var libraryNames: MutableList? = null + + init { + DumbService.getInstance(project).runReadActionInSmartMode { + getLibraryNames() + } + } + + /// get all user define library + fun getLibraryNames(): MutableList { + if (libraryNames.isNullOrEmpty()) { + libraryNames = getLibraryFiles(project) + } + return libraryNames!! + } + + companion object { + fun getInstance(project: Project) = project.service() + } + + + private fun getLibraryFiles(project: Project): MutableList { + val lib: VirtualFile = LocalFileSystem.getInstance().findFileByPath("${project.basePath}/lib") + ?: return mutableListOf() + val files = FileTypeIndex.getFiles(DartFileType.INSTANCE, GlobalSearchScopes.directoryScope(project, lib, true)) + val libraryNames = mutableListOf() + if (files.isNotEmpty()) { + files.forEach { file -> + val findFile = PsiManager.getInstance(project).findFile(file) + val findChildrenOfAnyType = + PsiTreeUtil.findChildrenOfAnyType(findFile, DartLibraryStatementImpl::class.java) + findChildrenOfAnyType.forEach { libPsi -> + libPsi.libraryNameElement?.text?.let { libName -> + if (libName.isNotEmpty()) { + libraryNames.add(libName) + } + } + } + } + } + return libraryNames + } +} + + +class OnlyProjectFileSearch(private val myProject: Project) : GlobalSearchScope(myProject) { + + private val fileIndex = ProjectRootManager.getInstance(myProject).fileIndex + + override fun contains(p0: VirtualFile): Boolean { + val psiFile = runReadAction { PsiManager.getInstance(myProject).findFile(p0) } + println("is in source ${fileIndex.isInSourceContent(p0)}") + return fileIndex.isInSourceContent(p0) && PsiTreeUtil.findChildOfAnyType( + psiFile, DartLibraryStatementImpl::class.java + ) != null + } + + override fun isSearchInModuleContent(p0: Module): Boolean { + return false + } + + override fun isSearchInLibraries(): Boolean { + return false + } + +} \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/services/FlutterAssetsService.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/services/FlutterAssetsService.kt new file mode 100644 index 00000000..ea40287c --- /dev/null +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/services/FlutterAssetsService.kt @@ -0,0 +1,62 @@ +package shop.itbug.fluttercheckversionx.services + +import com.intellij.openapi.components.Service +import com.intellij.openapi.project.Project +import com.intellij.openapi.vfs.InvalidVirtualFileAccessException +import com.intellij.openapi.vfs.LocalFileSystem +import com.intellij.openapi.vfs.VirtualFile + +private typealias HandleVirtualFile = (virtualFile: VirtualFile) -> Unit + + +// assets +@Service(Service.Level.PROJECT) +class FlutterAssetsService(val project: Project) { + + + companion object { + fun getInstance(project: Project): FlutterAssetsService = project.getService(FlutterAssetsService::class.java) + } + + private var assets: MutableList = mutableListOf() + + fun allAssets(): MutableList = assets + + fun init(folderName: String) { + assets.clear() + onFolderEachWithProject(folderName) { + assets.add(it.fileNameWith(folderName)) + } + } + + + private fun onFolderEachWithProject(folderName: String, handle: HandleVirtualFile) { + val path = project.basePath + "/$folderName" + val findFileByPath = LocalFileSystem.getInstance().findFileByPath(path) + findFileByPath?.apply { + virtualFileHandle(this, handle) + } + } + + private fun virtualFileHandle(file: VirtualFile, handle: HandleVirtualFile) { + if (file.isDirectory) { + try { + val cs = file.children.toList() + cs.forEach { f -> + if (f.isDirectory) { + virtualFileHandle(f, handle) + } else { + handle.invoke(f) + } + } + } catch (_: InvalidVirtualFileAccessException) { + } + } + } + + fun VirtualFile.fileNameWith(folderName: String): String { + val indexOf = this.path.indexOf(folderName) + return this.path.substring(indexOf) + } + +} \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/services/FlutterService.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/services/FlutterService.kt index 9e8cac39..1936e2ce 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/services/FlutterService.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/services/FlutterService.kt @@ -1,20 +1,18 @@ package shop.itbug.fluttercheckversionx.services -import cn.hutool.http.HttpUtil -import com.alibaba.fastjson2.JSONObject -import com.alibaba.fastjson2.annotation.JSONField +import com.google.gson.Gson +import com.google.gson.annotations.SerializedName +import com.intellij.util.io.HttpRequests class FlutterVersionCheckException(message: String) : Exception(message) object FlutterService { - - fun getVersion(): FlutterVersions { try { val url = " https://storage.googleapis.com/flutter_infra_release/releases/releases_macos.json" - val get: String = HttpUtil.get(url) - return JSONObject.parseObject(get, FlutterVersions::class.java) + val get: String = HttpRequests.request(url).readString() + return Gson().fromJson(get, FlutterVersions::class.java) } catch (e: Exception) { e.printStackTrace() throw FlutterVersionCheckException("Failed to detect new version of flutter:${e.localizedMessage}") @@ -35,19 +33,19 @@ fun FlutterVersions.getCurrentReleaseByChannel(channel: String): String? { } data class FlutterVersions( - @JSONField(name = "base_url") - val baseURL: String, + @SerializedName("base_url") + var baseURL: String, - @JSONField(name = "current_release") - val currentRelease: CurrentRelease, + @SerializedName("current_release") + var currentRelease: CurrentRelease, - val releases: List + var releases: List ) data class CurrentRelease( - val beta: String, - val dev: String, - val stable: String + var beta: String, + var dev: String, + var stable: String ) val testRelease = Release( @@ -55,14 +53,14 @@ val testRelease = Release( ) data class Release( - val hash: String, - val version: String, - @JSONField(name = "dart_sdk_version") - val dartSDKVersion: String? = null, - @JSONField(name = "release_date") - val releaseDate: String, - val archive: String, - val sha256: String + var hash: String, + var version: String, + @SerializedName("dart_sdk_version") + var dartSDKVersion: String? = null, + @SerializedName("release_date") + var releaseDate: String, + var archive: String, + var sha256: String ) diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/services/ModelToFreezedModelService.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/services/ModelToFreezedModelService.kt index 7b3b4948..941ee5c7 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/services/ModelToFreezedModelService.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/services/ModelToFreezedModelService.kt @@ -1,14 +1,24 @@ package shop.itbug.fluttercheckversionx.services -import com.alibaba.fastjson2.JSONObject import com.intellij.openapi.actionSystem.AnActionEvent import com.jetbrains.lang.dart.psi.impl.DartClassDefinitionImpl +import kotlinx.serialization.json.JsonElement import shop.itbug.fluttercheckversionx.model.FreezedCovertModel + const val DEFAULT_CLASS_NAME = "Root" + interface ModelToFreezedModelService { - fun psiElementToFreezedCovertModel(classPsiElement: DartClassDefinitionImpl) : FreezedCovertModel - fun anActionEventToFreezedCovertModel(event: AnActionEvent) : FreezedCovertModel - fun jsonObjectToFreezedCovertModelList(jsonObject: JSONObject,oldList: MutableList = mutableListOf(),className: String=DEFAULT_CLASS_NAME) : MutableList - fun jsonObjectToFreezedCovertModel(jsonObject: JSONObject,className: String = DEFAULT_CLASS_NAME) : FreezedCovertModel + fun psiElementToFreezedCovertModel(classPsiElement: DartClassDefinitionImpl): FreezedCovertModel + fun anActionEventToFreezedCovertModel(event: AnActionEvent): FreezedCovertModel + fun jsonObjectToFreezedCovertModelList( + jsonObject: JsonElement, + oldList: MutableList = mutableListOf(), + className: String = DEFAULT_CLASS_NAME + ): MutableList + + fun jsonObjectToFreezedCovertModel( + jsonObject: JsonElement, + className: String = DEFAULT_CLASS_NAME + ): FreezedCovertModel } \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/services/PubService.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/services/PubService.kt index ac32f8a1..ec566c7b 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/services/PubService.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/services/PubService.kt @@ -1,8 +1,8 @@ package shop.itbug.fluttercheckversionx.services import PluginVersionModel -import cn.hutool.http.HttpUtil -import com.alibaba.fastjson2.JSONObject +import com.google.gson.Gson +import com.intellij.util.io.HttpRequests import shop.itbug.fluttercheckversionx.model.PubSearchResult import shop.itbug.fluttercheckversionx.model.PubVersionDataModel @@ -20,10 +20,10 @@ object PubService { fun callPluginDetails(plugName: String): PubVersionDataModel? { val url = "https://pub.dartlang.org/api/packages/$plugName" try { - val resposne = HttpUtil.get(url, 2000) - return JSONObject.parseObject(resposne, PubVersionDataModel::class.java) + val resposne = HttpRequests.request(url).readString() + return Gson().fromJson(resposne, PubVersionDataModel::class.java) } catch (e: Exception) { - println("获取插件信息失败${plugName}:${e.message} url:$url") + println("获取插件信息失败${plugName} url:$url ${e.localizedMessage}") return null } } @@ -34,8 +34,8 @@ object PubService { fun getPackageVersions(pluginName: String): PluginVersionModel? { val url = "https://pub.dartlang.org/packages/$pluginName.json" try { - val resposne = HttpUtil.get(url) - return JSONObject.parseObject(resposne, PluginVersionModel::class.java) + val resposne = HttpRequests.request(url).readString() + return Gson().fromJson(resposne, PluginVersionModel::class.java) } catch (e: Exception) { return null } @@ -47,8 +47,8 @@ object PubService { fun search(pluginName: String): PubSearchResult? { val url = "https://pub.dartlang.org/api/search?q=$pluginName" try { - val resposne = HttpUtil.get(url) - return JSONObject.parseObject(resposne, PubSearchResult::class.java) + val resposne = HttpRequests.request(url).readString() + return Gson().fromJson(resposne, PubSearchResult::class.java) } catch (e: Exception) { return null } diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/services/PubspecService.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/services/PubspecService.kt new file mode 100644 index 00000000..faf82471 --- /dev/null +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/services/PubspecService.kt @@ -0,0 +1,71 @@ +package shop.itbug.fluttercheckversionx.services + +import com.intellij.openapi.Disposable +import com.intellij.openapi.application.runReadAction +import com.intellij.openapi.components.Service +import com.intellij.openapi.components.service +import com.intellij.openapi.project.DumbAware +import com.intellij.openapi.project.Project +import com.intellij.openapi.startup.ProjectActivity +import com.intellij.openapi.vfs.AsyncFileListener +import com.intellij.openapi.vfs.VirtualFileManager +import com.intellij.openapi.vfs.newvfs.events.VFileEvent +import shop.itbug.fluttercheckversionx.util.MyPsiElementUtil + + +class PubspecStartActivity : ProjectActivity, DumbAware { + override suspend fun execute(project: Project) { + PubspecService.getInstance(project).startCheck() + VirtualFileManager.getInstance() + .addAsyncFileListener(PubspecFileChangeListenAsync(project), project.service()) + } +} + +@Service(Service.Level.PROJECT) +class PubspecService(val project: Project) : Disposable { + + private var dependenciesNames = listOf() + + fun getAllDependencies(): List = dependenciesNames + + fun startCheck() { + runReadAction { + dependenciesNames = MyPsiElementUtil.getAllPluginsString(project) + } + } + + companion object { + fun getInstance(project: Project): PubspecService { + return project.service() + } + } + + override fun dispose() { + dependenciesNames = emptyList() + } + +} + + +class PubspecFileChangeListenAsync(val project: Project) : AsyncFileListener { + override fun prepareChange(events: MutableList): AsyncFileListener.ChangeApplier? { + if (project.isDisposed) { + return null + } + return object : AsyncFileListener.ChangeApplier { + override fun afterVfsChange() { + if (project.isDisposed) { + return + } + events.forEach { + val filename = it.file?.name + if (filename != null && filename == "pubspec.yaml") { + project.service().startCheck() + } + } + + } + } + } + +} \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/services/actions/SocketConnectComboxAction.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/services/actions/SocketConnectComboxAction.kt deleted file mode 100644 index 76f29bd7..00000000 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/services/actions/SocketConnectComboxAction.kt +++ /dev/null @@ -1,59 +0,0 @@ -package shop.itbug.fluttercheckversionx.services.actions - -import com.intellij.openapi.actionSystem.ActionUpdateThread -import com.intellij.openapi.actionSystem.AnActionEvent -import com.intellij.openapi.actionSystem.DefaultActionGroup -import com.intellij.openapi.ui.popup.JBPopup -import com.intellij.openapi.ui.popup.JBPopupFactory -import shop.itbug.fluttercheckversionx.common.MyAction -import shop.itbug.fluttercheckversionx.i18n.PluginBundle -import shop.itbug.fluttercheckversionx.socket.service.DioApiService -import shop.itbug.fluttercheckversionx.widget.MyExpandableComboAction - -/** - * socket 链接列表 - */ -class SocketConnectComboxAction : MyExpandableComboAction() { - - var selectSessionId = "" - - private fun createGroup() = object : DefaultActionGroup() { - init { - addAll(DioApiService.getInstance().getSessions().map { - object : MyAction({ it.sessionID }) { - override fun actionPerformed(e: AnActionEvent) { - println("勾选。。。") - selectSessionId = it.sessionID - } - } - }) - } - } - - - override fun update(e: AnActionEvent) { - val sessions = DioApiService.getInstance().getSessions() - if (sessions.isEmpty()) { - e.presentation.description = "Empty" - e.presentation.text = PluginBundle.get("empty") - } - - super.update(e) - } - - - override fun createPopup(event: AnActionEvent): JBPopup { - val pop = JBPopupFactory.getInstance().createActionGroupPopup( - null, - createGroup(), - event.dataContext, - JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, - true - ) - return pop - } - - override fun getActionUpdateThread(): ActionUpdateThread { - return ActionUpdateThread.BGT - } -} diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/services/impl/ModelToFreezedModelServiceImpl.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/services/impl/ModelToFreezedModelServiceImpl.kt index 18824ca8..4a71d044 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/services/impl/ModelToFreezedModelServiceImpl.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/services/impl/ModelToFreezedModelServiceImpl.kt @@ -1,9 +1,10 @@ package shop.itbug.fluttercheckversionx.services.impl -import com.alibaba.fastjson2.JSONArray -import com.alibaba.fastjson2.JSONObject import com.intellij.openapi.actionSystem.AnActionEvent import com.jetbrains.lang.dart.psi.impl.DartClassDefinitionImpl +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject import shop.itbug.fluttercheckversionx.model.DartClassProperty import shop.itbug.fluttercheckversionx.model.FreezedCovertModel import shop.itbug.fluttercheckversionx.services.ModelToFreezedModelService @@ -13,7 +14,9 @@ class ModelToFreezedModelServiceImpl : ModelToFreezedModelService { override fun psiElementToFreezedCovertModel(classPsiElement: DartClassDefinitionImpl): FreezedCovertModel { val classProperties = DartPsiElementUtil.getClassProperties(classPsiElement) val models = DartPsiElementUtil.getModels(classProperties) - return FreezedCovertModel(properties = models, className = classPsiElement.componentName.text, isDartClassElementType = true) + return FreezedCovertModel( + properties = models, className = classPsiElement.componentName.text, isDartClassElementType = true + ) } override fun anActionEventToFreezedCovertModel(event: AnActionEvent): FreezedCovertModel { @@ -23,42 +26,61 @@ class ModelToFreezedModelServiceImpl : ModelToFreezedModelService { override fun jsonObjectToFreezedCovertModelList( - jsonObject: JSONObject, - oldList: MutableList, - className: String + jsonObject: JsonElement, oldList: MutableList, className: String ): MutableList { val filter = oldList.none { it.className == className } if (filter) { val rootModel = jsonObjectToFreezedCovertModel(jsonObject, className) oldList.add(rootModel) - jsonObject.forEach { key, value -> - if (value is JSONObject) { - jsonObjectToFreezedCovertModelList(value, oldList, key.toString().formatDartName()) - } else if (value is JSONArray && value.isNotEmpty() && value.first() is JSONObject) { - val parse = JSONObject.parse(JSONObject.toJSONString(value.findPropertiesMaxLenObject())) - jsonObjectToFreezedCovertModelList(parse, oldList, key.toString().formatDartName()) + + if (jsonObject.isObject) { + jsonObject.jsonObject.forEach { k, v -> + run { + if (v.isObject) { + jsonObjectToFreezedCovertModelList(v, oldList, k.formatDartName()) + } + if (v.isJsonArray) { + val maxEle = v.jsonArray.findPropertiesMaxLenObject() + jsonObjectToFreezedCovertModelList(maxEle, oldList, k.formatDartName()) + } + } } } + + } return oldList } - // - override fun jsonObjectToFreezedCovertModel(jsonObject: JSONObject, className: String): FreezedCovertModel { + override fun jsonObjectToFreezedCovertModel(jsonObject: JsonElement, className: String): FreezedCovertModel { val properties = mutableListOf() - jsonObject.forEach { key, value -> - val dartType = DartJavaCovertUtil.getDartType(value, key) - val dartClassProperty = DartClassProperty( - type = dartType, - name = key, - isNonNull = false, - finalPropertyValue = value, - finalPropertyName = key - ) - properties.add(dartClassProperty) + if (jsonObject.isObject) { + jsonObject.jsonObject.forEach { key, value -> + val dartType = DartJavaCovertUtil.getDartType(value, key) + val dartClassProperty = DartClassProperty( + type = dartType, name = key, isNonNull = false, finalPropertyValue = value, finalPropertyName = key + ) + properties.add(dartClassProperty) + } } return FreezedCovertModel(properties = properties, className = className) } -} \ No newline at end of file +} + +val JsonElement.isObject: Boolean + get() = try { + this.jsonObject + true + } catch (_: Exception) { + false + } + +val JsonElement.isJsonArray: Boolean + get() = try { + this.jsonArray + true + } catch (_: Exception) { + false + } \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/setting/AppConfig.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/setting/AppConfig.kt index 3bb3c2a6..eeeb5531 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/setting/AppConfig.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/setting/AppConfig.kt @@ -3,6 +3,7 @@ package shop.itbug.fluttercheckversionx.setting import com.intellij.openapi.Disposable import com.intellij.openapi.options.Configurable import com.intellij.openapi.options.SearchableConfigurable +import com.intellij.openapi.project.Project import com.intellij.openapi.ui.DialogPanel import com.intellij.openapi.util.Disposer import com.intellij.ui.components.JBTabbedPane @@ -17,7 +18,12 @@ import shop.itbug.fluttercheckversionx.services.AppStateModel import shop.itbug.fluttercheckversionx.services.PluginStateService import javax.swing.JComponent -class AppConfig : Configurable, Disposable, SearchableConfigurable { +class AppConfig(project: Project) : Configurable, Disposable, SearchableConfigurable { + + + init { + println("project config init...:${project.basePath}") + } var model = PluginStateService.getInstance().state ?: AppStateModel() diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/socket/ProjectSocketService.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/socket/ProjectSocketService.kt index 3d782733..b132c562 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/socket/ProjectSocketService.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/socket/ProjectSocketService.kt @@ -1,7 +1,10 @@ package shop.itbug.fluttercheckversionx.socket -import cn.hutool.core.date.DateUtil +import com.google.gson.annotations.SerializedName import shop.itbug.fluttercheckversionx.form.socket.Request +import java.text.DecimalFormat +import java.time.LocalDateTime +import java.time.format.DateTimeFormatter class ProjectSocketService { @@ -18,7 +21,7 @@ class ProjectSocketService { responseHeaders = emptyMap(), timestamp = 300, projectName = "Test Request", - createDate = DateUtil.now(), + createDate = LocalDateTime.now().toString(), ) } } @@ -26,39 +29,69 @@ class ProjectSocketService { /** * 解析flutter发送过来的模型 */ - data class SocketResponseModel( + class SocketResponseModel( ///服务器返回谁 - val data: Any?, + val data: Any = emptyMap(), ///请求类型 - val method: String?, + val method: String? = "", /// get 查询参数 - val queryParams: Map?, + val queryParams: Map = emptyMap(), ///请求URL - val url: String?, + val url: String = "", ///状态码 - val statusCode: Int?, + val statusCode: Int = -1, ///post参数 - val body: Any?, + val body: Any? = emptyMap(), ///请求头 - val headers: Map?, + val headers: Map = emptyMap(), ///response 请求头 - val responseHeaders: Map?, + val responseHeaders: Map = emptyMap(), ///请求耗时 - var timestamp: Int?, + var timestamp: Int = -1, ///项目名称 var projectName: String = "", - ///生成成功 - var createDate: String = DateUtil.now(), + ///时间 + @SerializedName("createDate") + var createDate: String = LocalDateTime.now().formatDate(), ///扩展label列表 - var extendNotes: List = listOf() - ) + var extendNotes: List = emptyList() + ) { + override fun toString(): String { + return "${url}:${statusCode}:${body}:${extendNotes}:${createDate}" + } + + ///计算大小 + fun calculateSize(): String { + return formatSize(data.toString().toByteArray().size.toLong()) + } + } } + + +fun LocalDateTime.formatDate(): String { + val f = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") + return this.format(f) +} + +fun formatSize(sizeInBytes: Long): String { + val units = arrayOf("Bytes", "KB", "MB", "GB", "TB") + var size = sizeInBytes.toDouble() + var unitIndex = 0 + + while (size >= 1024 && unitIndex < units.size - 1) { + size /= 1024 + unitIndex++ + } + + val df = DecimalFormat("#.##") + return "${df.format(size)} ${units[unitIndex]}" +} \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/socket/service/DioApiService.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/socket/service/DioApiService.kt index 7efc6ac4..4a28ff5f 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/socket/service/DioApiService.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/socket/service/DioApiService.kt @@ -1,7 +1,6 @@ package shop.itbug.fluttercheckversionx.socket.service -import com.alibaba.fastjson2.JSON -import com.alibaba.fastjson2.JSONObject +import com.google.gson.Gson import com.intellij.openapi.components.Service import com.intellij.openapi.components.service import org.smartboot.socket.StateMachineEnum @@ -33,8 +32,6 @@ class DioApiService { messageProcessor.addHandle(processor) } - fun getSessions() = sessions - fun addSession(session: AioSession?) { session?.let { sessions.add(it) } } @@ -44,24 +41,28 @@ class DioApiService { } private fun sendMessage(message: String) { + println("发送JSON:$message") sessions.forEach { it.send(message) } } - fun sendByMap(map: MutableMap) { - sendMessage(JSONObject.toJSONString(map)) - } - fun sendByAnyObject(obj: Any) { - val json = JSON.toJSONString(obj) - sendByMap(JSON.parseObject(json)) + try { + if (obj is String) { + sendMessage(obj) + } else { + val jsonString = Gson().toJson(obj) + sendMessage(jsonString) + } + } catch (e: Exception) { + e.printStackTrace() + } } interface NativeMessageProcessing { - fun register() { getInstance().addHandle(this) } @@ -71,7 +72,7 @@ class DioApiService { * @param nativeMessage 字符串消息 * @param jsonObject 会尝试转换字符串消息为JSON,注意判空 */ - fun handleFlutterAppMessage(nativeMessage: String, jsonObject: JSONObject?, aio: AioSession?) + fun handleFlutterAppMessage(nativeMessage: String, jsonObject: Map?, aio: AioSession?) fun stateEvent( session: AioSession?, stateMachineEnum: StateMachineEnum?, throwable: Throwable? @@ -86,14 +87,15 @@ class DioApiService { fun covertJsonError(e: Exception, aio: AioSession?) {} - override fun handleFlutterAppMessage(nativeMessage: String, jsonObject: JSONObject?, aio: AioSession?) { + override fun handleFlutterAppMessage(nativeMessage: String, jsonObject: Map?, aio: AioSession?) { try { - jsonObject?.to(ProjectSocketService.SocketResponseModel::class.java)?.let { - if (it.projectName.isNotBlank()) { - handleModel(it) - } + if (jsonObject != null && jsonObject["projectName"] != null) { + val model = Gson().fromJson(nativeMessage, ProjectSocketService.SocketResponseModel::class.java) + handleModel(model) } } catch (e: Exception) { + println("转换异常:${e.localizedMessage}") + e.printStackTrace() covertJsonError(e, aio) } } @@ -124,11 +126,14 @@ object MyMessageProcessor : AbstractMessageProcessor() { private fun jsonStringToModel(msg: String, session: AioSession?) { try { - val json = JSONObject.parse(msg) + println("收到message:$msg") + val json = Gson().fromJson(msg, Map::class.java).toMapAny + println("json is $json") handle.forEach { it.handleFlutterAppMessage(msg, json, session) } - } catch (_: Exception) { + } catch (e: Exception) { + e.printStackTrace() handle.forEach { it.handleFlutterAppMessage(msg, null, session) } @@ -155,19 +160,12 @@ object MyMessageProcessor : AbstractMessageProcessor() { private fun defaultEventHandle(session: AioSession?, stateMachineEnum: StateMachineEnum?) { println("==$session $stateMachineEnum") when (stateMachineEnum) { - StateMachineEnum.NEW_SESSION -> { - getInstance().addSession(session) - } - + StateMachineEnum.NEW_SESSION -> getInstance().addSession(session) StateMachineEnum.INPUT_SHUTDOWN -> getInstance().removeSession(session) - StateMachineEnum.SESSION_CLOSING -> getInstance() - .removeSession(session) - + StateMachineEnum.SESSION_CLOSING -> getInstance().removeSession(session) StateMachineEnum.SESSION_CLOSED -> getInstance().removeSession(session) StateMachineEnum.REJECT_ACCEPT -> getInstance().removeSession(session) - StateMachineEnum.ACCEPT_EXCEPTION -> getInstance() - .removeSession(session) - + StateMachineEnum.ACCEPT_EXCEPTION -> getInstance().removeSession(session) else -> {} } } @@ -185,8 +183,8 @@ private class MyHeartCommon : MyHeartPlugin(15, TimeUnit.SECONDS) { override fun isHeartMessage(session: AioSession?, msg: String?): Boolean { msg?.let { - val json = JSONObject.parse(msg) - if (json.getString("type") == "ping") { + val json = Gson().fromJson(it, HashMap::class.java) + if (json["type"] == "ping") { MyLoggerEvent.fire(MyLogInfo(message = "$msg", key = LogKeys.ping)) return true } @@ -206,4 +204,17 @@ private fun AioSession.send(message: String) { } catch (e: Exception) { println("发送消息失败:$e") } -} \ No newline at end of file +} + +val Map<*, *>.toMapAny: Map + get() { + val map = mutableMapOf() + this.forEach { (k, v) -> + run { + if (v != null) { + map[k.toString()] = v + } + } + } + return map + } \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/tools/DartPluginVersionCheck.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/tools/DartPluginVersionCheck.kt index 0da25a1f..ab17bd9b 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/tools/DartPluginVersionCheck.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/tools/DartPluginVersionCheck.kt @@ -1,35 +1,34 @@ package shop.itbug.fluttercheckversionx.tools -import cn.hutool.core.date.DateUtil -import com.intellij.codeInspection.InspectionManager -import com.intellij.codeInspection.LocalQuickFix -import com.intellij.codeInspection.ProblemDescriptor -import com.intellij.codeInspection.ProblemHighlightType +import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction import com.intellij.lang.annotation.AnnotationHolder import com.intellij.lang.annotation.ExternalAnnotator import com.intellij.lang.annotation.HighlightSeverity -import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.DumbAware import com.intellij.openapi.project.Project +import com.intellij.openapi.util.Iconable import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile import com.intellij.psi.PsiRecursiveElementWalkingVisitor +import com.intellij.psi.impl.source.tree.LeafPsiElement import kotlinx.coroutines.Deferred import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll import kotlinx.coroutines.runBlocking +import org.jetbrains.yaml.psi.impl.YAMLKeyValueImpl +import org.jetbrains.yaml.psi.impl.YAMLPlainTextImpl import shop.itbug.fluttercheckversionx.cache.DartPluginIgnoreConfig import shop.itbug.fluttercheckversionx.i18n.PluginBundle -import shop.itbug.fluttercheckversionx.listeners.MyLoggerEvent +import shop.itbug.fluttercheckversionx.icons.MyIcons import shop.itbug.fluttercheckversionx.model.PubVersionDataModel import shop.itbug.fluttercheckversionx.model.getLastVersionText -import shop.itbug.fluttercheckversionx.util.ApiService +import shop.itbug.fluttercheckversionx.services.PubService import shop.itbug.fluttercheckversionx.util.DartPluginVersionName -import shop.itbug.fluttercheckversionx.util.MyPsiElementUtil +import shop.itbug.fluttercheckversionx.util.MyYamlPsiElementFactory import shop.itbug.fluttercheckversionx.util.YamlExtends -import shop.itbug.fluttercheckversionx.window.logger.LogKeys -import shop.itbug.fluttercheckversionx.window.logger.MyLogInfo +import javax.swing.Icon /** * 插件新版本检测 @@ -68,28 +67,16 @@ class DartPluginVersionCheck : ExternalAnnotator { val arr = mutableListOf() collectedInfo?.let { - MyLoggerEvent.fire( - MyLogInfo( - message = "${DateUtil.now()} Start detecting new version of package", - key = LogKeys.checkPlugin - ) - ) val infos: List = runBlocking { val tasks = it.element.map { info -> val pluginName = info.packageInfo.name val r: Deferred = async { - return@async ApiService.getPluginDetail(pluginName) + return@async PubService.callPluginDetails(pluginName) } return@map r } return@runBlocking tasks.awaitAll() } - MyLoggerEvent.fire( - MyLogInfo( - message = "${DateUtil.now()} The new version of the detection package has ended, with a total of ${it.element.size} packages", - key = LogKeys.checkPlugin - ) - ) it.element.forEach { info -> val packageName = info.packageInfo.name val find: PubVersionDataModel? = infos.find { detail -> detail?.name == packageName } @@ -97,15 +84,6 @@ class DartPluginVersionCheck : ExternalAnnotator?, holder: AnnotationHolder) { annotationResult?.forEach { val fixText = PluginBundle.get("version.tip.3") + it.lastVersion - val fix = MyLocalFix(fixText, it.lastVersion) - val desc = InspectionManager.getInstance(file.project).createProblemDescriptor( - it.element, - fixText, - fix, - ProblemHighlightType.WARNING, - false - ) holder.newAnnotation( HighlightSeverity.WARNING, "${PluginBundle.get("version.tip.1")}:${it.lastVersion}" - ).newLocalQuickFix(fix, desc).registerFix().range(it.element.lastChild).needsUpdateOnTyping().create() - - } + ) + .newFix(object : PsiElementBaseIntentionAction(), Iconable, DumbAware { + override fun getFamilyName() = fixText + override fun getText() = fixText + override fun isAvailable(project: Project, editor: Editor?, element: PsiElement): Boolean { + return element.text != it.lastVersion + } - } -} + override fun invoke(project: Project, editor: Editor?, element: PsiElement) { + val newElement = MyYamlPsiElementFactory.createPlainPsiElement(project, it.lastVersion) + if (newElement != null) { + if (element is LeafPsiElement && element.prevSibling is YAMLKeyValueImpl && element.prevSibling.lastChild is YAMLPlainTextImpl) { + element.prevSibling.lastChild.replace(newElement) + } else { + element.replace(newElement) + } + } + } + override fun getIcon(flags: Int): Icon = MyIcons.flutter -///修复新版本 -class MyLocalFix(private val fixText: String, private val newText: String) : LocalQuickFix { - override fun getFamilyName(): String = fixText + }).registerFix().range(it.element.lastChild) + .needsUpdateOnTyping() + .create() - override fun applyFix(project: Project, descriptor: ProblemDescriptor) { - val element = descriptor.psiElement - ApplicationManager.getApplication().invokeLater { - MyPsiElementUtil.modifyPsiElementText(element.lastChild, newText) } + } -} \ No newline at end of file +} diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/tools/LibTools.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/tools/LibTools.kt deleted file mode 100644 index cd2d4a96..00000000 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/tools/LibTools.kt +++ /dev/null @@ -1,35 +0,0 @@ -package shop.itbug.fluttercheckversionx.tools - -import com.intellij.openapi.project.Project -import com.intellij.psi.PsiManager -import com.intellij.psi.search.FileTypeIndex -import com.intellij.psi.util.PsiTreeUtil -import com.jetbrains.lang.dart.DartFileType -import com.jetbrains.lang.dart.psi.impl.DartLibraryStatementImpl -import shop.itbug.fluttercheckversionx.autoCompletion.OnlyProjectFileSearch - -object LibTools { - - - ///获取库列表 - fun getLibraryFiles(project: Project): MutableCollection { - val files = FileTypeIndex.getFiles(DartFileType.INSTANCE, OnlyProjectFileSearch(project)) - val libraryNames = mutableListOf() - if (files.isNotEmpty()) { - files.forEach { file -> - val findFile = PsiManager.getInstance(project).findFile(file) - val findChildrenOfAnyType = - PsiTreeUtil.findChildrenOfAnyType(findFile, DartLibraryStatementImpl::class.java) - findChildrenOfAnyType.forEach { libPsi -> - libPsi.libraryNameElement?.text?.let { libName -> - if (libName.isNotEmpty()) { - libraryNames.add(libName) - } - } - } - } - } - return libraryNames - } - -} \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/tools/MyJsonParseTool.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/tools/MyJsonParseTool.kt new file mode 100644 index 00000000..826f94f0 --- /dev/null +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/tools/MyJsonParseTool.kt @@ -0,0 +1,319 @@ +package shop.itbug.fluttercheckversionx.tools + +import com.google.common.base.CaseFormat +import com.google.gson.JsonArray +import com.google.gson.JsonElement +import com.google.gson.JsonObject +import com.google.gson.JsonParser +import com.intellij.openapi.components.* +import com.intellij.openapi.project.Project +import com.intellij.openapi.project.guessProjectDir +import shop.itbug.fluttercheckversionx.i18n.PluginBundle +import shop.itbug.fluttercheckversionx.util.formatDartName + +sealed class MyDartType(var dartType: String, var defaultValue: String) +data object DartDynamicValue : MyDartType("dynamic", "") +data object DartStringValue : MyDartType("String", "''") +data object DartNumberValue : MyDartType("num", "0") +data object DartBooleanValue : MyDartType("bool", "false") +data class DartCustomObject(var className: String) : + MyDartType(className.formatDartName(), "${className.formatDartName()}()") + +enum class NameFormat(val title: String, val example: String) { + Original( + PluginBundle.get("freezed.gen.formatname.original"), + "${PluginBundle.get("freezed.gen.formatname.start")}:Root ${PluginBundle.get("freezed.gen.formatname.after")}:Root" + ), + Tf( + PluginBundle.get("freezed.gen.formatname.tf"), + "${PluginBundle.get("freezed.gen.formatname.start")}:test_properties ${PluginBundle.get("freezed.gen.formatname.after")}:testProperties" + ), + UC( + "C++", + "${PluginBundle.get("freezed.gen.formatname.start")}:test_properties ${PluginBundle.get("freezed.gen.formatname.after")}:TestProperties" + ) + +} + +enum class FormJsonType(val value: String) { + DynamicMap("Map"), ObjectType("Map"), ObjectObject("Map"), DynamicType( + "dynamic" + ) +} + +data class DartArrayValue(var className: String) : MyDartType("List<${className.formatDartName()}>", "[]") +data class MyDartProperties(var name: String, var type: MyDartType, var index: Int) +sealed class DartType +sealed class DartPropertyGenerateConfig +sealed class DartClassGenerateConfig : BaseState() +data class MyJsonObject(val name: String, var obj: JsonObject) +data class MyJsonArray(var name: String, var obj: JsonArray) +data class MyChildObject(var className: String, var properties: List, var index: Int? = null) : + DartType() + +data class FreezedPropertiesConfig( + var setDefaultValue: Boolean = true, + var useJsonKey: Boolean = true, + var nameFormat: NameFormat = NameFormat.Tf, + var hiveConfig: HiveSetting = HiveSetting() +) : DartPropertyGenerateConfig() + +data class HiveSetting(var enable: Boolean = false, var hiveId: Int = 0) +data class FreezedClassConfig( + var rootName: String = "Root", + var saveFileName: String = "root", + var saveDirectory: String = "", + var addStructureFunction: Boolean = true, + var addFromJsonFunction: Boolean = true, + var classNameFormat: NameFormat = NameFormat.Original, + var propertyNameFormat: NameFormat = NameFormat.Tf, + var propsConfig: FreezedPropertiesConfig = FreezedPropertiesConfig(), + var formJsonType: FormJsonType = FormJsonType.DynamicMap, + var hiveSetting: HiveSetting = HiveSetting(), + var runBuildCommand: Boolean = false, + var openInEditor: Boolean = false, +) : DartClassGenerateConfig() + +@Service(Service.Level.PROJECT) +@State(name = "FlutterX Freezed Code Gen Setting", category = SettingsCategory.PLUGINS) +@Storage(roamingType = RoamingType.DEFAULT) +class FreezedClassConfigStateService(project: Project) : SimplePersistentStateComponent( + FreezedClassConfig( + saveDirectory = project.guessProjectDir()?.path ?: "" + ) +) { + companion object { + fun getInstance(project: Project): FreezedClassConfigStateService = project.service() + } +} + +///json数据处理 +class MyJsonParseTool(root: JsonElement, var className: String = "Root") { + + val jsonObject: JsonObject? = if (root.isJsonObject) root.asJsonObject else null + + ///获取所有的字段(排除了对象和数组) + private fun properties(): List { + val list = mutableListOf() + val map = jsonObject?.asMap() ?: emptyMap() + map.onEachIndexed { index, (t, u) -> + run { + if (!u.isJsonObject && !u.isJsonArray) { + list.add(MyDartProperties(t.toString(), u.getDartType(), index)) + } else { + if (u.isJsonObject) { + list.add(MyDartProperties(t.toString(), DartCustomObject(t), index)) + } + if (u.isJsonArray) { + val arr: JsonArray = u.asJsonArray + if (!arr.isEmpty) { + val first: JsonElement = arr.first() + when (val type = first.getDartType()) { + is DartCustomObject -> list.add( + MyDartProperties( + t.toString(), DartArrayValue(DartCustomObject(t).className), index + ) + ) + + else -> list.add(MyDartProperties(t.toString(), DartArrayValue(type.dartType), index)) + } + } else { + list.add(MyDartProperties(t.toString(), DartDynamicValue, index)) + } + } + } + } + } + + return list + } + + ///获取所有属性 + fun findAllDartType(): List { + val list = mutableListOf() + if (jsonObject != null) { + list.add(MyChildObject(className, properties())) + } + findAllObjects().forEach { + val props = MyJsonParseTool(it.obj, it.name.formatDartName()) + list.addAll(props.findAllDartType()) + } + findAllArrays().forEach { + val maxObject: JsonElement? = it.obj.getMaxObject() + if (maxObject != null) { + val tool = MyJsonParseTool(maxObject, it.name.formatDartName()) + list.addAll(tool.findAllDartType()) + } + } + return list + } + + + ///获取值是对象的所有模型 + private fun findAllObjects(): List { + val list = mutableListOf() + jsonObject?.asMap()?.forEach { (t, u) -> + run { + if (u.isJsonObject) { + list.add(MyJsonObject(t.toString(), u.asJsonObject)) + } + } + } + return list + } + + ///获取所有的数组类型 + private fun findAllArrays(): List { + val list = mutableListOf() + jsonObject?.asMap()?.forEach { (t, u) -> + run { + if (u.isJsonArray) { + list.add(MyJsonArray(t.toString(), u.asJsonArray)) + } + } + } + return list + } + + companion object { + + fun parseJson(json: String): List { + val root = getRootJsonElement(json) + return MyJsonParseTool(root).findAllDartType() + } + + private fun getRootJsonElement(json: String): JsonElement { + val ele = JsonParser.parseString(json) + if (ele.isJsonObject) return ele + if (ele.isJsonArray) { + return ele.asJsonArray.getMaxObject() ?: ele + } + return ele + } + } +} + + +///获取dart类型 +fun JsonElement.getDartType(): MyDartType { + if (this.isJsonPrimitive) { + val jp = this.asJsonPrimitive + if (jp.isString) { + return DartStringValue + } else if (jp.isNumber) { + return DartNumberValue + } else if (jp.isBoolean) { + return DartBooleanValue + } + } + if (this.isJsonObject) { + return DartCustomObject("") + } + return DartDynamicValue +} + +fun JsonArray.getMaxObject(): JsonElement? { + var maxItem = this.firstOrNull { it.isJsonObject } + for (it in this.iterator()) { + if (it.isJsonObject && maxItem != null) { + if (it.asJsonObject.keySet().size > maxItem.asJsonObject.keySet().size) { + maxItem = it + } + } + } + return maxItem +} + + +///生成freezed class +fun MyChildObject.getFreezedClass(config: FreezedClassConfig = FreezedClassConfig()): String { + val sb = StringBuilder() + val hiveConfig = config.hiveSetting + val className = this.className.formatDartName(config.classNameFormat) + sb.appendLine("@freezed") + + if (hiveConfig.enable) { + var id = hiveConfig.hiveId + index?.let { + if (it != 0) { + id++ + } + } + sb.appendLine("@HiveType(typeId: $id)") + } + + sb.appendLine("class $className with _\$$className {") + if (config.addStructureFunction) { + sb.appendLine("\tconst $className._();") + sb.appendLine("") + } + sb.appendLine("\tconst factory $className({") + + ///属性 + properties.forEach { p -> + val isLast = properties.last() == p + sb.appendLine( + "\t\t${ + p.getFreezedProperty( + config.propsConfig.copy( + nameFormat = config.propertyNameFormat, hiveConfig = hiveConfig + ) + ) + }${if (isLast) "" else ","}" + ) + } + + + sb.appendLine("\t}) = _$className;") + sb.appendLine("") + + + if (config.addFromJsonFunction) { + sb.appendLine("\t factory $className.fromJson(${config.formJsonType.value} json) => _\$$className" + "FromJson(json);") + sb.appendLine("") + } + + sb.appendLine("}") + return sb.toString() +} + +fun MyDartProperties.getFreezedProperty(config: FreezedPropertiesConfig): String { + val sb = StringBuilder() + val hiveConfig = config.hiveConfig + if (hiveConfig.enable) { + val hiveDefaultValue = if (config.setDefaultValue) ", defaultValue:${this.type.defaultValue}" else "" + sb.append("@HiveField($index$hiveDefaultValue) ") + } + + if (config.useJsonKey) { + sb.append("@JsonKey(name: '${this.name}') ") + } + + if (config.setDefaultValue) { + if (this.type.defaultValue.isNotBlank()) { + sb.append("@Default(${this.type.defaultValue}) ") + } + } else { + sb.append("required ") + } + + sb.append(this.type.dartType + " ") + + sb.append(this.name.formatDartName(config.nameFormat)) + + + return sb.toString() +} + + +fun String.formatDartName(type: NameFormat): String { + var finalName = this + if (this.startsWith("_")) { + finalName = finalName.removePrefix("_") + } + return when (type) { + NameFormat.Original -> finalName + NameFormat.Tf -> CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, finalName) + NameFormat.UC -> CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, finalName) + } +} \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/util/ApiService.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/util/ApiService.kt deleted file mode 100644 index d42b22ec..00000000 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/util/ApiService.kt +++ /dev/null @@ -1,26 +0,0 @@ -package shop.itbug.fluttercheckversionx.util - -import cn.hutool.core.date.DateUtil -import shop.itbug.fluttercheckversionx.listeners.MyLoggerEvent -import shop.itbug.fluttercheckversionx.model.PubVersionDataModel -import shop.itbug.fluttercheckversionx.services.PubService -import shop.itbug.fluttercheckversionx.window.logger.LogKeys -import shop.itbug.fluttercheckversionx.window.logger.MyLogInfo - -object ApiService { - fun getPluginDetail(name: String): PubVersionDataModel? { - try { - return PubService.callPluginDetails(name) - } catch (e: Exception) { - println("获取插件失败:${e.localizedMessage}") - MyLoggerEvent.fire( - MyLogInfo( - message = "${DateUtil.now()} [$name] Failed to detect package version: ${e.localizedMessage}", - key = LogKeys.checkPlugin - ) - ) - e.printStackTrace() - } - return null - } -} \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/util/DartJavaCovertUtil.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/util/DartJavaCovertUtil.kt index aef2a9d8..846f2d9d 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/util/DartJavaCovertUtil.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/util/DartJavaCovertUtil.kt @@ -1,15 +1,18 @@ package shop.itbug.fluttercheckversionx.util -import com.alibaba.fastjson2.JSONArray -import com.alibaba.fastjson2.JSONObject +import kotlinx.serialization.json.JsonArray +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonObject +import shop.itbug.fluttercheckversionx.services.impl.isObject import java.math.BigDecimal -fun JSONArray.findPropertiesMaxLenObject(): JSONObject { - var obj = JSONObject() +fun JsonArray.findPropertiesMaxLenObject(): JsonElement { + var obj = this.first() for (it in this) { - if (it is JSONObject) { - if (it.keys.size > obj.keys.size) { + if (it.isObject) { + val keys = it.jsonObject.keys + if (keys.size > obj.jsonObject.keys.size) { obj = it } } @@ -40,19 +43,16 @@ object DartJavaCovertUtil { "bool" } - JSONObject::class.java -> { + JsonElement::class.java -> { key.formatDartName() } - JSONArray::class.java -> { + JsonArray::class.java -> { - val arr = obj as JSONArray + val arr = obj as JsonArray if (arr.isNotEmpty()) { - if (arr.first() is JSONObject) { - "List<${key.formatDartName()}>" - } - + "List<${key.formatDartName()}>" } "List<${if (arr.isEmpty()) "dynamic" else getDartType(arr.first(), key)}>" diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/util/MyFileUtil.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/util/MyFileUtil.kt index 1623daf3..50b6b2e9 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/util/MyFileUtil.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/util/MyFileUtil.kt @@ -47,7 +47,6 @@ class MyFileUtil { companion object { - /** * 遍历文件夹目录内所有的文件 * @param folderName 项目文件夹目录 diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/util/MyPsiUtil.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/util/MyPsiUtil.kt index 139beae8..6834a81f 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/util/MyPsiUtil.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/util/MyPsiUtil.kt @@ -1,7 +1,8 @@ package shop.itbug.fluttercheckversionx.util -import com.intellij.openapi.application.readAction +import com.intellij.openapi.application.runReadAction import com.intellij.openapi.command.WriteCommandAction +import com.intellij.openapi.components.service import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.LocalFileSystem import com.intellij.project.stateStore @@ -20,7 +21,7 @@ import org.jetbrains.yaml.psi.impl.YAMLKeyValueImpl import shop.itbug.fluttercheckversionx.constance.igFlutterPlugin import shop.itbug.fluttercheckversionx.model.FlutterPluginElementModel import shop.itbug.fluttercheckversionx.model.FlutterPluginType -import shop.itbug.fluttercheckversionx.tools.FlutterVersionTool +import shop.itbug.fluttercheckversionx.services.PubspecService import java.io.File @@ -79,13 +80,12 @@ class MyPsiElementUtil { /** * 获取项目pubspec.yaml 文件 */ - suspend fun getPubSpecYamlFile(project: Project): PsiFile? { - FlutterVersionTool.readVersionFromSdkHome(project) ?: return null + fun getPubSpecYamlFile(project: Project): PsiFile? { val pubspecYamlFile = LocalFileSystem.getInstance() .findFileByIoFile(File("${project.stateStore.projectBasePath}/pubspec.yaml")) if (pubspecYamlFile != null) { - return readAction { PsiManager.getInstance(project).findFile(pubspecYamlFile) } + return runReadAction { PsiManager.getInstance(project).findFile(pubspecYamlFile) } } return null } @@ -93,30 +93,33 @@ class MyPsiElementUtil { /** * 获取项目的所有插件 */ - suspend fun getAllPlugins(project: Project, key: String = "dependencies"): List { + fun getAllPlugins(project: Project): List { + return project.service().getAllDependencies() + } + + + fun getAllPluginsString(project: Project, key: String = "dependencies"): List { val yamlFile = project.getPubspecYAMLFile() yamlFile?.let { file -> val deps = YAMLUtil.getQualifiedKeyInFile(file, key) if (deps != null) { - return deps.children.first().children.map { (it as YAMLKeyValueImpl).keyText } } } return emptyList() } - /** * 获取项目插件列表 */ - suspend fun getAllFlutters(project: Project): MutableMap> { + fun getAllFlutters(project: Project): MutableMap> { val yamlFile = project.getPubspecYAMLFile() val map = mutableMapOf>() yamlFile?.let { yaml -> val coreElement = yaml.firstChild.firstChild val coreElementChildren = coreElement.childrenOfType() if (coreElementChildren.isNotEmpty()) { - FlutterPluginType.entries.forEach { type -> + FlutterPluginType.values().forEach { type -> val l = coreElementChildren.filter { it.keyText == type.type }.toList() if (l.isNotEmpty()) { val pluginDevs = l.first() @@ -209,6 +212,6 @@ fun PsiElement.getPluginName(): String { /** * 获取项目下的pubspec.yaml文件的yaml file对象 */ -suspend fun Project.getPubspecYAMLFile(): YAMLFile? { +fun Project.getPubspecYAMLFile(): YAMLFile? { return MyPsiElementUtil.getPubSpecYamlFile(this) as? YAMLFile } \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/util/RunUtil.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/util/RunUtil.kt index 3f6b1ae9..3e86eb39 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/util/RunUtil.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/util/RunUtil.kt @@ -8,10 +8,16 @@ import org.jetbrains.plugins.terminal.TerminalToolWindowManager object RunUtil { - fun runCommand(project: Project, title: String, command: String) { + fun runFlutterBuildCommand(project: Project) { + runCommand(project, "Flutter Builder", "flutter pub run build_runner build") + } + + private fun runFlutterCommandBy233(project: Project, title: String, command: String) { ApplicationManager.getApplication().invokeLater { val instance = TerminalToolWindowManager.getInstance(project) var toolWindow = instance.toolWindow + + //显示窗口 if (toolWindow == null) { toolWindow = ToolWindowManager.getInstance(project).getToolWindow(TerminalToolWindowFactory.TOOL_WINDOW_ID) @@ -23,10 +29,46 @@ object RunUtil { } toolWindow.activate { // 241-- -// instance.createLocalShellWidget(project.basePath, title).executeCommand(command) - // 241+ - instance.createShellWidget(project.basePath, title, true, true).sendCommandToExecute(command) //241+ + instance.createLocalShellWidget(project.basePath, title).executeCommand(command) } } } + + private fun runCommandBy244(project: Project, title: String, command: String) { + ApplicationManager.getApplication().invokeLater { + val instance = TerminalToolWindowManager.getInstance(project) + var toolWindow = instance.toolWindow + + //显示窗口 + if (toolWindow == null) { + toolWindow = + ToolWindowManager.getInstance(project).getToolWindow(TerminalToolWindowFactory.TOOL_WINDOW_ID) + toolWindow?.show() + } else { + if (toolWindow.isAvailable) { + toolWindow.show() + } + } + + val find = toolWindow.contentManager.findContent(title) + if (find != null) { + val tw = TerminalToolWindowManager.findWidgetByContent(find) + tw?.let { println(tw::class.java) } + tw?.requestFocus() + tw?.sendCommandToExecute(command) + tw?.setCursorVisible(true) + toolWindow.contentManager.setSelectedContent(find) + } else { + toolWindow.activate { + val terminal = instance.createShellWidget(project.basePath, title, true, true) + terminal.sendCommandToExecute(command) + } + } + } + } + + fun runCommand(project: Project, title: String, command: String) { + runCommandBy244(project, title, command) +// runFlutterCommandBy233(project, title, command) + } } \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/util/VerifyFileDir.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/util/VerifyFileDir.kt new file mode 100644 index 00000000..3f38d0b6 --- /dev/null +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/util/VerifyFileDir.kt @@ -0,0 +1,49 @@ +package shop.itbug.fluttercheckversionx.util + +import com.intellij.openapi.ui.TextFieldWithBrowseButton +import com.intellij.openapi.ui.ValidationInfo +import com.intellij.openapi.ui.validation.DialogValidation +import com.intellij.openapi.vfs.LocalFileSystem +import com.intellij.openapi.vfs.VirtualFile +import com.intellij.openapi.vfs.VirtualFileManager +import com.intellij.ui.layout.ValidationInfoBuilder +import shop.itbug.fluttercheckversionx.i18n.PluginBundle +import kotlin.io.path.Path + +class VerifyFileDir : DialogValidation.WithParameter { + override fun curry(parameter: TextFieldWithBrowseButton): DialogValidation { + println("file: ${parameter.textField.text}") + return object : DialogValidation { + override fun validate(): ValidationInfo? { + val file: VirtualFile? = VirtualFileManager.getInstance().findFileByUrl(parameter.text) + println("file: -> $file") + if (file == null || LocalFileSystem.getInstance().exists(file).not()) { + return ValidationInfoBuilder(parameter).error(PluginBundle.get("freezed.gen.base.file.dir.error")) + } + return null + } + + } + } + + companion object { + fun validateDir(path: String): Pair? { + VirtualFileManager.getInstance().findFileByNioPath(Path(path)) + ?: return Pair(false, PluginBundle.get("freezed.gen.base.file.dir.error")) + return null + } + + val ERROR_MSG = PluginBundle.get("freezed.gen.base.file.dir.error") + val ENTER_YOU_FILE_NAME = PluginBundle.get("freezed.gen.create.enter.you.file.name") + fun validDirByComponent(comp: TextFieldWithBrowseButton): Boolean { + val path = comp.text + return VirtualFileManager.getInstance().findFileByNioPath(Path(path)) == null + } + + fun validDirByPath(path: String): Boolean { + return VirtualFileManager.getInstance().findFileByNioPath(Path(path)) == null + } + + + } +} \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/util/YamlExtends.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/util/YamlExtends.kt index 64791e12..5b82dcd5 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/util/YamlExtends.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/util/YamlExtends.kt @@ -1,10 +1,15 @@ package shop.itbug.fluttercheckversionx.util +import com.intellij.openapi.project.Project import com.intellij.psi.PsiElement +import com.intellij.psi.PsiFileFactory import com.intellij.psi.impl.source.tree.LeafPsiElement import com.intellij.psi.util.PsiTreeUtil +import org.jetbrains.yaml.YAMLLanguage +import org.jetbrains.yaml.psi.YAMLFile import org.jetbrains.yaml.psi.impl.YAMLBlockMappingImpl import org.jetbrains.yaml.psi.impl.YAMLKeyValueImpl +import org.jetbrains.yaml.psi.impl.YAMLPlainTextImpl private val devPattern = Regex("""\bdev\b""") @@ -67,4 +72,14 @@ class YamlExtends(val element: PsiElement) { return null } +} + +object MyYamlPsiElementFactory { + + ///创建一个节点 + fun createPlainPsiElement(project: Project, text: String): YAMLPlainTextImpl? { + val instance = PsiFileFactory.getInstance(project) + val createFileFromText: YAMLFile = instance.createFileFromText(YAMLLanguage.INSTANCE, "name: $text") as YAMLFile + return PsiTreeUtil.findChildrenOfAnyType(createFileFromText, YAMLPlainTextImpl::class.java).lastOrNull() + } } \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/widget/EditorTextPanel.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/widget/EditorTextPanel.kt index 55989623..3c6e12e6 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/widget/EditorTextPanel.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/widget/EditorTextPanel.kt @@ -1,6 +1,7 @@ package shop.itbug.fluttercheckversionx.widget import com.intellij.json.JsonLanguage +import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.editor.colors.EditorColorsManager import com.intellij.openapi.editor.colors.EditorFontType import com.intellij.openapi.editor.ex.EditorEx @@ -23,7 +24,9 @@ open class JsonEditorTextPanel(project: Project, initText: String = "") : } fun scrollToTop() { - editor?.scrollingModel?.scrollVertically(0) + ApplicationManager.getApplication().invokeLater { + editor?.scrollingModel?.scrollVertically(0) + } } override fun getFont(): Font { diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/widget/MyExpandableComboAction.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/widget/MyExpandableComboAction.kt deleted file mode 100644 index c7ed43ff..00000000 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/widget/MyExpandableComboAction.kt +++ /dev/null @@ -1,29 +0,0 @@ -package shop.itbug.fluttercheckversionx.widget - -import com.intellij.ide.DataManager -import com.intellij.openapi.actionSystem.AnAction -import com.intellij.openapi.actionSystem.AnActionEvent -import com.intellij.openapi.actionSystem.Presentation -import com.intellij.openapi.actionSystem.ex.CustomComponentAction -import com.intellij.openapi.ui.popup.JBPopup -import com.intellij.openapi.wm.impl.ToolbarComboWidget -import java.awt.event.InputEvent -import javax.swing.JComponent - -abstract class MyExpandableComboAction : AnAction(), CustomComponentAction { - override fun createCustomComponent(presentation: Presentation, place: String): JComponent { - return object : ToolbarComboWidget() { - override fun doExpand(e: InputEvent?) { - val dataContext = DataManager.getInstance().getDataContext(this) - val anActionEvent = AnActionEvent.createFromInputEvent(e, place, presentation, dataContext) - createPopup(anActionEvent)?.showUnderneathOf(this) - } - } - } - - protected abstract fun createPopup(event: AnActionEvent): JBPopup? - - override fun actionPerformed(e: AnActionEvent) { - e.project?.let { createPopup(e)?.showCenteredInCurrentWindow(it) } - } -} diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/window/AllPluginsCheckVersion.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/window/AllPluginsCheckVersion.kt index ac5d4031..a1b9adc0 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/window/AllPluginsCheckVersion.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/window/AllPluginsCheckVersion.kt @@ -7,7 +7,6 @@ import com.intellij.ui.components.JBScrollPane import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking import shop.itbug.fluttercheckversionx.model.FlutterPluginElementModel import shop.itbug.fluttercheckversionx.model.FlutterPluginType import shop.itbug.fluttercheckversionx.model.getElementVersion @@ -26,7 +25,7 @@ class AllPluginsCheckVersion(val project: Project, val onDone: () -> Unit) : JPa //插件列表 private var plugins: MutableMap> = - runBlocking { MyPsiElementUtil.getAllFlutters(project) } + MyPsiElementUtil.getAllFlutters(project) //展示列表组件 private val listView = JBList() diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/window/logger/LoggerWindow.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/window/logger/LoggerWindow.kt index efee87c8..0575940d 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/window/logger/LoggerWindow.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/window/logger/LoggerWindow.kt @@ -1,7 +1,5 @@ package shop.itbug.fluttercheckversionx.window.logger -import cn.hutool.core.date.DateTime -import cn.hutool.core.date.DateUtil import com.intellij.openapi.project.Project import com.intellij.ui.JBColor import com.intellij.ui.OnePixelSplitter @@ -13,6 +11,7 @@ import com.intellij.util.ui.UIUtil import com.intellij.util.ui.components.BorderLayoutPanel import shop.itbug.fluttercheckversionx.listeners.MyLoggerEvent import java.awt.Component +import java.time.LocalDateTime import javax.swing.BorderFactory import javax.swing.DefaultListModel import javax.swing.JList @@ -21,7 +20,7 @@ import javax.swing.event.ListSelectionEvent import javax.swing.event.ListSelectionListener data class MyLogKey(val key: String) -data class MyLogInfo(val message: String, val time: DateTime? = DateUtil.date(), val key: MyLogKey) +data class MyLogInfo(val message: String, val time: LocalDateTime? = LocalDateTime.now(), val key: MyLogKey) object LogKeys { val dioLog = MyLogKey(key = "Dio Listen") val ping = MyLogKey(key = "Socket Ping") diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/window/sp/SpManager.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/window/sp/SpManager.kt index e3fe85f8..1859f5b0 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/window/sp/SpManager.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/window/sp/SpManager.kt @@ -1,6 +1,6 @@ package shop.itbug.fluttercheckversionx.window.sp -import com.alibaba.fastjson2.JSONObject +import com.google.gson.Gson import com.intellij.openapi.application.ApplicationManager import com.intellij.util.messages.Topic @@ -22,9 +22,11 @@ data class SPValueModel( val runtimeType: String ) + class SpManager(message: String) { - private val jsonObject: SPResult = JSONObject.parseObject(message, SPResult::class.java) + //private val jsonObject: SPResult = JSONObject.parseObject(message, SPResult::class.java) + private val jsonObject: SPResult = Gson().fromJson(message, SPResult::class.java) fun handle() { val type = jsonObject.type when (type) { @@ -35,13 +37,13 @@ class SpManager(message: String) { } private fun valueHandle() { - val valueModel = JSONObject.parseObject(jsonObject.jsonString, SPValueModel::class.java) + val valueModel = Gson().fromJson(jsonObject.jsonString, SPValueModel::class.java) SpManagerListen.fireValue(valueModel) } //处理key private fun keysHandle() { - val spKeysModel = JSONObject.parseObject(jsonObject.jsonString, SPKeysModel::class.java) + val spKeysModel = Gson().fromJson(jsonObject.jsonString, SPKeysModel::class.java) SpManagerListen.fire(spKeysModel) } diff --git a/src/main/kotlin/shop/itbug/fluttercheckversionx/window/sp/SpWindow.kt b/src/main/kotlin/shop/itbug/fluttercheckversionx/window/sp/SpWindow.kt index e469e4ea..6ea3a518 100644 --- a/src/main/kotlin/shop/itbug/fluttercheckversionx/window/sp/SpWindow.kt +++ b/src/main/kotlin/shop/itbug/fluttercheckversionx/window/sp/SpWindow.kt @@ -1,6 +1,5 @@ package shop.itbug.fluttercheckversionx.window.sp -import com.alibaba.fastjson2.JSONObject import com.intellij.icons.AllIcons import com.intellij.openapi.actionSystem.* import com.intellij.openapi.project.DumbAwareAction @@ -48,7 +47,7 @@ class SpWindow(project: Project, private val toolWindow: ToolWindow) : BorderLay } private fun getAllKeys() { - DioApiService.getInstance().sendByMap(mutableMapOf("action" to "SP_KEY")) + DioApiService.getInstance().sendByAnyObject(mutableMapOf("action" to "SP_KEY")) } @@ -62,9 +61,9 @@ class SpWindow(project: Project, private val toolWindow: ToolWindow) : BorderLay } } - override fun handleFlutterAppMessage(nativeMessage: String, jsonObject: JSONObject?, aio: AioSession?) { + override fun handleFlutterAppMessage(nativeMessage: String, jsonObject: Map?, aio: AioSession?) { if (jsonObject != null) { - val type = jsonObject.getString("type") + val type = jsonObject["type"] if (type == SpManager.KEYS || type == SpManager.VALUE_GET) { SpManager(nativeMessage).handle() } @@ -78,7 +77,7 @@ class SpWindow(project: Project, private val toolWindow: ToolWindow) : BorderLay ///刷新sp keys操作 class SpRefreshAction : DumbAwareAction(AllIcons.Actions.Refresh) { override fun actionPerformed(e: AnActionEvent) { - DioApiService.getInstance().sendByMap(mutableMapOf("action" to "SP_KEY")) + DioApiService.getInstance().sendByAnyObject(mutableMapOf("action" to "SP_KEY")) } override fun getActionUpdateThread(): ActionUpdateThread { @@ -121,7 +120,7 @@ class SpWindowLeft : JBList(), ListSelectionListener { override fun valueChanged(e: ListSelectionEvent?) { if (e != null && e.valueIsAdjusting.not() && selectedValue != null) { DioApiService.getInstance() - .sendByMap(mutableMapOf("action" to "SP_GET_VALUE", "data" to selectedValue)) + .sendByAnyObject(mutableMapOf("action" to "SP_GET_VALUE", "data" to selectedValue)) } } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 4a71c850..cb67eb91 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -52,8 +52,6 @@ messages.pluginBundle - - @@ -107,8 +105,8 @@ language="Dart"/> - - + - + @@ -172,9 +170,15 @@ + + + + + + @@ -205,12 +209,9 @@ - - + @@ -288,7 +289,7 @@ text="Add Default Value"/> + text="Freezed to Simple Class"/> //// @@ -332,6 +333,10 @@ + + + + diff --git a/src/main/resources/messages/pluginBundle.properties b/src/main/resources/messages/pluginBundle.properties index 5e78a559..7b6fe985 100644 --- a/src/main/resources/messages/pluginBundle.properties +++ b/src/main/resources/messages/pluginBundle.properties @@ -136,34 +136,42 @@ check_flutter_version_comment=打开Dart项目时,启动一个进程检查远程 open_flutterx_setting=打开设置 create_a_new_class_name=输入一个新的名称 simple_class_to_freezed_object_f1=构造函数转成freezed - - preview_title=代码预览 - copy_code_dialog_title=拷贝代码 - scan_privacy=扫描 - click_open_the_file=点击打开文件 - not_found_the_privacy_file=没找到 - privacy_info_tips=已经忽略没有iOS目录的package - are_you_ok_betch_insert_privacy_file=确认批量插入吗 - are_you_ok_betch_insert_privacy_file_title=确认 - are_you_ok_betch_insert_privacy_file_ok=批量添加 - are_you_ok_betch_insert_privacy_file_cancel=取消 - are_you_ok_betch_insert_privacy_file_insert=正在添加 - are_you_ok_betch_insert_privacy_file_file=文件 - are_you_ok_betch_insert_privacy_file_button_title=批量修复 - are_you_ok_betch_insert_privacy_file_window_title=隐私扫描工具 - pubspec_yaml_file_re_index=重新索引 +find_the_project_dart_lib_names=找到项目定义的library +get_package_verion_task_title=获取版本列表 +dio.setting.show.data.size=显示数据大小 +freezed.gen.group.title=全局设置 +freezed.gen.group.add.structure.fun=添加构造函数 +freezed.gen.group.add.fromjson.fun=添加函数 +freezed.gen.formatname.original=原始,不改变 +freezed.gen.formatname.tf=驼峰命名规则 +freezed.gen.formatname.classname=类名命名规则 +freezed.gen.formatname.properties=属性命名规则 +freezed.gen.formatname.example=示例 +freezed.gen.formatname.start=之前 +freezed.gen.formatname.after=之后 +freezed.gen.formatname.fromjson.type=类型 +freezed.gen.base.setting=设置 +freezed.gen.base.opt=命名规则和类型声明 +freezed.gen.base.set.default.value=设置默认值 +freezed.gen.base.file.dir.error=不是有效的目录 +freezed.gen.base.open.in.editor=成功后在编辑器打开文件 +freezed.gen.create.task.title=正在生成代码文件,请稍等 +freezed.gen.create.enter.you.file.name=请输入文件名 + + +freezed.gen.create.error=操作失败 diff --git a/src/main/resources/messages/pluginBundle_en.properties b/src/main/resources/messages/pluginBundle_en.properties index c748e754..091f7ec7 100644 --- a/src/main/resources/messages/pluginBundle_en.properties +++ b/src/main/resources/messages/pluginBundle_en.properties @@ -150,3 +150,47 @@ are_you_ok_betch_insert_privacy_file_file=file are_you_ok_betch_insert_privacy_file_button_title=Batch repair are_you_ok_betch_insert_privacy_file_window_title=Privacy scan tool pubspec_yaml_file_re_index=reindex + +find_the_project_dart_lib_names=Find the library defined by the project + +get_package_verion_task_title=Get version list + +dio.setting.show.data.size=Display data size + +freezed.gen.group.title=Global settings + +freezed.gen.group.add.structure.fun=Add constructor + +freezed.gen.group.add.fromjson.fun=Add function + +freezed.gen.formatname.original=Original, unchanged + +freezed.gen.formatname.tf=Naming rules for camel humps + +freezed.gen.formatname.classname=Class name naming convention + +freezed.gen.formatname.properties=Attribute naming convention + +freezed.gen.formatname.example=Example + +freezed.gen.formatname.start=before + +freezed.gen.formatname.after=after + +freezed.gen.formatname.fromjson.type=type + +freezed.gen.base.setting=set up + +freezed.gen.base.opt=Naming rules and type declarations + +freezed.gen.base.set.default.value=Set default values + +freezed.gen.base.file.dir.error=Not a valid directory + +freezed.gen.base.open.in.editor=Open the file in the editor after success + +freezed.gen.create.task.title=Generating code file, please wait + +freezed.gen.create.enter.you.file.name=Please enter a file name + +freezed.gen.create.error=operation failed diff --git a/src/main/resources/messages/pluginBundle_hk.properties b/src/main/resources/messages/pluginBundle_hk.properties index 264eecc2..e5014dc5 100644 --- a/src/main/resources/messages/pluginBundle_hk.properties +++ b/src/main/resources/messages/pluginBundle_hk.properties @@ -167,3 +167,47 @@ are_you_ok_betch_insert_privacy_file_button_title=批量修復 are_you_ok_betch_insert_privacy_file_window_title=隱私掃描工具 pubspec_yaml_file_re_index=重新索引 + +find_the_project_dart_lib_names=找到項目定義的library + +get_package_verion_task_title=獲取版本清單 + +dio.setting.show.data.size=顯示數據大小 + +freezed.gen.group.title=全域設定 + +freezed.gen.group.add.structure.fun=添加搆造函數 + +freezed.gen.group.add.fromjson.fun=添加函數 + +freezed.gen.formatname.original=原始,不改變 + +freezed.gen.formatname.tf=駝峰命名規則 + +freezed.gen.formatname.classname=類名命名規則 + +freezed.gen.formatname.properties=内容命名規則 + +freezed.gen.formatname.example=示例 + +freezed.gen.formatname.start=之前 + +freezed.gen.formatname.after=之後 + +freezed.gen.formatname.fromjson.type=類型 + +freezed.gen.base.setting=設定 + +freezed.gen.base.opt=命名規則和類型聲明 + +freezed.gen.base.set.default.value=設定預設值 + +freezed.gen.base.file.dir.error=不是有效的目錄 + +freezed.gen.base.open.in.editor=成功後在編輯器打開文件 + +freezed.gen.create.task.title=正在生成程式碼檔案,請稍等 + +freezed.gen.create.enter.you.file.name=請輸入檔名 + +freezed.gen.create.error=操作失敗 diff --git a/src/main/resources/messages/pluginBundle_ja.properties b/src/main/resources/messages/pluginBundle_ja.properties index 82881293..74b6b6b3 100644 --- a/src/main/resources/messages/pluginBundle_ja.properties +++ b/src/main/resources/messages/pluginBundle_ja.properties @@ -137,34 +137,48 @@ check_flutter_version_comment=Dart プロジェクトを開くときに、リモ open_flutterx_setting=設定を開く create_a_new_class_name=新しい名前を入力 simple_class_to_freezed_object_f1=コンストラクタをfreezedに変換 - - preview_title=コードプレビュー - copy_code_dialog_title=コピーコード - scan_privacy=スキャン - click_open_the_file=クリックしてファイルを開く - not_found_the_privacy_file=見つからない - privacy_info_tips=iOSディレクトリのないpackageは無視されました - are_you_ok_betch_insert_privacy_file=一括挿入を確認しますか - are_you_ok_betch_insert_privacy_file_title=確認 - are_you_ok_betch_insert_privacy_file_ok=一括追加 - are_you_ok_betch_insert_privacy_file_cancel=キャンセル - are_you_ok_betch_insert_privacy_file_insert=追加#ツイカ# - are_you_ok_betch_insert_privacy_file_file=ファイル - are_you_ok_betch_insert_privacy_file_button_title=一括修正 - are_you_ok_betch_insert_privacy_file_window_title=プライバシースキャンツール - pubspec_yaml_file_re_index=再インデックス +find_the_project_dart_lib_names=プロジェクト定義のlibraryを見つける +get_package_verion_task_title=バージョンリストの取得 +dio.setting.show.data.size=データサイズの表示 +freezed.gen.group.title=グローバル設定 +freezed.gen.group.add.structure.fun=コンストラクタの追加 +freezed.gen.group.add.fromjson.fun=関数の追加 +freezed.gen.formatname.original=オリジナル、変更しない +freezed.gen.formatname.tf=ラクダピーク命名規則 +freezed.gen.formatname.classname=クラス名命名規則 +freezed.gen.formatname.properties=属性命名規則 +freezed.gen.formatname.example=例 +freezed.gen.formatname.start=前 +freezed.gen.formatname.after=後 +freezed.gen.formatname.fromjson.type=タイプ + +freezed.gen.base.setting=設定#セッテイ# + +freezed.gen.base.opt=命名規則とタイプ宣言 + +freezed.gen.base.set.default.value=デフォルト値の設定 + +freezed.gen.base.file.dir.error=有効なディレクトリではありません + +freezed.gen.base.open.in.editor=成功したらエディタでファイルを開きます + +freezed.gen.create.task.title=コードファイルを生成しています。少々お待ちください + +freezed.gen.create.enter.you.file.name=ファイル名を入力してください + +freezed.gen.create.error=操作に失敗しました diff --git a/src/main/resources/messages/pluginBundle_ko.properties b/src/main/resources/messages/pluginBundle_ko.properties index 6674b30a..cae19182 100644 --- a/src/main/resources/messages/pluginBundle_ko.properties +++ b/src/main/resources/messages/pluginBundle_ko.properties @@ -170,3 +170,47 @@ are_you_ok_betch_insert_privacy_file_button_title=대량 수리 are_you_ok_betch_insert_privacy_file_window_title=개인 정보 검색 도구 pubspec_yaml_file_re_index=다시 인덱싱 + +find_the_project_dart_lib_names=프로젝트 정의 library 찾기 + +get_package_verion_task_title=버전 목록 가져오기 + +dio.setting.show.data.size=데이터 크기 표시 + +freezed.gen.group.title=전역 설정 + +freezed.gen.group.add.structure.fun=생성자 추가 + +freezed.gen.group.add.fromjson.fun=함수 추가 + +freezed.gen.formatname.original=원본, 변경 없음 + +freezed.gen.formatname.tf=낙타 봉 명명 규칙 + +freezed.gen.formatname.classname=클래스 이름 지정 규칙 + +freezed.gen.formatname.properties=속성 명명 규칙 + +freezed.gen.formatname.example=예제 + +freezed.gen.formatname.start=이전 + +freezed.gen.formatname.after=이후 + +freezed.gen.formatname.fromjson.type=유형 + +freezed.gen.base.setting=설치 + +freezed.gen.base.opt=명명 규칙 및 유형 선언 + +freezed.gen.base.set.default.value=기본값 설정 + +freezed.gen.base.file.dir.error=유효한 디렉토리가 아닙니다. + +freezed.gen.base.open.in.editor=성공하면 편집기에서 파일 열기 + +freezed.gen.create.task.title=코드 파일을 생성하는 중입니다. 잠시만 기다려 주십시오. + +freezed.gen.create.enter.you.file.name=파일 이름을 입력하십시오. + +freezed.gen.create.error=작업 실패 diff --git a/src/test/kotlin/DartPluginVersionTest.kt b/src/test/kotlin/DartPluginVersionTest.kt deleted file mode 100644 index 258b7927..00000000 --- a/src/test/kotlin/DartPluginVersionTest.kt +++ /dev/null @@ -1,98 +0,0 @@ -import shop.itbug.fluttercheckversionx.model.PubVersionDataModel -import shop.itbug.fluttercheckversionx.model.getLastVersionText -import shop.itbug.fluttercheckversionx.model.hasNewVersion -import shop.itbug.fluttercheckversionx.model.lastDevVersion -import shop.itbug.fluttercheckversionx.util.ApiService -import shop.itbug.fluttercheckversionx.util.DartPluginVersionName -import shop.itbug.fluttercheckversionx.util.isBeta -import shop.itbug.fluttercheckversionx.util.isDev -import kotlin.test.Test -import kotlin.test.assertEquals - -class DartPluginVersionTest { - - @Test - fun testVersion(): Unit { - val isarDev = DartPluginVersionName(name = "isar", version = "^4.0.0-dev.14") - val hiveDev = DartPluginVersionName(name = "hive", version = "4.0.0-dev.2") - val graphqlBeta = DartPluginVersionName(name = "graphql_flutter", version = "^5.2.0-beta.6") - val graphqlBeta2 = DartPluginVersionName(name = "graphql_flutter", version = "5.2.0-beta.12") - val ddJsUtil = DartPluginVersionName(name = "dd_js_util", version = "^3.5.2") - assertEquals(true, isarDev.isDev()) - assertEquals(true, hiveDev.isDev()) - assertEquals(false, isarDev.isBeta()) - assertEquals(false, hiveDev.isBeta()) - assertEquals(true, graphqlBeta.isBeta()) - assertEquals(false, graphqlBeta.isDev()) - assertEquals(true, graphqlBeta2.isBeta()) - assertEquals(false, graphqlBeta2.isDev()) - assertEquals(false, ddJsUtil.isBeta()) - assertEquals(false, ddJsUtil.isDev()) - } - - - ///dev测试 - @Test - fun lastVersionTest(): Unit { - - - /// dev 测试 - - val pluginName = "wechat_assets_picker"; - val model: PubVersionDataModel? = ApiService.getPluginDetail(pluginName) - model?.let { - assertEquals("8.8.1+1", it.latest.version) - assertEquals("9.0.0-dev.2", it.lastDevVersion?.version) - - - val testVersion = DartPluginVersionName(pluginName, "^9.0.0-dev.2") - - val testVersion2 = DartPluginVersionName(pluginName, "^9.0.0-dev.1") - - val testVersion3 = DartPluginVersionName(pluginName, "9.0.0-dev.1") - - - - assertEquals(false, it.hasNewVersion(testVersion)) - assertEquals(true, it.hasNewVersion(testVersion2)) - - assertEquals("^9.0.0-dev.2", it.getLastVersionText(testVersion2)) - assertEquals("^9.0.0-dev.2", it.getLastVersionText(testVersion3)) - - } - - } - - - ///基本测试 - @Test - fun lastVersionTest2(): Unit { - - - /// dev 测试 - - val pluginName = "dd_js_util"; - val model: PubVersionDataModel? = ApiService.getPluginDetail(pluginName) - model?.let { - assertEquals("5.1.6", it.latest.version) - assertEquals(null, it.lastDevVersion?.version) - - - val testVersion = DartPluginVersionName(pluginName, "^9.0.0-dev.2") - - val testVersion2 = DartPluginVersionName(pluginName, "^9.0.0-dev.1") - - val testVersion3 = DartPluginVersionName(pluginName, "5.1.5") - - - - assertEquals(false, it.hasNewVersion(testVersion)) - assertEquals(false, it.hasNewVersion(testVersion2)) - - assertEquals("^5.1.6", it.getLastVersionText(testVersion3)) - - } - - } - -} \ No newline at end of file