holder.registerProblem doesn't work

Answered
/**
* yaml 版本自动补全
*/
class AutoVersionTool : LocalInspectionTool() {

/// 访问了文件
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {
return YamlElementVisitor(holder)
}
}

class YamlElementVisitor(
private val holder: ProblemsHolder
) : PsiElementVisitor() {

override fun visitFile(file: PsiFile) {


ProgressManager.getInstance().run(object : Task.Backgroundable(holder.project, "检测插件中") {
override fun run(progressIndicator: ProgressIndicator) {
runBlocking {
launch {
val yamlFileParser = YamlFileParser(file, holder)
val list = yamlFileParser.startCheckFile()
if(list.isNotEmpty()){
SwingUtilities.invokeLater {
regProblem(list,file) // doesn't work here
}
}

}
}

}
})


super.visitFile(file)

}


/**
* 问题注册器,并新增快速修复功能更
*/
private fun regProblem(plugins: List<PluginVersion>,file: PsiFile) {
plugins.map { plugin ->
// 有新版本了,注册问题快捷修复
val findElementAt = file.findElementAt(plugin.startIndex)!!

holder.registerProblem(
findElementAt,
"当前插件有新版本:${plugin.newVersion}",
ProblemHighlightType.WARNING,
NewVersinFix(file.findElementAt(plugin.startIndex)!!, plugin.newVersion)
)
}
}

}

 

Please is there any way to use holder.registerProblem in Task.Backgroundable

 

 

1 comment
Comment actions Permalink

Hi,

Sorry, but your code looks overcomplicated.

Why are you trying to achieve? What is your exact use case? Why are you trying to run tasks from inspection?

0

Please sign in to leave a comment.