Skip to content

Commit 49a4935

Browse files
yaohui-wyhrogeryhwang
authored and
rogeryhwang
committed
feat: enable run inspection on project start
1 parent df323e8 commit 49a4935

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/GitpodProjectManager.kt

+40
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,31 @@
55
package io.gitpod.jetbrains.remote
66

77
import com.intellij.ProjectTopics
8+
import com.intellij.analysis.AnalysisScope
9+
import com.intellij.codeInspection.actions.RunInspectionIntention
10+
import com.intellij.codeInspection.ex.InspectionManagerEx
811
import com.intellij.openapi.diagnostic.thisLogger
912
import com.intellij.openapi.module.Module
1013
import com.intellij.openapi.module.ModuleManager
14+
import com.intellij.openapi.project.DumbService
1115
import com.intellij.openapi.project.ModuleListener
1216
import com.intellij.openapi.project.Project
1317
import com.intellij.openapi.projectRoots.ProjectJdkTable
1418
import com.intellij.openapi.projectRoots.Sdk
1519
import com.intellij.openapi.roots.ModuleRootModificationUtil
1620
import com.intellij.openapi.roots.ProjectRootManager
21+
import com.intellij.openapi.vfs.VfsUtil
22+
import com.intellij.profile.codeInspection.InspectionProfileManager
23+
import com.intellij.psi.PsiFile
24+
import com.intellij.psi.PsiManager
1725
import com.intellij.util.application
26+
import io.gitpod.jetbrains.remote.inspections.GitpodConfigInspection
27+
import io.gitpod.jetbrains.remote.utils.GitpodConfig.gitpodYamlFile
1828
import kotlinx.coroutines.GlobalScope
1929
import kotlinx.coroutines.future.await
2030
import kotlinx.coroutines.launch
31+
import org.jetbrains.yaml.psi.YAMLFile
32+
import java.nio.file.Paths
2133
import java.util.concurrent.CompletableFuture
2234

2335

@@ -29,6 +41,34 @@ class GitpodProjectManager(
2941
configureSdks()
3042
}
3143

44+
init {
45+
application.invokeLater {
46+
try {
47+
runInspection()
48+
} catch (ex: Exception) {
49+
thisLogger().error("Failed to run inspection", ex)
50+
}
51+
}
52+
}
53+
54+
private fun runInspection() {
55+
val psiFile = getGitpodYamlPsiFile(project) ?: return
56+
val profile = InspectionProfileManager.getInstance(project).currentProfile
57+
val inspectionName = GitpodConfigInspection::class.java.simpleName
58+
val tool = profile.getInspectionTool(inspectionName, psiFile) ?: return
59+
val manager = InspectionManagerEx.getInstance(project) as InspectionManagerEx
60+
val scope = AnalysisScope(psiFile)
61+
DumbService.getInstance(project).smartInvokeLater {
62+
RunInspectionIntention.rerunInspection(tool, manager, scope, psiFile)
63+
}
64+
}
65+
66+
private fun getGitpodYamlPsiFile(project: Project): PsiFile? {
67+
val basePath = project.basePath ?: return null
68+
val vfile = VfsUtil.findFile(Paths.get(basePath, gitpodYamlFile), true) ?: return null
69+
return PsiManager.getInstance(project).findFile(vfile) as? YAMLFile ?: return null
70+
}
71+
3272
/**
3373
* It is a workaround for https://youtrack.jetbrains.com/issue/GTW-88
3474
*/

components/ide/jetbrains/backend-plugin/src/main/resources/META-INF/plugin.xml

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<projectService serviceImplementation="io.gitpod.jetbrains.remote.GitpodProjectManager" preload="true"/>
3232
<gateway.customization.name implementation="io.gitpod.jetbrains.remote.GitpodGatewayClientCustomizationProvider"/>
3333
<localInspection language="yaml" bundle="messages.GitpodBundle"
34+
shortName="GitpodConfigInspection"
3435
groupKey="inspections.group.name"
3536
key="inspections.gitpod.schema.validation.name"
3637
level="WARNING" enabledByDefault="true"

0 commit comments

Comments
 (0)