Last active
August 21, 2019 19:06
-
-
Save dkandalov/da7f58c4b0cfbed4e3ee1cade3cc5174 to your computer and use it in GitHub Desktop.
Plugin for toggling syntax highlighting in the current file (same as built-in "Highlighting level" slider in the inspector popup)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer | |
import com.intellij.codeInsight.daemon.impl.analysis.FileHighlightingSetting | |
import com.intellij.codeInsight.daemon.impl.analysis.HighlightLevelUtil | |
import com.intellij.codeInsight.daemon.impl.analysis.HighlightingLevelManager | |
import com.intellij.lang.injection.InjectedLanguageManager | |
import com.intellij.openapi.project.Project | |
import liveplugin.PluginUtil | |
import liveplugin.currentFile | |
import liveplugin.registerAction | |
import liveplugin.show | |
registerAction("Toggle Highlighting", "ctrl shift H") { event -> | |
toggleCurrentEditorHightlighting(event.project) | |
} | |
if (!isIdeStartup) show("Reloaded 'Toggle Highlighting'") | |
fun toggleCurrentEditorHightlighting(project: Project?) { | |
if (project == null) return | |
val virtualFile = project.currentFile ?: return | |
val psiFile = PluginUtil.psiFile(virtualFile, project) ?: return | |
val manager = HighlightingLevelManager.getInstance(project) | |
val isSyntaxHighlightingEnabled = manager.shouldHighlight(psiFile) | |
val isInspectionsHighlightingEnabled = manager.shouldInspect(psiFile) | |
if (isSyntaxHighlightingEnabled && isInspectionsHighlightingEnabled) { | |
HighlightLevelUtil.forceRootHighlighting(psiFile, FileHighlightingSetting.SKIP_HIGHLIGHTING) | |
} else { | |
HighlightLevelUtil.forceRootHighlighting(psiFile, FileHighlightingSetting.FORCE_HIGHLIGHTING) | |
} | |
InjectedLanguageManager.getInstance(project).dropFileCaches(psiFile) | |
DaemonCodeAnalyzer.getInstance(project).restart() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment