Last active
September 20, 2025 13:41
-
-
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 hidden or 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.FORCE_HIGHLIGHTING | |
| import com.intellij.codeInsight.daemon.impl.analysis.FileHighlightingSetting.SKIP_HIGHLIGHTING | |
| 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 | |
| // See https://gist.github.com/dkandalov/da7f58c4b0cfbed4e3ee1cade3cc5174 | |
| registerAction("Toggle Highlighting", "ctrl shift H") { event -> | |
| toggleCurrentEditorHighlighting(event.project) | |
| } | |
| if (!isIdeStartup) show("Reloaded 'Toggle Highlighting'") | |
| fun toggleCurrentEditorHighlighting(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, SKIP_HIGHLIGHTING) | |
| } else { | |
| HighlightLevelUtil.forceRootHighlighting(psiFile, 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