This Question is Answered

2 "helpful" answers available (2 pts)
3 Replies Last post: Feb 12, 2010 11:12 PM by Andrew  
Jean Morissette Newbie 6 posts since
Feb 3, 2010
Currently Being Moderated

Feb 3, 2010 9:53 AM

PsiReference problem

Hi,
Using IDEA platform, I'm creating a plugin to edit and compile my custom SQL-like language. I wrote already a lexer and a parser, which create a PsiElement tree. Until there, all work well. Now, in order to support code completion later, I have to provide PsiReference for some of my PsiElement (right?). Thus, I started by writing LabeledExpression (see below). To check if it work, I run my plugin and I move the mouse over the text corresponding to LabeledExpression while pressing Ctrl. I'm expecting to see the text underlined in blue but instead nothing hapend. Also, it seems that only the getRangeInElement() is called. Is-it normal? Does the parent of LabeledExpression must also provide a PsiReference in order to work? Any help would be greatly appreciated.
<code>
public interface LabeledExpression extends Expression {
     String getLabel();
     PsiElement getExpression();
}
public class LabeledExpressionImpl extends ExpressionImpl implements LabeledExpression, PsiReference {
    public LabeledExpressionImpl(@NotNull ASTNode node) {
        super(node);
    }
    public String getLabel() {
        return getNode().findChildByType(TokenTypes.LABEL).getText();
    }
    public PsiElement getExpression() {
        return findChildByClass(PsiElement.class);
    }
 
    @Override public PsiReference getReference() {
        return this;
    }
     public PsiElement getElement() {
        return this;
    }
     public TextRange getRangeInElement() {
        TextRange range = getNode().getTextRange();
        return range;
    }
     public PsiElement resolve() {
        PsiElement target = findChildByType(ElementTypes.FIELD_ACCESS_EXPRESSION);
        return target;
    }
     public String getCanonicalText() {
        return null;
    }
     public PsiElement handleElementRename(java.lang.String s) throws com.intellij.util.IncorrectOperationException {
        return this;
    }
     public PsiElement bindToElement(@org.jetbrains.annotations.NotNull com.intellij.psi.PsiElement psiElement) throws com.intellij.util.IncorrectOperationException {
        return this;
    }
     public boolean isReferenceTo(PsiElement element) {
        return resolve() == element;
    }
     public Object[] getVariants() {
        return new Object[0];
    }
     public boolean isSoft() {
        return false;
    }
}
</code>
wallaby.pouch Novice 240 posts since
May 15, 2008
Currently Being Moderated
Feb 3, 2010 10:05 AM in response to: Jean Morissette
Re: PsiReference problem

HI,

Not sure if I can help.

I think getRangeInElement has to return the range inside of the element, starting with 0 if it's at the beginning.

 

For example:

 

<code>

    public TextRange getRangeInElement() {

        return TextRange.from(1, getText().length());
    }
</code>

Andrew  Newbie 1 posts since
Sep 23, 2006
Currently Being Moderated
Feb 12, 2010 11:12 PM in response to: wallaby.pouch
Re: PsiReference problem

Thank you. May be it will be more correctly to calc textRange from "0", I mean:      return TextRange.from(0, getText().length()-1);

More Like This

  • Retrieving data ...