Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.intellij.lang.annotation.AnnotationHolder
import com.intellij.lang.annotation.Annotator
import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.psi.PsiElement
import net.sjrx.intellij.plugins.systemdunitfiles.intentions.EnablePodmanQuadletSupportQuickFix
import net.sjrx.intellij.plugins.systemdunitfiles.intentions.EnablePodmanQuadletSupportIntention
import net.sjrx.intellij.plugins.systemdunitfiles.psi.UnitFileSectionType
import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.SemanticDataRepository
import net.sjrx.intellij.plugins.systemdunitfiles.settings.shouldSuggestPodmanSupport
Expand Down Expand Up @@ -43,7 +43,7 @@ class InvalidSectionHeaderNameAnnotator : Annotator {
val annotation = holder.newAnnotation(HighlightSeverity.ERROR, errorString).range(element.getFirstChild())

if (shouldSuggestPodmanSupport(element.containingFile)) {
annotation.withFix(EnablePodmanQuadletSupportQuickFix())
annotation.withFix(EnablePodmanQuadletSupportIntention())
}

annotation.create()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,30 @@ import com.intellij.psi.PsiFile
import com.intellij.ui.EditorNotifications
import net.sjrx.intellij.plugins.systemdunitfiles.settings.PodmanQuadletSettings

class EnablePodmanQuadletSupportQuickFix : LocalQuickFix, IntentionAction {
private fun enablePodmanSupport(project: Project) {
PodmanQuadletSettings.getInstance(project).state.enabled = true
EditorNotifications.getInstance(project).updateAllNotifications()
DaemonCodeAnalyzer.getInstance(project).restart()
}

/**
* LocalQuickFix for use with inspections (ProblemsHolder.registerProblem).
*/
class EnablePodmanQuadletSupportQuickFix : LocalQuickFix {

override fun getFamilyName(): String = "Enable Podman Quadlet support (experimental)"

override fun startInWriteAction(): Boolean = false

override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
enablePodmanSupport(project)
}
}

/**
* IntentionAction for use with annotators (AnnotationBuilder.withFix).
*/
class EnablePodmanQuadletSupportIntention : IntentionAction {

override fun getFamilyName(): String = "Enable Podman Quadlet support (experimental)"

Expand All @@ -23,14 +46,4 @@ class EnablePodmanQuadletSupportQuickFix : LocalQuickFix, IntentionAction {
override fun invoke(project: Project, editor: Editor?, file: PsiFile?) {
enablePodmanSupport(project)
}

override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
enablePodmanSupport(project)
}

private fun enablePodmanSupport(project: Project) {
PodmanQuadletSettings.getInstance(project).state.enabled = true
EditorNotifications.getInstance(project).updateAllNotifications()
DaemonCodeAnalyzer.getInstance(project).restart()
}
}
Loading