Skip to content

Commit

Permalink
部分细节更新,优化部分函数触发时机
Browse files Browse the repository at this point in the history
  • Loading branch information
mdddj committed Oct 24, 2024
1 parent 7d25aea commit 2bdef6c
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 21 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.

15 changes: 9 additions & 6 deletions .idea/workspace.xml

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

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

Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ import com.intellij.openapi.ui.popup.util.BaseListPopupStep
import com.intellij.psi.PsiElement
import com.intellij.ui.awt.RelativePoint
import icons.MyImages
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import shop.itbug.fluttercheckversionx.actions.PUB_URL
import shop.itbug.fluttercheckversionx.cache.DartPluginIgnoreConfig
import shop.itbug.fluttercheckversionx.i18n.PluginBundle
import shop.itbug.fluttercheckversionx.icons.MyIcons
import shop.itbug.fluttercheckversionx.services.DartPackageCheckService
import shop.itbug.fluttercheckversionx.services.DartPackageTaskParam
import shop.itbug.fluttercheckversionx.services.noused.DartNoUsedCheckService
import shop.itbug.fluttercheckversionx.util.MyFileUtil
import shop.itbug.fluttercheckversionx.util.getPluginName
import shop.itbug.fluttercheckversionx.util.isDartPluginElement
import shop.itbug.fluttercheckversionx.util.restartAnalyzer
Expand Down Expand Up @@ -58,9 +64,11 @@ data class PluginDartIconActionMenuItem(val title: String, val type: String, val

class PluginDartIconActionMenuList(val element: PsiElement) : BaseListPopupStep<PluginDartIconActionMenuItem>() {

private val project = element.project
private val virtualFile = element.containingFile.virtualFile
private val removeIgnoreText = PluginBundle.get("ignore_remove")
private val addIgnoreText = PluginBundle.get("ig.version.check")
private val igManager = DartPluginIgnoreConfig.getInstance(element.project)
private val igManager = DartPluginIgnoreConfig.getInstance(project)
private val pluginName = element.getPluginName()
private val isIgnored = igManager.isIg(pluginName)

Expand Down Expand Up @@ -92,6 +100,12 @@ class PluginDartIconActionMenuList(val element: PsiElement) : BaseListPopupStep<
return value?.title ?: "未知选项"
}

fun reIndexFile() {
project.restartAnalyzer()
MyFileUtil.reIndexFile(project, virtualFile)
}

@OptIn(DelicateCoroutinesApi::class)
override fun onChosen(selectedValue: PluginDartIconActionMenuItem?, finalChoice: Boolean): PopupStep<*>? {
when (selectedValue?.type) {
menus[0].type -> {
Expand All @@ -100,16 +114,24 @@ class PluginDartIconActionMenuList(val element: PsiElement) : BaseListPopupStep<

menus[1].type -> {
if (isIgnored) {
DartPluginIgnoreConfig.getInstance(element.project).remove(pluginName)
DartPluginIgnoreConfig.getInstance(project).remove(pluginName)

GlobalScope.launch {
DartPackageCheckService.getInstance(project).resetIndex(DartPackageTaskParam(false) {
reIndexFile()
})
}
} else {
DartPluginIgnoreConfig.getInstance(element.project).add(pluginName)
DartPluginIgnoreConfig.getInstance(project).add(pluginName)
DartPackageCheckService.getInstance(project).removeItemByPluginName(pluginName)
reIndexFile()
}

element.project.restartAnalyzer()

}

menus[2].type -> {
DartNoUsedCheckService.getInstance(element.project).openInBrowser(pluginName)
DartNoUsedCheckService.getInstance(project).openInBrowser(pluginName)
}
}
return super.onChosen(selectedValue, finalChoice)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ data class MyDartPackage(
}
}

typealias DartCheckTaskComplete = () -> Unit

data class DartPackageTaskParam(
val showNotification: Boolean = true,
val complete: DartCheckTaskComplete? = null
)

/**
* 项目包检测的服务类
*/
Expand Down Expand Up @@ -208,8 +215,9 @@ class DartPackageCheckService(val project: Project) {
MyFileUtil.reIndexPubspecFile(project)//重新索引
}


@OptIn(DelicateCoroutinesApi::class)
suspend fun startWithAsync(showNotification: Boolean = true) {
suspend fun startWithAsync(param: DartPackageTaskParam = DartPackageTaskParam()) {
val startTime = System.currentTimeMillis() // 获取起始时间
this.details.clear()
val list = getPackageInfos().filter { ignoreManager.isIg(it.packageName).not() }
Expand All @@ -220,13 +228,13 @@ class DartPackageCheckService(val project: Project) {
val endTime = System.currentTimeMillis() // 获取结束时间
GlobalScope.launch(Dispatchers.Main) {
project.messageBus.syncPublisher(FetchDartPackageFinishTopic).finish(results)///发送加载完成通知
if (showNotification) {
if (param.showNotification) {
getNotificationGroup()?.createNotification(
PluginBundle.get("refresh_success") + ", ${PluginBundle.get("package_size_is")}:${details.size} (${endTime - startTime}ms)",
NotificationType.INFORMATION
)?.notify(project)
}

param.complete?.invoke()
}
MyFileUtil.reIndexPubspecFile(project)//重新索引
}
Expand All @@ -240,11 +248,21 @@ class DartPackageCheckService(val project: Project) {
}


/**
* 删除某一个项目
*/
fun removeItemByPluginName(name: String) {
val find = details.find { it.first.packageName == name }
if (find != null) {
details.remove(find)
}
}

/**
* 重新索引
*/
suspend fun resetIndex(showNotification: Boolean = true) {
startWithAsync(showNotification)
suspend fun resetIndex(param: DartPackageTaskParam = DartPackageTaskParam()) {
startWithAsync(param)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class PubspecFileChangeListenAsync(val project: Project) : AsyncFileListener {
val filename = it.file?.name
if (filename != null && filename == "pubspec.yaml") {
println("文件发生变化::::::::::${filename}")
it.file?.let { file -> MyFileUtil.reIndexFile(file) }
it.file?.let { file -> MyFileUtil.reIndexFile(project, file) }
}
}

Expand Down
17 changes: 14 additions & 3 deletions src/main/kotlin/shop/itbug/fluttercheckversionx/util/MyFileUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package shop.itbug.fluttercheckversionx.util

import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer
import com.intellij.openapi.application.runReadAction
import com.intellij.openapi.project.DumbService
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.guessProjectDir
import com.intellij.openapi.startup.StartupManager
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.VirtualFileManager
Expand Down Expand Up @@ -101,15 +103,24 @@ object MyFileUtil {
*/
fun reIndexPubspecFile(project: Project) {
getPubspecVirtualFile(project)?.let { virtualFile ->
FileBasedIndex.getInstance().requestReindex(virtualFile)
StartupManager.getInstance(project).runAfterOpened {
DumbService.getInstance(project).runWhenSmart {
println("reindex pubspec.yaml")
FileBasedIndex.getInstance().requestReindex(virtualFile)
}
}
}
}

/**
* 重新索引指定文件
*/
fun reIndexFile(file: VirtualFile) {
FileBasedIndex.getInstance().requestReindex(file)
fun reIndexFile(project: Project, file: VirtualFile) {
StartupManager.getInstance(project).runAfterOpened {
DumbService.getInstance(project).runWhenSmart {
FileBasedIndex.getInstance().requestReindex(file)
}
}
}

/**
Expand Down

0 comments on commit 2bdef6c

Please sign in to comment.