forked from cjllanwarne/winstanley
-
Notifications
You must be signed in to change notification settings - Fork 4
/
WdlDeclarationReference.scala
41 lines (35 loc) · 1.71 KB
/
WdlDeclarationReference.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package winstanley.references
import javax.annotation.Nullable
import com.intellij.openapi.util.TextRange
import com.intellij.psi.{PsiElement, PsiReferenceBase}
import winstanley.psi.WdlVariableLookup
import winstanley.structure.WdlImplicits._
final case class WdlDeclarationReference(value: WdlVariableLookup) extends PsiReferenceBase[PsiElement](value, value.getTextRange){
/**
* Returns the element which is the target of the reference !!! OR NULL IF NOT FOUND !!!
*
* @return the target element, or null if it was not possible to resolve the reference to a valid target.
* @see PsiPolyVariantReference#multiResolve(boolean)
*/
@Nullable
override def resolve(): PsiElement = {
value.findDeclarationsAvailableInScope.find(d => value.getIdentifierNode.exists(_.getText == d.getNameIdentifier.getText)).map(_.getNameIdentifier).orNull
}
/**
* Returns the array of String, PsiElement and/or LookupElement
* instances representing all identifiers that are visible at the location of the reference. The contents
* of the returned array is used to build the lookup list for basic code completion. (The list
* of visible identifiers may not be filtered by the completion prefix string - the
* filtering is performed later by IDEA core.)
*
* @return the array of available identifiers.
*/
override def getVariants: Array[AnyRef] = Array.empty[AnyRef]
/**
* This override is required to make reference-lookup work.
*
* It needs a relative range within the PsiElement 'value' to count as the reference,
* which in this case is the entire 'WdlVariableLookup' element.
*/
override def getRangeInElement: TextRange = new TextRange(0, value.getTextLength - 1)
}