Highlight files in diff view (KT-17892)
KT-17892 Fixed
This commit is contained in:
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.idea.caches.lightClasses.KtLightClassForDecompiledDe
|
||||
import org.jetbrains.kotlin.idea.core.isInTestSourceContentKotlinAware
|
||||
import org.jetbrains.kotlin.idea.core.script.ScriptDependenciesManager
|
||||
import org.jetbrains.kotlin.idea.core.script.scriptRelatedModuleName
|
||||
import org.jetbrains.kotlin.idea.highlighter.OutsidersPsiFileSupportUtils
|
||||
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil
|
||||
import org.jetbrains.kotlin.idea.util.isInSourceContentWithoutInjected
|
||||
import org.jetbrains.kotlin.idea.util.isKotlinBinary
|
||||
@@ -59,9 +60,7 @@ fun getLibrarySourcesModuleInfos(project: Project, virtualFile: VirtualFile) =
|
||||
)
|
||||
|
||||
fun getScriptRelatedModuleInfo(project: Project, virtualFile: VirtualFile): ModuleSourceInfo? {
|
||||
val projectFileIndex = ProjectFileIndex.SERVICE.getInstance(project)
|
||||
|
||||
val moduleRelatedModuleInfo = getModuleRelatedModuleInfo(projectFileIndex, virtualFile)
|
||||
val moduleRelatedModuleInfo = getModuleRelatedModuleInfo(project, virtualFile)
|
||||
if (moduleRelatedModuleInfo != null) {
|
||||
return moduleRelatedModuleInfo
|
||||
}
|
||||
@@ -167,7 +166,7 @@ private fun <T> PsiElement.collectInfos(c: ModuleInfoCollector<T>): T {
|
||||
?: return c.onFailure("Analyzing element of type ${this::class.java} in non-physical file $containingFile of type ${containingFile::class.java}\nText:\n$text")
|
||||
|
||||
if (containingKtFile?.isScript() == true) {
|
||||
getModuleRelatedModuleInfo(ProjectFileIndex.SERVICE.getInstance(project), virtualFile)?.let {
|
||||
getModuleRelatedModuleInfo(project, virtualFile)?.let {
|
||||
return c.onResult(it)
|
||||
}
|
||||
findScriptDefinition(virtualFile, project)?.let {
|
||||
@@ -207,14 +206,12 @@ private inline fun <T> collectInfosByVirtualFile(
|
||||
treatAsLibrarySource: Boolean,
|
||||
onOccurrence: (IdeaModuleInfo?) -> T
|
||||
): T {
|
||||
|
||||
val projectFileIndex = ProjectFileIndex.SERVICE.getInstance(project)
|
||||
|
||||
val moduleRelatedModuleInfo = getModuleRelatedModuleInfo(projectFileIndex, virtualFile)
|
||||
val moduleRelatedModuleInfo = getModuleRelatedModuleInfo(project, virtualFile)
|
||||
if (moduleRelatedModuleInfo != null) {
|
||||
onOccurrence(moduleRelatedModuleInfo)
|
||||
}
|
||||
|
||||
val projectFileIndex = ProjectFileIndex.SERVICE.getInstance(project)
|
||||
projectFileIndex.getOrderEntriesForFile(virtualFile).forEach {
|
||||
it.toIdeaModuleInfo(project, virtualFile, treatAsLibrarySource).map(onOccurrence)
|
||||
}
|
||||
@@ -235,7 +232,9 @@ private inline fun <T> collectInfosByVirtualFile(
|
||||
return onOccurrence(null)
|
||||
}
|
||||
|
||||
private fun getModuleRelatedModuleInfo(projectFileIndex: ProjectFileIndex, virtualFile: VirtualFile): ModuleSourceInfo? {
|
||||
private fun getModuleRelatedModuleInfo(project: Project, virtualFile: VirtualFile): ModuleSourceInfo? {
|
||||
val projectFileIndex = ProjectFileIndex.SERVICE.getInstance(project)
|
||||
|
||||
val module = projectFileIndex.getModuleForFile(virtualFile)
|
||||
if (module != null && !module.isDisposed) {
|
||||
val moduleFileIndex = ModuleRootManager.getInstance(module).fileIndex
|
||||
@@ -245,6 +244,12 @@ private fun getModuleRelatedModuleInfo(projectFileIndex: ProjectFileIndex, virtu
|
||||
return module.productionSourceInfo()
|
||||
}
|
||||
}
|
||||
|
||||
val fileOrigin = OutsidersPsiFileSupportUtils.getOutsiderFileOrigin(project, virtualFile)
|
||||
if (fileOrigin != null) {
|
||||
return getModuleRelatedModuleInfo(project, fileOrigin)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,10 @@ object KotlinHighlightingUtil {
|
||||
return shouldHighlightScript(ktFile)
|
||||
}
|
||||
|
||||
if (OutsidersPsiFileSupportWrapper.isOutsiderFile(ktFile.virtualFile)) {
|
||||
return true
|
||||
}
|
||||
|
||||
return ProjectRootsUtil.isInProjectOrLibraryContent(ktFile) && ktFile.getModuleInfo() !is NotUnderContentRootModuleInfo
|
||||
}
|
||||
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.highlighter
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.vfs.VfsUtil
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import java.io.File
|
||||
|
||||
object OutsidersPsiFileSupportUtils {
|
||||
fun getOutsiderFileOrigin(project: Project, virtualFile: VirtualFile): VirtualFile? {
|
||||
if (!OutsidersPsiFileSupportWrapper.isOutsiderFile(virtualFile)) return null
|
||||
|
||||
val originalFilePath = OutsidersPsiFileSupportWrapper.getOriginalFilePath(virtualFile) ?: return null
|
||||
|
||||
return generateSequence(File(originalFilePath)) { if (it.canonicalPath == project.baseDir.canonicalPath) null else it.parentFile }
|
||||
.filter { it.exists() }
|
||||
.firstOrNull()
|
||||
?.let { VfsUtil.findFileByIoFile(it, false) }
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.highlighter
|
||||
|
||||
import com.intellij.codeInsight.daemon.OutsidersPsiFileSupport
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
|
||||
object OutsidersPsiFileSupportWrapper {
|
||||
fun isOutsiderFile(virtualFile: VirtualFile): Boolean {
|
||||
return OutsidersPsiFileSupport.isOutsiderFile(virtualFile)
|
||||
}
|
||||
|
||||
fun getOriginalFilePath(virtualFile: VirtualFile): String? {
|
||||
return OutsidersPsiFileSupport.getOriginalFilePath(virtualFile)
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.highlighter
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
|
||||
object OutsidersPsiFileSupportWrapper {
|
||||
fun isOutsiderFile(virtualFile: VirtualFile): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
fun getOriginalFilePath(virtualFile: VirtualFile): String? {
|
||||
return null
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user