Search in sources :

Example 6 with DartAnalysisServerService

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

the class DartServerHighlightingTest method testServerDataUpdateOnPaste.

public void testServerDataUpdateOnPaste() {
    initServerDataTest();
    final DartAnalysisServerService service = DartAnalysisServerService.getInstance(getProject());
    final VirtualFile file = getFile().getVirtualFile();
    checkServerDataInitialState(file);
    CopyPasteManager.getInstance().setContents(new StringSelection("long text 012345678901234567890123456789"));
    // paste a lot at the beginning of the region
    getEditor().getCaretModel().moveToOffset(27);
    myFixture.performEditorAction(IdeActions.ACTION_EDITOR_PASTE);
    checkRegions(service.getNavigation(file), TextRange.create(7, 18), TextRange.create(67, 78), TextRange.create(87, 98));
    checkRegions(service.getHighlight(file), TextRange.create(0, 19), TextRange.create(0, 6), TextRange.create(7, 18), TextRange.create(20, 79), TextRange.create(20, 26), TextRange.create(67, 78), TextRange.create(80, 99), TextRange.create(80, 86), TextRange.create(87, 98));
    undoAndUpdateHighlighting(file);
    // paste a lot in the middle of the region
    getEditor().getCaretModel().moveToOffset(29);
    myFixture.performEditorAction(IdeActions.ACTION_EDITOR_PASTE);
    checkRegions(service.getNavigation(file), TextRange.create(7, 18), /*TextRange.create(28, 39),*/
    TextRange.create(87, 98));
    checkRegions(service.getHighlight(file), TextRange.create(0, 19), TextRange.create(0, 6), TextRange.create(7, 18), TextRange.create(20, 79), TextRange.create(20, 26), TextRange.create(27, 78), TextRange.create(80, 99), TextRange.create(80, 86), TextRange.create(87, 98));
    undoAndUpdateHighlighting(file);
    // paste a lot at the end of the region
    getEditor().getCaretModel().moveToOffset(38);
    myFixture.performEditorAction(IdeActions.ACTION_EDITOR_PASTE);
    checkRegions(service.getNavigation(file), TextRange.create(7, 18), TextRange.create(27, 38), TextRange.create(87, 98));
    checkRegions(service.getHighlight(file), TextRange.create(0, 19), TextRange.create(0, 6), TextRange.create(7, 18), TextRange.create(20, 79), TextRange.create(20, 26), TextRange.create(27, 38), TextRange.create(80, 99), TextRange.create(80, 86), TextRange.create(87, 98));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService) StringSelection(java.awt.datatransfer.StringSelection)

Example 7 with DartAnalysisServerService

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

the class DartServerHighlightingTest method testServerDataUpdateOnSelectionDelete.

