Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jb] add inspections & quickfixes on .gitpod.yml vmoptions config #11089

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: enable run inspection on project start
  • Loading branch information
yaohui-wyh committed Aug 12, 2022
commit 72f42e5fa5eece1c0cc8a96753b280376951f13a
Original file line number Diff line number Diff line change
@@ -5,19 +5,31 @@
package io.gitpod.jetbrains.remote

import com.intellij.ProjectTopics
import com.intellij.analysis.AnalysisScope
import com.intellij.codeInspection.actions.RunInspectionIntention
import com.intellij.codeInspection.ex.InspectionManagerEx
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.module.Module
import com.intellij.openapi.module.ModuleManager
import com.intellij.openapi.project.DumbService
import com.intellij.openapi.project.ModuleListener
import com.intellij.openapi.project.Project
import com.intellij.openapi.projectRoots.ProjectJdkTable
import com.intellij.openapi.projectRoots.Sdk
import com.intellij.openapi.roots.ModuleRootModificationUtil
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.vfs.VfsUtil
import com.intellij.profile.codeInspection.InspectionProfileManager
import com.intellij.psi.PsiFile
import com.intellij.psi.PsiManager
import com.intellij.util.application
import io.gitpod.jetbrains.remote.inspections.GitpodConfigInspection
import io.gitpod.jetbrains.remote.utils.GitpodConfig.gitpodYamlFile
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.future.await
import kotlinx.coroutines.launch
import org.jetbrains.yaml.psi.YAMLFile
import java.nio.file.Paths
import java.util.concurrent.CompletableFuture


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

init {
application.invokeLater {
try {
runInspection()
} catch (ex: Exception) {
thisLogger().error("Failed to run inspection", ex)
}
}
}

private fun runInspection() {
val psiFile = getGitpodYamlPsiFile(project) ?: return
val profile = InspectionProfileManager.getInstance(project).currentProfile
val inspectionName = GitpodConfigInspection::class.java.simpleName
val tool = profile.getInspectionTool(inspectionName, psiFile) ?: return
val manager = InspectionManagerEx.getInstance(project) as InspectionManagerEx
val scope = AnalysisScope(psiFile)
DumbService.getInstance(project).smartInvokeLater {
RunInspectionIntention.rerunInspection(tool, manager, scope, psiFile)
}
}

private fun getGitpodYamlPsiFile(project: Project): PsiFile? {
val basePath = project.basePath ?: return null
val vfile = VfsUtil.findFile(Paths.get(basePath, gitpodYamlFile), true) ?: return null
return PsiManager.getInstance(project).findFile(vfile) as? YAMLFile ?: return null
}

/**
* It is a workaround for https://youtrack.jetbrains.com/issue/GTW-88
*/
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@
<projectService serviceImplementation="io.gitpod.jetbrains.remote.GitpodProjectManager" preload="true"/>
<gateway.customization.name implementation="io.gitpod.jetbrains.remote.GitpodGatewayClientCustomizationProvider"/>
<localInspection language="yaml" bundle="messages.GitpodBundle"
shortName="GitpodConfigInspection"
groupKey="inspections.group.name"
key="inspections.gitpod.schema.validation.name"
level="WARNING" enabledByDefault="true"