Search in sources :

Example 16 with DartAnalysisServerService

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

the class DartServerImplementationsMarkerProvider method createMarker.

@Nullable
private static LineMarkerInfo createMarker(@NotNull final DartComponentName name) {
    final DartAnalysisServerService service = DartAnalysisServerService.getInstance(name.getProject());
    final VirtualFile file = name.getContainingFile().getVirtualFile();
    if (file == null || !file.isInLocalFileSystem()) {
        return null;
    }
    final int nameOffset = name.getTextRange().getStartOffset();
    final int nameLength = name.getTextLength();
    // ignore Object
    if ("Object".equals(name.getName())) {
        return null;
    }
    // classes
    for (DartServerData.DartRegion implementedClassRegion : service.getImplementedClasses(file)) {
        if (implementedClassRegion.getOffset() == nameOffset && implementedClassRegion.getLength() == nameLength) {
            return createMarkerClass(name);
        }
    }
    // members
    for (DartServerData.DartRegion implementedMemberRegion : service.getImplementedMembers(file)) {
        if (implementedMemberRegion.getOffset() == nameOffset && implementedMemberRegion.getLength() == nameLength) {
            return createMarkerMember(name);
        }
    }
    // not found
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService) DartServerData(com.jetbrains.lang.dart.analyzer.DartServerData) Nullable(org.jetbrains.annotations.Nullable)

Example 17 with DartAnalysisServerService

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

the class DartExecutionHelper method getIssues.

@NotNull
public static List<DartServerData.DartError> getIssues(@NotNull final Project project, @NotNull VirtualFile launchFile, boolean onlyErrors) {
    GlobalSearchScope scope = DartResolveScopeProvider.getDartScope(project, launchFile, true);
    if (scope == null) {
        return Collections.emptyList();
    }
    // Collect errors.
    final DartAnalysisServerService analysisServerService = DartAnalysisServerService.getInstance(project);
    List<DartServerData.DartError> errors = analysisServerService.getErrors(scope);
    if (onlyErrors) {
        errors = errors.stream().filter(DartServerData.DartError::isError).collect(Collectors.toList());
    }
    return errors;
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with DartAnalysisServerService

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

the class DartServerHighlightingTest method testServerDataLifecycle.

public void testServerDataLifecycle() throws Exception {
    myFixture.configureByText("firstFile.dart", "class Foo { toString(){ return super.toString(); } }");
    final VirtualFile firstFile = getFile().getVirtualFile();
    final VirtualFile secondFile = myFixture.addFileToProject("secondFile.dart", "class Bar { toString(){ return super.toString(); } }").getVirtualFile();
    final DartAnalysisServerService service = DartAnalysisServerService.getInstance(getProject());
    myFixture.doHighlighting();
    assertNotEmpty(service.getHighlight(firstFile));
    assertNotEmpty(service.getNavigation(firstFile));
    assertNotEmpty(service.getOverrideMembers(firstFile));
    myFixture.openFileInEditor(secondFile);
    // TestFileEditorManager doesn't notify listeners itself;
    // we need any notification to trigger DartAnalysisserverService.updateVisibleFiles()
    final FileEditorManagerEvent event = new FileEditorManagerEvent(FileEditorManager.getInstance(getProject()), firstFile, null, secondFile, null);
    getProject().getMessageBus().syncPublisher(FileEditorManagerListener.FILE_EDITOR_MANAGER).selectionChanged(event);
    myFixture.doHighlighting();
    assertNotEmpty(service.getHighlight(firstFile));
    assertNotEmpty(service.getNavigation(firstFile));
    assertNotEmpty(service.getOverrideMembers(firstFile));
    assertNotEmpty(service.getHighlight(secondFile));
    assertNotEmpty(service.getNavigation(secondFile));
    assertNotEmpty(service.getOverrideMembers(secondFile));
    getProject().getMessageBus().syncPublisher(FileEditorManagerListener.FILE_EDITOR_MANAGER).fileClosed(FileEditorManager.getInstance(getProject()), firstFile);
    assertNotEmpty(service.getHighlight(firstFile));
    assertNotEmpty(service.getNavigation(firstFile));
    assertNotEmpty(service.getOverrideMembers(firstFile));
    assertNotEmpty(service.getHighlight(secondFile));
    assertNotEmpty(service.getNavigation(secondFile));
    assertNotEmpty(service.getOverrideMembers(secondFile));
    FileEditorManager.getInstance(getProject()).closeFile(firstFile);
    getProject().getMessageBus().syncPublisher(FileEditorManagerListener.FILE_EDITOR_MANAGER).fileClosed(FileEditorManager.getInstance(getProject()), firstFile);
    assertEmpty(service.getHighlight(firstFile));
    assertEmpty(service.getNavigation(firstFile));
    assertEmpty(service.getOverrideMembers(firstFile));
    assertNotEmpty(service.getHighlight(secondFile));
    assertNotEmpty(service.getNavigation(secondFile));
    assertNotEmpty(service.getOverrideMembers(secondFile));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService) FileEditorManagerEvent(com.intellij.openapi.fileEditor.FileEditorManagerEvent)

Example 19 with DartAnalysisServerService

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

the class DartServerHighlightingTest method checkServerDataInitialState.

private void checkServerDataInitialState(@NotNull final VirtualFile file) {
    final DartAnalysisServerService service = DartAnalysisServerService.getInstance(getProject());
    // references to 'dart:core'
    checkRegions(service.getNavigation(file), TextRange.create(7, 18), TextRange.create(27, 38), TextRange.create(47, 58));
    checkRegions(service.getHighlight(file), TextRange.create(0, 19), TextRange.create(0, 6), TextRange.create(7, 18), TextRange.create(20, 39), TextRange.create(20, 26), TextRange.create(27, 38), TextRange.create(40, 59), TextRange.create(40, 46), TextRange.create(47, 58));
}
Also used : DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService)