public void testServerDataUpdateOnSelectionDelete() {
    initServerDataTest();
    final DartAnalysisServerService service = DartAnalysisServerService.getInstance(getProject());
    final VirtualFile file = getFile().getVirtualFile();
    checkServerDataInitialState(file);
    // delete exactly the region
    getEditor().getSelectionModel().setSelection(27, 38);
    getEditor().getCaretModel().moveToOffset(38);
    myFixture.type('\b');
    checkRegions(service.getNavigation(file), TextRange.create(7, 18), /*TextRange.create(26, 37),*/
    TextRange.create(47 - 11, 58 - 11));
    checkRegions(service.getHighlight(file), TextRange.create(0, 19), TextRange.create(0, 6), TextRange.create(7, 18), TextRange.create(20, 39 - 11), TextRange.create(20, 26), /*TextRange.create(27, 38),*/
    TextRange.create(40 - 11, 59 - 11), TextRange.create(40 - 11, 46 - 11), TextRange.create(47 - 11, 58 - 11));
    undoAndUpdateHighlighting(file);
    // delete selection in the middle of the region
    getEditor().getSelectionModel().setSelection(29, 36);
    getEditor().getCaretModel().moveToOffset(36);
    myFixture.type('\b');
    checkRegions(service.getNavigation(file), TextRange.create(7, 18), /*TextRange.create(28, 39),*/
    TextRange.create(47 - 7, 58 - 7));
    checkRegions(service.getHighlight(file), TextRange.create(0, 19), TextRange.create(0, 6), TextRange.create(7, 18), TextRange.create(20, 39 - 7), TextRange.create(20, 26), TextRange.create(27, 38 - 7), TextRange.create(40 - 7, 59 - 7), TextRange.create(40 - 7, 46 - 7), TextRange.create(47 - 7, 58 - 7));
    undoAndUpdateHighlighting(file);
    // delete selection that includes region and selection start/end touch other regions
    getEditor().getSelectionModel().setSelection(18, 47);
    getEditor().getCaretModel().moveToOffset(47);
    myFixture.type('\b');
    checkRegions(service.getNavigation(file), TextRange.create(7, 18), /*TextRange.create(28, 39),*/
    TextRange.create(47 - 29, 58 - 29));
    checkRegions(service.getHighlight(file), /*TextRange.create(0, 19),*/
    TextRange.create(0, 6), TextRange.create(7, 18), /*TextRange.create(40, 59), TextRange.create(40, 46),*/
    TextRange.create(47 - 29, 58 - 29));
    undoAndUpdateHighlighting(file);
    // delete selection that has start in one region and end in another
    getEditor().getSelectionModel().setSelection(17, 28);
    getEditor().getCaretModel().moveToOffset(28);
    myFixture.type('\b');
    checkRegions(service.getNavigation(file), /*TextRange.create(7, 18), TextRange.create(28, 39),*/
    TextRange.create(36, 47));
    checkRegions(service.getHighlight(file), /*TextRange.create(0, 19),*/
    TextRange.create(0, 6), /*TextRange.create(20, 39), TextRange.create(20, 26), TextRange.create(27, 38),*/
    TextRange.create(40 - 11, 59 - 11), TextRange.create(40 - 11, 46 - 11), TextRange.create(47 - 11, 58 - 11));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService)

Example 8 with DartAnalysisServerService

use of com.jetbrains.lang.dart.analyzer.DartAnalysisServerService 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 9 with DartAnalysisServerService

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

the class DartServerHighlightingTest method testServerDataUpdateOnBackspace.

public void testServerDataUpdateOnBackspace() {
    initServerDataTest();
    final DartAnalysisServerService service = DartAnalysisServerService.getInstance(getProject());
    final VirtualFile file = getFile().getVirtualFile();
    checkServerDataInitialState(file);
    // backspace at the beginning of the region
    getEditor().getCaretModel().moveToOffset(27);
    myFixture.type('\b');
    checkRegions(service.getNavigation(file), TextRange.create(7, 18), TextRange.create(26, 37), TextRange.create(46, 57));
    checkRegions(service.getHighlight(file), TextRange.create(0, 19), TextRange.create(0, 6), TextRange.create(7, 18), TextRange.create(20, 38), TextRange.create(20, 26), TextRange.create(26, 37), TextRange.create(39, 58), TextRange.create(39, 45), TextRange.create(46, 57));
    undoAndUpdateHighlighting(file);
    // backspace in the middle of the region
    getEditor().getCaretModel().moveToOffset(29);
    myFixture.type('\b');
    checkRegions(service.getNavigation(file), TextRange.create(7, 18), /*TextRange.create(27, 38),*/
    TextRange.create(46, 57));
    checkRegions(service.getHighlight(file), TextRange.create(0, 19), TextRange.create(0, 6), TextRange.create(7, 18), TextRange.create(20, 38), TextRange.create(20, 26), TextRange.create(27, 37), TextRange.create(39, 58), TextRange.create(39, 45), TextRange.create(46, 57));
    undoAndUpdateHighlighting(file);
    // backspace at the end of the region
    getEditor().getCaretModel().moveToOffset(39);
    myFixture.type('\b');
    checkRegions(service.getNavigation(file), TextRange.create(7, 18), TextRange.create(27, 38), TextRange.create(46, 57));
    checkRegions(service.getHighlight(file), TextRange.create(0, 19), TextRange.create(0, 6), TextRange.create(7, 18), TextRange.create(20, 38), TextRange.create(20, 26), TextRange.create(27, 38), TextRange.create(39, 58), TextRange.create(39, 45), TextRange.create(46, 57));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService)

