Skip to content

Commit

Permalink
attempt to fix disabled highlighting in liveplugins
Browse files Browse the repository at this point in the history
  • Loading branch information
dkandalov committed Feb 20, 2023
1 parent 191c255 commit 6d619d9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/main/liveplugin/implementation/LivePlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ fun List<FilePath>.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
Expand Down
6 changes: 3 additions & 3 deletions src/main/liveplugin/implementation/ide-extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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" }
}
}
Expand Down

0 comments on commit 6d619d9

Please sign in to comment.