Example 20 with DartAnalysisServerService

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

the class DartServerHighlightingTest method testServerDataUpdateOnTyping.

public void testServerDataUpdateOnTyping() {
    // navigation region must be deleted when touched by editing and updated otherwise
    initServerDataTest();
    final DartAnalysisServerService service = DartAnalysisServerService.getInstance(getProject());
    final VirtualFile file = getFile().getVirtualFile();
    checkServerDataInitialState(file);
    // typing at the beginning of the region
    getEditor().getCaretModel().moveToOffset(27);
    myFixture.type('a');
    checkRegions(service.getNavigation(file), TextRange.create(7, 18), TextRange.create(28, 39), TextRange.create(48, 59));
    checkRegions(service.getHighlight(file), TextRange.create(0, 19), TextRange.create(0, 6), TextRange.create(7, 18), TextRange.create(20, 40), TextRange.create(20, 26), TextRange.create(28, 39), TextRange.create(41, 60), TextRange.create(41, 47), TextRange.create(48, 59));
    undoAndUpdateHighlighting(file);
    // typing in the middle of the region
    getEditor().getCaretModel().moveToOffset(29);
    myFixture.type('a');
    checkRegions(service.getNavigation(file), TextRange.create(7, 18), /*TextRange.create(28, 39),*/
    TextRange.create(48, 59));
    checkRegions(service.getHighlight(file), TextRange.create(0, 19), TextRange.create(0, 6), TextRange.create(7, 18), TextRange.create(20, 40), TextRange.create(20, 26), TextRange.create(27, 39), TextRange.create(41, 60), TextRange.create(41, 47), TextRange.create(48, 59));
    undoAndUpdateHighlighting(file);
    // typing at the end of the region
    getEditor().getCaretModel().moveToOffset(38);
    myFixture.type('a');
    checkRegions(service.getNavigation(file), TextRange.create(7, 18), TextRange.create(27, 38), TextRange.create(48, 59));
    checkRegions(service.getHighlight(file), TextRange.create(0, 19), TextRange.create(0, 6), TextRange.create(7, 18), TextRange.create(20, 40), TextRange.create(20, 26), TextRange.create(27, 38), TextRange.create(41, 60), TextRange.create(41, 47), TextRange.create(48, 59));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService)

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