Example 10 with DartAnalysisServerService

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

the class DartServerFindUsagesHandler method processElementUsages.

@Override
public boolean processElementUsages(@NotNull final PsiElement elementToSearch, @NotNull final Processor<UsageInfo> processor, @NotNull final FindUsagesOptions options) {
    final SearchScope scope = options.searchScope;
    final Project project = ReadAction.compute(this::getProject);
    final DartAnalysisServerService service = DartAnalysisServerService.getInstance(project);
    final ReadActionConsumer<SearchResult> searchResultProcessor = new ReadActionConsumer<SearchResult>() {

        @Override
        public void consumeInReadAction(SearchResult result) {
            if (result.getKind().equals(SearchResultKind.DECLARATION))
                return;
            final Location location = result.getLocation();
            final VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(location.getFile()));
            if (vFile == null)
                return;
            if (!scope.contains(vFile))
                return;
            final PsiFile psiFile = elementToSearch.getManager().findFile(vFile);
            if (psiFile == null)
                return;
            final int offset = service.getConvertedOffset(vFile, location.getOffset());
            final int length = service.getConvertedOffset(vFile, location.getOffset() + location.getLength()) - offset;
            final TextRange range = TextRange.create(offset, offset + length);
            final boolean potentialUsage = result.isPotential();
            final PsiElement usageElement = getUsagePsiElement(psiFile, range);
            final UsageInfo usageInfo = usageElement == null ? null : getUsageInfo(usageElement, range, potentialUsage);
            if (usageInfo != null && usageInfo.getElement() != null && (!(scope instanceof LocalSearchScope) || PsiSearchScopeUtil.isInScope((LocalSearchScope) scope, usageInfo.getElement()))) {
                processor.process(usageInfo);
            }
        }
    };
    final VirtualFile file = ReadAction.compute(() -> elementToSearch.getContainingFile().getVirtualFile());
    final int offset = elementToSearch.getTextRange().getStartOffset();
    service.search_findElementReferences(file, offset, searchResultProcessor);
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalSearchScope(com.intellij.psi.search.LocalSearchScope) SearchResult(org.dartlang.analysis.server.protocol.SearchResult) TextRange(com.intellij.openapi.util.TextRange) Project(com.intellij.openapi.project.Project) SearchScope(com.intellij.psi.search.SearchScope) LocalSearchScope(com.intellij.psi.search.LocalSearchScope) PsiFile(com.intellij.psi.PsiFile) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService) PsiElement(com.intellij.psi.PsiElement) UsageInfo(com.intellij.usageView.UsageInfo) Location(org.dartlang.analysis.server.protocol.Location)

Aggregations

DartAnalysisServerService (com.jetbrains.lang.dart.analyzer.DartAnalysisServerService)22 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 Project (com.intellij.openapi.project.Project)3 TextRange (com.intellij.openapi.util.TextRange)3 PsiFile (com.intellij.psi.PsiFile)3 Document (com.intellij.openapi.editor.Document)2 PsiElement (com.intellij.psi.PsiElement)2 UsageInfo (com.intellij.usageView.UsageInfo)2 DartServerData (com.jetbrains.lang.dart.analyzer.DartServerData)2 SourceChange (org.dartlang.analysis.server.protocol.SourceChange)2 SourceEdit (org.dartlang.analysis.server.protocol.SourceEdit)2 SourceFileEdit (org.dartlang.analysis.server.protocol.SourceFileEdit)2 GetServerPortConsumer (com.google.dart.server.GetServerPortConsumer)1 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)1 PsiElement2UsageTargetAdapter (com.intellij.find.findUsages.PsiElement2UsageTargetAdapter)1 ASTNode (com.intellij.lang.ASTNode)1 Annotation (com.intellij.lang.annotation.Annotation)1 AnnotationSession (com.intellij.lang.annotation.AnnotationSession)1 Notification (com.intellij.notification.Notification)1 Caret (com.intellij.openapi.editor.Caret)1