Skip to content

Commit

Permalink
properly excluding HOCON files in library sources from Find Usages
Browse files Browse the repository at this point in the history
  • Loading branch information
ghik committed Oct 18, 2019
1 parent 7eff333 commit 35b8633
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
3 changes: 2 additions & 1 deletion resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
implementationClass="org.jetbrains.plugins.hocon.navigation.HoconFindUsagesProvider"/>
<findUsagesHandlerFactory
implementation="org.jetbrains.plugins.hocon.navigation.HoconFindUsagesHandlerFactory"/>
<useScopeEnlarger implementation="org.jetbrains.plugins.hocon.navigation.HoconUseScopeEnlarger"/>
<useScopeEnlarger implementation="org.jetbrains.plugins.hocon.navigation.HoconUseScopeAdjuster"/>
<useScopeOptimizer implementation="org.jetbrains.plugins.hocon.navigation.HoconUseScopeAdjuster"/>
<highlightUsagesHandlerFactory
implementation="org.jetbrains.plugins.hocon.highlight.HoconHighlightUsagesHandlerFactory"/>
<readWriteAccessDetector implementation="org.jetbrains.plugins.hocon.navigation.HoconReadWriteAccessDetector"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import com.intellij.lang.HelpID
import com.intellij.lang.cacheBuilder.{DefaultWordsScanner, WordsScanner}
import com.intellij.lang.findUsages.FindUsagesProvider
import com.intellij.openapi.application.ReadAction
import com.intellij.openapi.roots.ProjectFileIndex
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiElement
import com.intellij.psi.search.{GlobalSearchScope, ProjectAndLibrariesScope, SearchScope, UseScopeEnlarger}
import com.intellij.psi.search._
import com.intellij.psi.tree.TokenSet
import com.intellij.usageView.UsageInfo
import com.intellij.util.Processor
Expand Down Expand Up @@ -97,14 +98,23 @@ object HoconFindUsagesHandler {
} yield occkey
}

class HoconUseScopeEnlarger extends UseScopeEnlarger {
class HoconUseScopeAdjuster extends UseScopeEnlarger with ScopeOptimizer {
def getAdditionalUseScope(element: PsiElement): SearchScope = element match {
// HOCON properties represent paths which can be used anywhere
case fk: HFieldKey => new ProjectAndLibrariesScope(fk.getProject) {
// exclude HOCON files from library sources
override def contains(file: VirtualFile): Boolean = super.contains(file) &&
(file.getFileType != HoconFileType || !myProjectFileIndex.isInLibrarySource(file))
}
// HOCON properties represent paths which can be used anywhere in the project
case fk: HFieldKey => ProjectScope.getAllScope(fk.getProject)
case _ => null
}

override def getRestrictedUseScope(element: PsiElement): SearchScope = element match {
case hk: HFieldKey =>
val project = hk.getProject
val pfi = ProjectFileIndex.getInstance(project)
new EverythingGlobalScope(project) {
// HOCON files in library sources are just duplicates of the same HOCON files in regular library jars
override def contains(file: VirtualFile): Boolean =
!(file.getFileType == HoconFileType && pfi.isInLibrarySource(file))
}
case _ =>
super.getRestrictedUseScope(element)
}
}

0 comments on commit 35b8633

Please sign in to comment.