Skip to content

Commit

Permalink
fixed file(...) includes from within sources or resources
Browse files Browse the repository at this point in the history
  • Loading branch information
ghik committed Oct 22, 2019
1 parent 6f8bc2f commit c0368f7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import java.{util => ju}
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots._
import com.intellij.openapi.util.{Condition, TextRange}
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi._
import com.intellij.psi.impl.source.resolve.reference.impl.providers.{FileReference, FileReferenceSet}
import com.intellij.psi.search.GlobalSearchScope
Expand Down Expand Up @@ -101,11 +102,9 @@ class IncludedFileReferenceSet(
item.getName.endsWith(ConfExt) || item.getName.endsWith(JsonExt) || item.getName.endsWith(PropsExt)

// code mostly based on similar bits in `FileReferenceSet` and `PsiFileReferenceHelper`
override def computeDefaultContexts: ju.Collection[PsiFileSystemItem] = {
override def computeDefaultContexts: JCollection[PsiFileSystemItem] = {
val empty = ju.Collections.emptyList[PsiFileSystemItem]

def single(fsi: PsiFileSystemItem) = ju.Collections.singletonList(fsi)

val cf = getContainingFile
if (cf == null) return empty

Expand All @@ -118,17 +117,20 @@ class IncludedFileReferenceSet(
val parent = vfile.getParent
if (parent == null) return empty

def single(vf: VirtualFile): JCollection[PsiFileSystemItem] =
PsiManager.getInstance(proj).findDirectory(vf).opt.fold(empty)(ju.Collections.singletonList)

val pfi = ProjectRootManager.getInstance(proj).getFileIndex
if (fromClasspath) {
val pfi = ProjectRootManager.getInstance(proj).getFileIndex
val pkgName =
if (isAbsolutePathReference) ""
else pfi.getPackageNameByDirectory(parent)

if (pkgName != null) classpathPackageDirs(proj, scope, pkgName).toJList else empty
} else if (isAbsolutePathReference) {
FileReferenceSet.getAbsoluteTopLevelDirLocations(containingFile)
single(pfi.getContentRootForFile(vfile))
} else {
Option(PsiManager.getInstance(proj).findDirectory(parent)).map(single).getOrElse(empty)
single(parent)
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions testdata/includes/multimodule/modC/src/including.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# modC/src/included.conf, modC/lib/included.conf
include "included"
# modC/src/included.conf
include file("src/included")

0 comments on commit c0368f7

Please sign in to comment.