From 6d619d99c6613757ed629572e2651f09e43f61df Mon Sep 17 00:00:00 2001 From: Dmitry Kandalov Date: Mon, 20 Feb 2023 11:53:47 +0000 Subject: [PATCH] attempt to fix disabled highlighting in liveplugins --- src/main/liveplugin/implementation/LivePlugin.kt | 3 +++ src/main/liveplugin/implementation/ide-extensions.kt | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/liveplugin/implementation/LivePlugin.kt b/src/main/liveplugin/implementation/LivePlugin.kt index 09e5df50..dff18137 100644 --- a/src/main/liveplugin/implementation/LivePlugin.kt +++ b/src/main/liveplugin/implementation/LivePlugin.kt @@ -29,6 +29,9 @@ fun List.toLivePlugins() = private tailrec fun FilePath.findParentPluginFolder(): FilePath? = if (isPluginFolder()) this else parent?.findParentPluginFolder() +fun FilePath.isPartOfPlugin(): Boolean = + findParentPluginFolder() != null + fun FilePath.isPluginFolder(): Boolean { if (!isDirectory && exists()) return false val parentPath = parent ?: return false diff --git a/src/main/liveplugin/implementation/ide-extensions.kt b/src/main/liveplugin/implementation/ide-extensions.kt index cde4eb13..1ed5ebf5 100644 --- a/src/main/liveplugin/implementation/ide-extensions.kt +++ b/src/main/liveplugin/implementation/ide-extensions.kt @@ -78,12 +78,12 @@ class LivePluginDirectoryCompletionContributor : CreateDirectoryCompletionContri // Workaround for https://youtrack.jetbrains.com/issue/IDEA-125379 class MakePluginFilesAlwaysEditable : NonProjectFileWritingAccessExtension { - override fun isWritable(file: VirtualFile) = file.toFilePath().isPluginFolder() + override fun isWritable(file: VirtualFile) = file.toFilePath().isPartOfPlugin() } class EnableSyntaxHighlighterInLivePlugins : SyntaxHighlighterProvider { override fun create(fileType: FileType, project: Project?, file: VirtualFile?): SyntaxHighlighter? { - if (project == null || file == null || !file.toFilePath().isPluginFolder()) return null + if (project == null || file == null || !file.toFilePath().isPartOfPlugin()) return null val language = LanguageUtil.getLanguageForPsi(project, file) ?: return null return SyntaxHighlighterFactory.getSyntaxHighlighter(language, project, file) } @@ -94,7 +94,7 @@ object FindUsageInLivePlugin { class UsageTypeExtension : UsageTypeProvider { override fun getUsageType(element: PsiElement): UsageType? { val file = PsiUtilCore.getVirtualFile(element) - return if (file == null || !file.toFilePath().isPluginFolder()) null + return if (file == null || !file.toFilePath().isPartOfPlugin()) null else UsageType { "Usage in liveplugin" } } }