Search in sources :

Example 6 with DartNavigationRegion

use of com.jetbrains.lang.dart.analyzer.DartServerData.DartNavigationRegion in project intellij-plugins by JetBrains.

the class DartCalleeTreeStructure method getRegionAt.

@NotNull
private static List<DartNavigationTarget> getRegionAt(int offset, @NotNull List<DartNavigationRegion> regions) {
    for (DartNavigationRegion region : regions) {
        int targetStart = region.getOffset();
        int targetEnd = targetStart + region.getLength();
        if (offset >= targetStart && offset <= targetEnd) {
            return region.getTargets();
        }
    }
    return new ArrayList<>(0);
}
Also used : DartNavigationRegion(com.jetbrains.lang.dart.analyzer.DartServerData.DartNavigationRegion) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with DartNavigationRegion

use of com.jetbrains.lang.dart.analyzer.DartServerData.DartNavigationRegion in project intellij-plugins by JetBrains.

the class DartResolver method resolve.

@Nullable
@Override
public List<? extends PsiElement> resolve(@NotNull DartReference reference, boolean incompleteCode) {
    reference = replaceQualifiedReferenceWithLast(reference);
    final PsiFile refPsiFile = reference.getContainingFile();
    int refOffset = reference.getTextRange().getStartOffset();
    int refLength = reference.getTextRange().getLength();
    DartNavigationRegion region = findRegion(refPsiFile, refOffset, refLength);
    if (region == null && reference instanceof DartLibraryId) {
        // DAS returns the whole "part of foo" as a region, but we have only "foo" as a reference
        final PsiElement parent = reference.getParent();
        if (parent instanceof DartPartOfStatement) {
            refOffset = parent.getTextRange().getStartOffset();
            refLength = reference.getTextRange().getEndOffset() - refOffset;
            region = findRegion(refPsiFile, refOffset, refLength);
        }
    }
    if (region == null && (reference instanceof DartSuperExpression || reference instanceof DartReferenceExpression)) {
        // DAS from SDK 1.13- returns 'super.foo' as a single range; SDK 1.14 returns 'super' and 'foo' separately.
        final PsiElement parent = reference.getParent();
        if (parent instanceof DartSuperCallOrFieldInitializer) {
            final List<DartExpression> expressions = ((DartSuperCallOrFieldInitializer) parent).getExpressionList();
            if (expressions.size() == 2 && expressions.get(0) instanceof DartSuperExpression && expressions.get(1) instanceof DartReferenceExpression) {
                refOffset = expressions.get(0).getTextRange().getStartOffset();
                refLength = expressions.get(1).getTextRange().getEndOffset() - refOffset;
                region = findRegion(refPsiFile, refOffset, refLength);
            }
        }
    }
    return region != null ? getTargetElements(reference.getProject(), region) : null;
}
Also used : DartNavigationRegion(com.jetbrains.lang.dart.analyzer.DartServerData.DartNavigationRegion) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

DartNavigationRegion (com.jetbrains.lang.dart.analyzer.DartServerData.DartNavigationRegion)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiFile (com.intellij.psi.PsiFile)3 Nullable (org.jetbrains.annotations.Nullable)3 DartServerData (com.jetbrains.lang.dart.analyzer.DartServerData)2 Document (com.intellij.openapi.editor.Document)1 Project (com.intellij.openapi.project.Project)1 PsiElement (com.intellij.psi.PsiElement)1 DartAnalysisServerService (com.jetbrains.lang.dart.analyzer.DartAnalysisServerService)1 DartNavigationTarget (com.jetbrains.lang.dart.analyzer.DartServerData.DartNavigationTarget)1 DartComponent (com.jetbrains.lang.dart.psi.DartComponent)1 DartComponentName (com.jetbrains.lang.dart.psi.DartComponentName)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1