Search in sources :

Example 1 with DartNavigationRegion

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

the class InlineMethodDialog method findContext.

@Nullable
private static InlineRefactoringContext findContext(@Nullable Editor editor) {
    if (editor == null) {
        return null;
    }
    // prepare project
    final Project project = editor.getProject();
    if (project == null) {
        return null;
    }
    // prepare files
    final Document document = editor.getDocument();
    final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
    if (psiFile == null) {
        return null;
    }
    final VirtualFile virtualFile = psiFile.getVirtualFile();
    // prepare navigation regions
    final int offset = editor.getCaretModel().getOffset();
    final List<DartNavigationRegion> navigationRegions = DartAnalysisServerService.getInstance(project).getNavigation(virtualFile);
    // find the navigation region
    for (DartNavigationRegion region : navigationRegions) {
        if (region.getOffset() <= offset && offset <= region.getOffset() + region.getLength()) {
            final List<DartNavigationTarget> targets = region.getTargets();
            final String kind = targets.get(0).getKind();
            return new InlineRefactoringContext(virtualFile, offset, kind);
        }
    }
    // fail
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DartNavigationTarget(com.jetbrains.lang.dart.analyzer.DartServerData.DartNavigationTarget) DartNavigationRegion(com.jetbrains.lang.dart.analyzer.DartServerData.DartNavigationRegion) PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with DartNavigationRegion

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

the class DartResolver method processRegionsInRange.

public static void processRegionsInRange(@NotNull final List<DartServerData.DartNavigationRegion> regions, @NotNull final TextRange range, @NotNull final Consumer<DartNavigationRegion> processor) {
    if (regions.isEmpty())
        return;
    // first find the first region that has minimal allowed offset
    int low = 0;
    int high = regions.size() - 1;
    while (low < high) {
        int mid = (low + high) >>> 1;
        DartServerData.DartNavigationRegion midVal = regions.get(mid);
        int cmp = midVal.getOffset() - range.getStartOffset();
        if (cmp < 0) {
            low = Math.min(high, mid + 1);
        } else {
            high = Math.max(low, mid - 1);
        }
    }
    assert low == high : regions.size() + "," + low + "," + high;
    int i = low;
    DartNavigationRegion region = regions.get(i);
    if (region.getOffset() < range.getStartOffset()) {
        i++;
        if (i < regions.size()) {
            region = regions.get(i);
        } else {
            return;
        }
    }
    while (region.getOffset() + region.getLength() <= range.getEndOffset()) {
        processor.consume(region);
        i++;
        if (i < regions.size()) {
            region = regions.get(i);
        } else {
            return;
        }
    }
}
Also used : DartNavigationRegion(com.jetbrains.lang.dart.analyzer.DartServerData.DartNavigationRegion) DartNavigationRegion(com.jetbrains.lang.dart.analyzer.DartServerData.DartNavigationRegion) DartServerData(com.jetbrains.lang.dart.analyzer.DartServerData)

Example 3 with DartNavigationRegion

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

the class DartResolver method findRegion.

/**
   * Find the region with the given offset in the given list of sorted regions.
   * Returns the found region or null.
   */
@Nullable
public static DartNavigationRegion findRegion(@NotNull final List<DartServerData.DartNavigationRegion> regions, final int offset, final int length) {
    int low = 0;
    int high = regions.size() - 1;
    while (low <= high) {
        int mid = (low + high) >>> 1;
        DartServerData.DartNavigationRegion midVal = regions.get(mid);
        int cmp = midVal.getOffset() - offset;
        if (cmp < 0) {
            low = mid + 1;
        } else if (cmp > 0) {
            high = mid - 1;
        } else {
            if (midVal.getLength() == length) {
                return midVal;
            }
            return null;
        }
    }
    return null;
}
Also used : DartNavigationRegion(com.jetbrains.lang.dart.analyzer.DartServerData.DartNavigationRegion) DartServerData(com.jetbrains.lang.dart.analyzer.DartServerData) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with DartNavigationRegion

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

the class DartServerHighlightingTest method testNavigationTargetOffsetUpdated.

public void testNavigationTargetOffsetUpdated() {
    myFixture.configureByText(DartFileType.INSTANCE, "var a = 1; var b = a;");
    myFixture.doHighlighting();
    final DartAnalysisServerService service = DartAnalysisServerService.getInstance(getProject());
    final VirtualFile file = getFile().getVirtualFile();
    final List<DartNavigationRegion> regions = service.getNavigation(file);
    checkRegions(regions, TextRange.create(0, 3), TextRange.create(4, 5), TextRange.create(15, 16), TextRange.create(19, 20));
    assertEquals(4, regions.get(3).getTargets().get(0).getOffset(getProject(), file));
    getEditor().getCaretModel().moveToOffset(0);
    myFixture.type("foo \b");
    checkRegions(regions, TextRange.create(0 + 3, 3 + 3), TextRange.create(4 + 3, 5 + 3), TextRange.create(15 + 3, 16 + 3), TextRange.create(19 + 3, 20 + 3));
    assertEquals(4 + 3, regions.get(3).getTargets().get(0).getOffset(getProject(), file));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartNavigationRegion(com.jetbrains.lang.dart.analyzer.DartServerData.DartNavigationRegion) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService)

Example 5 with DartNavigationRegion

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

the class DartCalleeTreeStructure method getCallees.

private static void getCallees(@NotNull PsiElement element, @NotNull List<PsiElement> results) {
    DartComponentName name = (DartComponentName) element;
    DartComponent decl = (DartComponent) name.getParent();
    PsiFile file = decl.getContainingFile();
    if (file == null)
        return;
    VirtualFile vFile = file.getVirtualFile();
    List<DartNavigationRegion> navRegions = DartAnalysisServerService.getInstance(element.getProject()).analysis_getNavigation(vFile, decl.getTextOffset(), decl.getTextLength());
    if (navRegions == null)
        return;
    resolveReferences(decl, navRegions, results);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartComponentName(com.jetbrains.lang.dart.psi.DartComponentName) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) DartNavigationRegion(com.jetbrains.lang.dart.analyzer.DartServerData.DartNavigationRegion) PsiFile(com.intellij.psi.PsiFile)

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