Skip to content

Commit

Permalink
合并拉取请求 #60
Browse files Browse the repository at this point in the history
5.0.1
  • Loading branch information
mdddj authored Oct 29, 2024
2 parents 402e7d8 + 0040813 commit 44043f7
Show file tree
Hide file tree
Showing 51 changed files with 1,062 additions and 391 deletions.
2 changes: 1 addition & 1 deletion .idea/dataSources.local.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

232 changes: 117 additions & 115 deletions .idea/workspace.xml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions .kotlin/errors/errors-1729735402635.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kotlin version: 2.0.21
error message: The daemon has terminated unexpectedly on startup attempt #1 with error code: 0. The daemon process output:
1. Kotlin compile daemon is ready

4 changes: 4 additions & 0 deletions .kotlin/errors/errors-1729739570374.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kotlin version: 2.0.21
error message: The daemon has terminated unexpectedly on startup attempt #1 with error code: 0. The daemon process output:
1. Kotlin compile daemon is ready

4 changes: 4 additions & 0 deletions .kotlin/errors/errors-1729921160135.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kotlin version: 2.0.21
error message: The daemon has terminated unexpectedly on startup attempt #1 with error code: 0. The daemon process output:
1. Kotlin compile daemon is ready

15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@

## Unreleased

## [5.0.0] - 2024-10-22
## [5.0.1] - 2024-10-25

