Skip to content

Commit

Permalink
use local file context for resolution of config paths in HOCON string…
Browse files Browse the repository at this point in the history
… values
  • Loading branch information
ghik committed Oct 17, 2019
1 parent 2b53a97 commit 7eff333
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.util.TextRange
import com.intellij.psi._
import com.intellij.util.ProcessingContext
import org.jetbrains.plugins.hocon.psi.{HFieldKey, HoconPsiElementFactory}
import org.jetbrains.plugins.hocon.psi.{HFieldKey, HoconPsiElementFactory, HoconPsiFile}
import org.jetbrains.plugins.hocon.semantics.{ResOpts, ToplevelCtx}
import org.jetbrains.plugins.hocon.settings.HoconProjectSettings

Expand Down Expand Up @@ -68,12 +68,15 @@ class HoconPropertyReference(
def getElement: PsiElement = lit
def getRangeInElement: TextRange = range

// TODO: resolve with respect to local file if literal is inside HOCON file
def resolve(): PsiElement =
ToplevelCtx(lit, ToplevelCtx.ApplicationResource)
.occurrences(fullPath, ResOpts(reverse = true))
.nextOption.flatMap(_.ancestorField(reverseIndex))
.map(_.hkey).orNull
def createContext: ToplevelCtx = lit.getContainingFile match {
case hf: HoconPsiFile => ToplevelCtx(hf)
case _ => ToplevelCtx(lit, ToplevelCtx.ApplicationResource)
}

def resolve(): PsiElement = createContext
.occurrences(fullPath, ResOpts(reverse = true))
.nextOption.flatMap(_.ancestorField(reverseIndex))
.map(_.hkey).orNull

override def getVariants: Array[AnyRef] = {
val toplevelCtx = ToplevelCtx(lit, ToplevelCtx.ApplicationResource)
Expand Down

0 comments on commit 7eff333

Please sign in to comment.