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;
}
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;
}
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));
}
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));
}
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));
}
Aggregations