- Fix: Analyze the issue of inaccurate location after file changes (
`pubspec.yaml`) [(#59)](https://github.com/mdddj/dd_flutter_idea_plugin/issues/59)
- Adjust the inspection logic of `widget to ConsumerWidget`
- New: Do not analyze files other than `pubspec.yaml`
- New: `pubspec.yaml` New menu for drainage ditch (*Open package api in browser*,*Show Json Data*)
- New: *riverpod widget to ConsumerWidget*: Automatically add import statements
- New: Support local asset image preview
![img.png](https://minio.itbug.shop/blog/simple-file/img___1729914650363___.png)
- New: assets image preview
- ![img.png](https://minio.itbug.shop/blog/simple-file/img___1730164998800___.png)

### [5.0.0] - 2024-10-22

- Fix: dio api copy data to image action if null will null exception
- Fix: If the flutter command does not exist, an error pop-up will
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ repositories {
dependencies {
implementation("org.smartboot.socket:aio-pro:latest.release")
intellijPlatform {
local("/Applications/Android Studio.app")
local("/Applications/IntelliJ IDEA Ultimate.app")
// intellijIdeaCommunity(ideaVersion)
bundledPlugins("org.jetbrains.plugins.terminal", "org.jetbrains.plugins.yaml", "org.intellij.plugins.markdown")
plugins("Dart:$dartVersion")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
kotlin.stdlib.default.dependency=false
pluginVersion=5.0.0.
pluginVersion=5.0.1.
dartVersion=242.22855.32
sinceBuildVersion=242
untilBuildVersion=242.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.intellij.openapi.actionSystem.*
import com.intellij.openapi.options.ShowSettingsUtil
import shop.itbug.fluttercheckversionx.config.PluginConfig
import shop.itbug.fluttercheckversionx.constance.discordUrl
import shop.itbug.fluttercheckversionx.constance.qqGroup
import shop.itbug.fluttercheckversionx.dialog.JsonToFreezedInputDialog
import shop.itbug.fluttercheckversionx.dialog.SearchDialog
import shop.itbug.fluttercheckversionx.i18n.PluginBundle
Expand Down Expand Up @@ -78,10 +79,32 @@ class GoToDiscordAction : AnAction() {

override fun update(e: AnActionEvent) {
e.presentation.isEnabled = e.project != null
e.project?.let {
e.presentation.isVisible = PluginConfig.getState(it).showDiscord
}
e.presentation.text = "Discord"
}
}

// open setting
class GoToQQGroupAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
BrowserUtil.browse(qqGroup)
}

override fun getActionUpdateThread(): ActionUpdateThread {
return ActionUpdateThread.BGT
}

override fun update(e: AnActionEvent) {
e.presentation.isEnabled = e.project != null
e.project?.let {
e.presentation.isVisible = PluginConfig.getState(it).showQQGroup
}
e.presentation.text = "QQ Group"
}
}

// go to Discord
// open setting
class GoToDocumentAction : AnAction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.jetbrains.lang.dart.psi.impl.DartClassDefinitionImpl
import shop.itbug.fluttercheckversionx.config.PluginConfig
import shop.itbug.fluttercheckversionx.constance.MyKeys
import shop.itbug.fluttercheckversionx.inlay.HintsInlayPresentationFactory
import shop.itbug.fluttercheckversionx.services.PubspecService
import shop.itbug.fluttercheckversionx.util.MyPsiElementUtil
import java.awt.event.MouseEvent
import javax.swing.JComponent
Expand All @@ -25,8 +26,9 @@ import javax.swing.JComponent
private fun PsiElement.needHandler(): Boolean {
val setting = PluginConfig.getState(project)
val config: List<String> = MyPsiElementUtil.getAllPlugins(project)
val hasRiverpod = PubspecService.getInstance(project).hasRiverpod()
val element = this
return setting.showRiverpodInlay && element is DartClassDefinitionImpl && config.contains("hooks_riverpod") && (element.superclass?.type?.text == "StatelessWidget" || element.superclass?.type?.text == "StatefulWidget")
return setting.showRiverpodInlay && element is DartClassDefinitionImpl && hasRiverpod && (element.superclass?.type?.text == "StatelessWidget" || element.superclass?.type?.text == "StatefulWidget")
}

class PsiElementEditorPopupMenuInlay : InlayHintsProvider<NoSettings> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.jetbrains.lang.dart.psi.impl.DartReturnTypeImpl
import com.jetbrains.lang.dart.psi.impl.DartSuperclassImpl
import com.jetbrains.lang.dart.util.DartElementGenerator
import shop.itbug.fluttercheckversionx.constance.MyKeys
import shop.itbug.fluttercheckversionx.util.MyDartPsiElementUtil


private fun AnActionEvent.getEditClassPsi(): DartClassDefinitionImpl? {
Expand Down Expand Up @@ -64,13 +65,13 @@ class StatefulToConsumerAction : AnAction() {

val psi = e.getData(CommonDataKeys.EDITOR)?.getUserData(MyKeys.DartClassKey)
val isClass = psi is DartClassDefinitionImpl

val psiFile = e.getData(CommonDataKeys.PSI_FILE) ?: return
val dartClassName =
if (isClass) (psi as DartClassDefinitionImpl).componentName else e.getData(CommonDataKeys.PSI_ELEMENT) as DartComponentNameImpl
if (isClass) psi.componentName else e.getData(CommonDataKeys.PSI_ELEMENT) as DartComponentNameImpl
val classDefinition =
if (isClass) psi as DartClassDefinitionImpl else dartClassName.parent as DartClassDefinitionImpl
if (isClass) psi else dartClassName.parent as DartClassDefinitionImpl


val psiFile = e.getData(CommonDataKeys.PSI_FILE)
e.project?.let { project ->
val className = dartClassName.name
WriteCommandAction.runWriteCommandAction(project) {
Expand All @@ -92,15 +93,14 @@ class StatefulToConsumerAction : AnAction() {
}

//3.替换 state
if (psiFile != null) {
val dartFile = psiFile as DartFile
val dartClassList = PsiTreeUtil.findChildrenOfType(dartFile, DartClassDefinitionImpl::class.java)
val findStateClass = dartClassList.find { it.superclass?.type?.text == "State<${className}>" }
WriteCommandAction.runWriteCommandAction(project) {
findStateClass?.superclass?.replace(project.createSuperclass(superClassName = "ConsumerState<$className>"))
}

val dartFile = psiFile as DartFile
val dartClassList = PsiTreeUtil.findChildrenOfType(dartFile, DartClassDefinitionImpl::class.java)
val findStateClass = dartClassList.find { it.superclass?.type?.text == "State<${className}>" }
WriteCommandAction.runWriteCommandAction(project) {
findStateClass?.superclass?.replace(project.createSuperclass(superClassName = "ConsumerState<$className>"))
}
//添加导入语句
MyDartPsiElementUtil.addRiverpodHookImport(psiFile, project)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ private fun AnActionEvent.isEnable(): Boolean {

///将组件转换成
class StatelessToConsumer : AnAction() {

override fun actionPerformed(e: AnActionEvent) {
val classElement = e.getEditorClass()
val namePsi = classElement?.componentName ?: e.getData(CommonDataKeys.PSI_ELEMENT)
val psiFile = e.getData(CommonDataKeys.PSI_FILE) ?: return


val project = e.project
if (namePsi is DartComponentNameImpl && namePsi.parent is DartClassDefinitionImpl
Expand All @@ -60,10 +63,8 @@ class StatelessToConsumer : AnAction() {
val context =
params.find { it.simpleFormalParameter?.type?.text == "BuildContext" }
context?.let { _ ->

method.formalParameterList.replace(newPsi)
}

///替换继承
parent.superclass?.type?.exByModifyPsiElementText("ConsumerWidget")
}
Expand All @@ -72,6 +73,8 @@ class StatelessToConsumer : AnAction() {
println("已经有了")
}

//添加导入语句
MyDartPsiElementUtil.addRiverpodHookImport(psiFile, project)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ data class PluginSetting(
var showAssetsIconInEditor: Boolean = true,
//缩放大小
var assetsIconSize: Int = 16,
) : BaseState()


//显示discord
var showDiscord: Boolean = true,
//显示qq群
var showQQGroup: Boolean = true,

//显示打赏action
var showRewardAction: Boolean = true,

) : BaseState()

@Service(Service.Level.PROJECT)
@State(name = "FlutterxFullConfig", storages = [Storage("FlutterxFullConfig.xml")])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ sealed class AppConfig {
data class FlutterIgScanPlugins(val igPlugins: List<String>) : AppConfig()
}

val qqGroup = AppConfig.QQGroup("706438100")//QQ群号
var igFlutterPlugin = AppConfig.FlutterIgScanPlugins(
listOf(
"flutter",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
package shop.itbug.fluttercheckversionx.constance


const val discordUrl = "https://discord.gg/ethKNxKRcZ"
const val discordUrl = "https://discord.gg/ethKNxKRcZ"
const val qqGroup = "https://qm.qq.com/q/3zYRrSC7zW"


object Links {
const val riverpod = "https://flutterx.itbug.shop/riverpod.html"
const val openIn =
"https://flutterx.itbug.shop/%E5%BF%AB%E9%80%9F%E6%89%93%E5%BC%80%E5%AD%90%E7%9B%AE%E5%BD%95%E6%96%87%E4%BB%B6%E5%A4%B9.html"

const val link = "https://flutterx.itbug.shop/links.html"
const val icons = "https://flutterx.itbug.shop/%E5%86%85%E8%81%94%E8%B5%84%E4%BA%A7%E6%98%BE%E7%A4%BA.html"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package shop.itbug.fluttercheckversionx.document

import com.intellij.lang.documentation.AbstractDocumentationProvider
import com.intellij.openapi.application.runReadAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.jetbrains.lang.dart.analyzer.DartAnalysisServerService
import com.jetbrains.lang.dart.psi.impl.*
import org.dartlang.analysis.server.protocol.HoverInformation
Expand All @@ -18,10 +20,13 @@ import shop.itbug.fluttercheckversionx.util.MyDartPsiElementUtil
class DartDocumentExt : AbstractDocumentationProvider() {


override fun generateDoc(element: PsiElement, originalElement: PsiElement?): String {
override fun generateDoc(element: PsiElement, originalElement: PsiElement?): String? {

val reference = element.parent?.parent?.reference?.resolve()
val result = DartAnalysisServerService.getInstance(element.project).analysis_getHover(
element.containingFile.virtualFile,
val file = element.containingFile.virtualFile ?: return null
val project = element.project
val result = DartAnalysisServerService.getInstance(project).analysis_getHover(
file,
element.textOffset
)
if (result.isEmpty()) return "Document not found"
Expand All @@ -30,14 +35,13 @@ class DartDocumentExt : AbstractDocumentationProvider() {
reference?.parent?.children?.filterIsInstance<DartFormalParameterListImpl>() ?: emptyList()
return renderView(
docInfo,
element.project,
project,
if (dartFormalParameterList.isEmpty()) null else dartFormalParameterList.first(),
element
)

}


data class DartParams(
val key: String,
val value: String,
Expand Down Expand Up @@ -87,7 +91,7 @@ class DartDocumentExt : AbstractDocumentationProvider() {
return dartNormalElementHandle(normal.first(), isRequired, true)
}

val paramsArr = arrayListOf<DartParams>()
val paramsArr = mutableListOf<DartParams>()


//获取必填参数节点,不是{}里面声明的, fun(String str){}
Expand Down Expand Up @@ -145,10 +149,9 @@ class DartDocumentExt : AbstractDocumentationProvider() {
eleText = params
}
if (eleText != null) {
val simpleText = "```dart\n" +
var simpleText = "```dart\n" +
(eleText) + "\n```\n"
Helper.addKeyValueHeader(sb)
println(simpleText)
sb.appendTag(
MyMarkdownDocRenderObject(text = simpleText, project = project),
PluginBundle.get("element")
Expand All @@ -175,9 +178,18 @@ class DartDocumentExt : AbstractDocumentationProvider() {
)
sb.appendTag(obj, PluginBundle.get("doc"))
}

Helper.addKeyValueFoot(sb)
return sb.toString()
}


override fun getCustomDocumentationElement(
editor: Editor,
file: PsiFile,
contextElement: PsiElement?,
targetOffset: Int
): PsiElement? {
println("get custom contextElement.")
return super.getCustomDocumentationElement(editor, file, contextElement, targetOffset)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package shop.itbug.fluttercheckversionx.document

import com.intellij.ide.projectView.ProjectView
import com.intellij.lang.documentation.AbstractDocumentationProvider
import com.intellij.lang.documentation.ExternalDocumentationHandler
import com.intellij.openapi.application.runReadAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.PsiManager
import org.jetbrains.annotations.Nls
import shop.itbug.fluttercheckversionx.util.DartPsiElementHelper
import java.io.File
import java.net.URI

/**
* dart文件中对字符串进行本机文件解析.
*/
class DartImageDocumentProvider : AbstractDocumentationProvider(), ExternalDocumentationHandler {

override fun generateDoc(element: PsiElement?, originalElement: PsiElement?): @Nls String? {
element ?: return null
originalElement ?: return null
return DartPsiElementHelper.generateLocalImageDocument(element)
}

override fun getCustomDocumentationElement(
editor: Editor,
file: PsiFile,
contextElement: PsiElement?,
targetOffset: Int
): PsiElement? {
contextElement ?: return null
return DartPsiElementHelper.findTargetFilePsiElement(contextElement)
}


///处理图片链接点击
override fun handleExternalLink(psiManager: PsiManager?, link: String?, context: PsiElement?): Boolean {
if (link != null && context != null && psiManager != null && link.startsWith("file:")) {
try {
val project = context.project
val uri = URI.create(link)
val file = runReadAction { LocalFileSystem.getInstance().findFileByIoFile(File(uri.path)) }
if (file != null) {
ProjectView.getInstance(project).select(null, file, true) //文件浏览器中打开
return true
}
} catch (_: Exception) {
}
}
return false
}

}
Loading

0 comments on commit 44043f7

Please sign in to comment.