use of com.jetbrains.lang.dart.analyzer.DartAnalysisServerService in project intellij-plugins by JetBrains.
the class DartStyleAction method runOverEditor.
protected void runOverEditor(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile psiFile) {
final Document document = editor.getDocument();
if (!ReadonlyStatusHandler.ensureDocumentWritable(project, document))
return;
final int caretOffset = editor.getCaretModel().getOffset();
final int lineLength = getRightMargin(project);
final DartAnalysisServerService das = DartAnalysisServerService.getInstance(project);
das.updateFilesContent();
DartAnalysisServerService.FormatResult formatResult = das.edit_format(psiFile.getVirtualFile(), caretOffset, 0, lineLength);
if (formatResult == null) {
showHintLater(editor, DartBundle.message("dart.style.hint.failed"), true);
LOG.warn("Unexpected response from edit_format, formatResult is null");
return;
}
final Runnable runnable = () -> {
final List<SourceEdit> edits = formatResult.getEdits();
if (edits == null || edits.size() == 0) {
showHintLater(editor, DartBundle.message("dart.style.hint.already.good"), false);
} else if (edits.size() == 1) {
final String replacement = StringUtil.convertLineSeparators(edits.get(0).getReplacement());
document.replaceString(0, document.getTextLength(), replacement);
final int offset = das.getConvertedOffset(psiFile.getVirtualFile(), formatResult.getOffset());
editor.getCaretModel().moveToOffset(offset);
showHintLater(editor, DartBundle.message("dart.style.hint.success"), false);
} else {
showHintLater(editor, DartBundle.message("dart.style.hint.failed"), true);
LOG.warn("Unexpected response from edit_format, formatResult.getEdits().size() = " + edits.size());
}
};
ApplicationManager.getApplication().runWriteAction(() -> CommandProcessor.getInstance().executeCommand(project, runnable, DartBundle.message("dart.style.action.name"), null));
}
use of com.jetbrains.lang.dart.analyzer.DartAnalysisServerService in project intellij-plugins by JetBrains.
the class DartAnnotator method annotate.
@Override
public void annotate(@NotNull final PsiElement element, @NotNull final AnnotationHolder holder) {
if (holder.isBatchMode())
return;
final AnnotationSession session = holder.getCurrentAnnotationSession();
if (session.getUserData(DART_SERVER_DATA_HANDLED) != Boolean.TRUE) {
session.putUserData(DART_SERVER_DATA_HANDLED, Boolean.TRUE);
final VirtualFile vFile = element.getContainingFile().getVirtualFile();
final DartAnalysisServerService service = DartAnalysisServerService.getInstance(element.getProject());
if (canBeAnalyzedByServer(element.getProject(), vFile) && service.serverReadyForRequest(element.getProject())) {
service.updateFilesContent();
if (ApplicationManager.getApplication().isUnitTestMode()) {
service.waitForAnalysisToComplete_TESTS_ONLY(vFile);
}
applyServerHighlighting(vFile, holder);
}
}
if (DartTokenTypes.COLON == element.getNode().getElementType() && element.getParent() instanceof DartTernaryExpression) {
holder.createInfoAnnotation(element, null).setTextAttributes(DartSyntaxHighlighterColors.OPERATION_SIGN);
return;
}
if (DartTokenTypesSets.BUILT_IN_IDENTIFIERS.contains(element.getNode().getElementType())) {
if (element.getNode().getTreeParent().getElementType() != DartTokenTypes.ID) {
holder.createInfoAnnotation(element, null).setTextAttributes(DartSyntaxHighlighterColors.KEYWORD);
return;
}
}
// sync*, async* and yield*
if (DartTokenTypes.MUL == element.getNode().getElementType()) {
final ASTNode previous = element.getNode().getTreePrev();
if (previous != null && (previous.getElementType() == DartTokenTypes.SYNC || previous.getElementType() == DartTokenTypes.ASYNC || previous.getElementType() == DartTokenTypes.YIELD)) {
holder.createInfoAnnotation(element, null).setTextAttributes(DartSyntaxHighlighterColors.KEYWORD);
}
}
if (element.getNode().getElementType() == DartTokenTypes.REGULAR_STRING_PART) {
highlightEscapeSequences(element, holder);
return;
}
if (element instanceof DartSymbolLiteralExpression) {
holder.createInfoAnnotation(element, null).setTextAttributes(DartSyntaxHighlighterColors.SYMBOL_LITERAL);
//noinspection UnnecessaryReturnStatement
return;
}
}
use of com.jetbrains.lang.dart.analyzer.DartAnalysisServerService in project intellij-plugins by JetBrains.
the class DartAnnotator method applyServerHighlighting.
private static void applyServerHighlighting(@NotNull final VirtualFile file, @NotNull final AnnotationHolder holder) {
final PsiFile psiFile = holder.getCurrentAnnotationSession().getFile();
final DartAnalysisServerService das = DartAnalysisServerService.getInstance(psiFile.getProject());
for (DartServerData.DartError error : das.getErrors(file)) {
if (shouldIgnoreMessageFromDartAnalyzer(file.getPath(), error.getAnalysisErrorFileSD()))
continue;
final Annotation annotation = createAnnotation(holder, error, psiFile.getTextLength());
if (annotation != null) {
final DartQuickFixSet quickFixSet = new DartQuickFixSet(psiFile.getManager(), file, error.getOffset(), error.getCode(), error.getSeverity());
for (IntentionAction quickFix : quickFixSet.getQuickFixes()) {
annotation.registerFix(quickFix);
}
if (error.getCode() != null) {
annotation.setProblemGroup(new DartProblemGroup(error.getCode(), error.getSeverity()));
}
}
}
for (DartServerData.DartHighlightRegion region : das.getHighlight(file)) {
final String attributeKey = HIGHLIGHTING_TYPE_MAP.get(region.getType());
if (attributeKey != null) {
final TextRange textRange = new TextRange(region.getOffset(), region.getOffset() + region.getLength());
holder.createInfoAnnotation(textRange, null).setTextAttributes(TextAttributesKey.find(attributeKey));
}
}
}
use of com.jetbrains.lang.dart.analyzer.DartAnalysisServerService in project intellij-plugins by JetBrains.
the class DartSortMembersAction method runOverEditor.
protected void runOverEditor(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile psiFile) {
final Document document = editor.getDocument();
if (!ReadonlyStatusHandler.ensureDocumentWritable(project, document))
return;
final String path = psiFile.getVirtualFile().getPath();
final DartAnalysisServerService service = DartAnalysisServerService.getInstance(project);
service.updateFilesContent();
final SourceFileEdit fileEdit = service.edit_sortMembers(path);
if (fileEdit == null) {
showHintLater(editor, DartBundle.message("dart.sort.members.hint.failed"), true);
LOG.warn("Unexpected response from edit_sortMembers, fileEdit is null");
return;
}
final List<SourceEdit> edits = fileEdit.getEdits();
if (edits == null || edits.size() == 0) {
showHintLater(editor, DartBundle.message("dart.sort.members.hint.already.good"), false);
return;
}
final Runnable runnable = () -> {
AssistUtils.applySourceEdits(project, psiFile.getVirtualFile(), document, edits, Collections.emptySet());
showHintLater(editor, DartBundle.message("dart.sort.members.hint.success"), false);
};
ApplicationManager.getApplication().runWriteAction(() -> CommandProcessor.getInstance().executeCommand(project, runnable, DartBundle.message("dart.sort.members.action.name"), null));
}
use of com.jetbrains.lang.dart.analyzer.DartAnalysisServerService in project intellij-plugins by JetBrains.
the class DartInheritorsSearcher method processQuery.
@Override
public void processQuery(@NotNull final DefinitionsScopedSearch.SearchParameters parameters, @NotNull final Processor<PsiElement> consumer) {
final Ref<VirtualFile> fileRef = Ref.create();
final Ref<Integer> offsetRef = Ref.create();
final Ref<DartComponentType> componentTypeRef = Ref.create();
prepare(parameters, fileRef, offsetRef, componentTypeRef);
if (fileRef.isNull() || offsetRef.isNull() || componentTypeRef.isNull())
return;
ApplicationManager.getApplication().runReadAction(() -> {
final List<TypeHierarchyItem> hierarchyItems = CachedValuesManager.getCachedValue(parameters.getElement(), () -> {
final DartAnalysisServerService das = DartAnalysisServerService.getInstance(parameters.getElement().getProject());
final List<TypeHierarchyItem> items = das.search_getTypeHierarchy(fileRef.get(), offsetRef.get(), false);
return new CachedValueProvider.Result<>(items, PsiModificationTracker.MODIFICATION_COUNT);
});
final List<DartComponent> components = componentTypeRef.get() == DartComponentType.CLASS ? getSubClasses(parameters.getElement().getProject(), parameters.getScope(), hierarchyItems) : getSubMembers(parameters.getElement().getProject(), parameters.getScope(), hierarchyItems);
for (DartComponent component : components) {
consumer.process(component);
}
});
}
Aggregations