-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resources are now resolved also relatively to the module source roots
- Loading branch information
Showing
10 changed files
with
76 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# IntelliJ | ||
/.idea/workspace.xml | ||
lib |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Fri Jan 08 23:31:54 CET 2016 | ||
#Sun Jan 10 21:24:06 CET 2016 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 28 additions & 10 deletions
38
src/main/scala/amailp/intellij/robot/psi/reference/ResourceValueReference.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,36 @@ | ||
package amailp.intellij.robot.psi.reference | ||
|
||
import com.intellij.psi.{PsiElement, PsiReferenceBase} | ||
import amailp.intellij.robot.psi.ResourceValue | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import amailp.intellij.robot.psi.utils.ExtRobotPsiUtils | ||
import amailp.intellij.robot.psi.{ResourceValue, RobotPsiFile} | ||
import com.intellij.openapi.module.ModuleUtilCore | ||
import com.intellij.openapi.roots.ModuleRootManager | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import com.intellij.psi.{PsiElement, PsiReferenceBase} | ||
|
||
class ResourceValueReference(element: ResourceValue) extends PsiReferenceBase[ResourceValue](element) with ExtRobotPsiUtils { | ||
override def resolve() = { | ||
Option[VirtualFile](currentDirectory.findFileByRelativePath(getElement.getText)) match { | ||
case Some(targetFile) => psiManager.findFile(targetFile) | ||
case None => null | ||
} | ||
} | ||
|
||
override def resolve() = resolveReferenceValue().orNull | ||
override def getVariants: Array[AnyRef] = Array() | ||
override def utilsPsiElement: PsiElement = getElement | ||
|
||
def resolveReferenceValue(): Option[RobotPsiFile] = | ||
resolveLocalFile orElse resolveAbsoluteFile orElse resolveFromSourceRoots | ||
|
||
private def resolveLocalFile: Option[RobotPsiFile] = | ||
maybeToRobotPsiFile(Option(currentDirectory.findFileByRelativePath(getElement.getText))) | ||
|
||
private def resolveAbsoluteFile: Option[RobotPsiFile] = | ||
maybeToRobotPsiFile(Option(currentFile.getFileSystem.findFileByPath(getElement.getText))) | ||
|
||
private def resolveFromSourceRoots: Option[RobotPsiFile] = { | ||
def sourceRoots = ModuleRootManager.getInstance(ModuleUtilCore.findModuleForPsiElement(getElement)).getSourceRoots(true).toList | ||
sourceRoots.map(s => maybeToRobotPsiFile(Option(s.findFileByRelativePath(getElement.getText)))) | ||
.foldLeft(None: Option[RobotPsiFile])((a, b) => a orElse b) | ||
} | ||
|
||
private def maybeToRobotPsiFile(file: Option[VirtualFile]): Option[RobotPsiFile] = | ||
file.flatMap(f => | ||
Option(psiManager.findFile(f)) | ||
.filter(_.isInstanceOf[RobotPsiFile]) | ||
.map(_.asInstanceOf[RobotPsiFile]) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters