Search in sources :

Example 1 with DartAnalysisServerService

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

the class ChangeTarget method applySourceEdits.

public static List<SourceEditInfo> applySourceEdits(@NotNull final Project project, @NotNull final VirtualFile file, @NotNull final Document document, @NotNull final List<SourceEdit> edits, @NotNull final Set<String> excludedIds) {
    final List<SourceEditInfo> result = new ArrayList<>(edits.size());
    final DartAnalysisServerService service = DartAnalysisServerService.getInstance(project);
    for (SourceEdit edit : edits) {
        if (excludedIds.contains(edit.getId())) {
            continue;
        }
        final int offset = service.getConvertedOffset(file, edit.getOffset());
        final int length = service.getConvertedOffset(file, edit.getOffset() + edit.getLength()) - offset;
        final String replacement = StringUtil.convertLineSeparators(edit.getReplacement());
        for (SourceEditInfo info : result) {
            if (info.resultingOriginalOffset > edit.getOffset()) {
                info.resultingOriginalOffset -= edit.getLength();
                info.resultingOriginalOffset += edit.getReplacement().length();
                info.resultingConvertedOffset -= length;
                info.resultingConvertedOffset += replacement.length();
            }
        }
        result.add(new SourceEditInfo(edit.getOffset(), offset, edit.getLength(), length, edit.getReplacement(), replacement));
        if (length != replacement.length() || !replacement.equals(document.getText(TextRange.create(offset, offset + length)))) {
            document.replaceString(offset, offset + length, replacement);
        }
    }
    return result;
}
Also used : DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService)

Example 2 with DartAnalysisServerService

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

the class DartRenameDialog method fillTargetsAndUsageToEditIdMap.

private void fillTargetsAndUsageToEditIdMap(@NotNull final List<UsageTarget> usageTargets, @NotNull final Map<Usage, String> usageToEditIdMap) {
    final SourceChange change = myRefactoring.getChange();
    assert change != null;
    final DartAnalysisServerService service = DartAnalysisServerService.getInstance(myProject);
    final PsiManager psiManager = PsiManager.getInstance(myProject);
    for (SourceFileEdit fileEdit : change.getEdits()) {
        final VirtualFile file = AssistUtils.findVirtualFile(fileEdit);
        final PsiFile psiFile = file == null ? null : psiManager.findFile(file);
        if (psiFile == null)
            continue;
        for (SourceEdit sourceEdit : fileEdit.getEdits()) {
            final int offset = service.getConvertedOffset(file, sourceEdit.getOffset());
            final int length = service.getConvertedOffset(file, sourceEdit.getOffset() + sourceEdit.getLength()) - offset;
            final TextRange range = TextRange.create(offset, offset + length);
            final boolean potentialUsage = myRefactoring.getPotentialEdits().contains(sourceEdit.getId());
            final PsiElement usageElement = DartServerFindUsagesHandler.getUsagePsiElement(psiFile, range);
            if (usageElement != null) {
                if (DartComponentType.typeOf(usageElement) != null) {
                    usageTargets.add(new PsiElement2UsageTargetAdapter(usageElement));
                } else {
                    final UsageInfo usageInfo = DartServerFindUsagesHandler.getUsageInfo(usageElement, range, potentialUsage);
                    if (usageInfo != null) {
                        usageToEditIdMap.put(new UsageInfo2UsageAdapter(usageInfo), sourceEdit.getId());
                    }
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SourceFileEdit(org.dartlang.analysis.server.protocol.SourceFileEdit) PsiManager(com.intellij.psi.PsiManager) PsiElement2UsageTargetAdapter(com.intellij.find.findUsages.PsiElement2UsageTargetAdapter) TextRange(com.intellij.openapi.util.TextRange) SourceEdit(org.dartlang.analysis.server.protocol.SourceEdit) SourceChange(org.dartlang.analysis.server.protocol.SourceChange) PsiFile(com.intellij.psi.PsiFile) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService) PsiElement(com.intellij.psi.PsiElement) UsageInfo(com.intellij.usageView.UsageInfo)

Example 3 with DartAnalysisServerService

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

the class DartServerStatementCompletionProcessor method process.

@Override
public boolean process(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile psiFile) {
    final int offset = editor.getCaretModel().getOffset();
    final DartAnalysisServerService service = DartAnalysisServerService.getInstance(psiFile.getProject());
    service.updateFilesContent();
    SourceChange sourceChange = service.edit_getStatementCompletion(psiFile.getVirtualFile(), offset);
    if (sourceChange != null && !isNoop(sourceChange)) {
        try {
            AssistUtils.applySourceChange(project, sourceChange, true);
            Position position = sourceChange.getSelection();
            if (position != null) {
                // The position should never be null but it might be if unit tests are flaky.
                editor.getCaretModel().moveToOffset(service.getConvertedOffset(psiFile.getVirtualFile(), position.getOffset()));
            }
        } catch (DartSourceEditException e) {
            CommonRefactoringUtil.showErrorHint(project, editor, e.getMessage(), CommonBundle.getErrorTitle(), null);
        }
        return true;
    }
    return false;
}
Also used : Position(org.dartlang.analysis.server.protocol.Position) SourceChange(org.dartlang.analysis.server.protocol.SourceChange) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService) DartSourceEditException(com.jetbrains.lang.dart.assists.DartSourceEditException)

Example 4 with DartAnalysisServerService

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

the class AnalysisServerDiagnosticsAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    if (project == null)
        return;
    // Get the current analysis server.
    DartAnalysisServerService server = DartAnalysisServerService.getInstance(project);
    // Ask it for the diagnostics port.
    server.diagnostic_getServerPort(new GetServerPortConsumer() {

        @Override
        public void computedServerPort(int port) {
            // Open a new browser page.
            final String url = "http://localhost:" + port + "/status";
            OpenDartObservatoryUrlAction.openUrlInChromeFamilyBrowser(url);
        }

        @Override
        public void onError(RequestError requestError) {
            Notification notification = new Notification(GROUP_DISPLAY_ID, DartBundle.message("analysis.server.show.diagnostics.error"), requestError.getMessage(), NotificationType.ERROR);
            Notifications.Bus.notify(notification);
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) GetServerPortConsumer(com.google.dart.server.GetServerPortConsumer) RequestError(org.dartlang.analysis.server.protocol.RequestError) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService) Notification(com.intellij.notification.Notification)

Example 5 with DartAnalysisServerService

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

the class AnalysisServerStatusAction method updateStatus.

private static void updateStatus(@NotNull final Project project, @NotNull final Presentation presentation) {
    DartAnalysisServerService das = DartAnalysisServerService.getInstance(project);
    Icon statusIcon;
    String statusText;
    String statusDesc;
    if (das.isServerProcessActive()) {
        if (das.isServerResponsive()) {
            statusIcon = STATUS_GOOD;
            statusText = DartBundle.message("analysis.server.status.good.text");
            statusDesc = DartBundle.message("analysis.server.status.good.desc");
        } else {
            statusIcon = STATUS_UNKNOWN;
            statusText = DartBundle.message("analysis.server.status.unknown.text");
            statusDesc = DartBundle.message("analysis.server.status.unknown.desc");
        }
    } else {
        statusIcon = STATUS_BAD;
        statusText = DartBundle.message("analysis.server.status.bad.text");
        statusDesc = DartBundle.message("analysis.server.status.bad.desc");
    }
    presentation.setIcon(statusIcon);
    presentation.setText(statusText);
    presentation.setDescription(statusDesc);
}
Also used : DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService)

Aggregations

DartAnalysisServerService (com.jetbrains.lang.dart.analyzer.DartAnalysisServerService)24 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 PsiFile (com.intellij.psi.PsiFile)4 Project (com.intellij.openapi.project.Project)3 TextRange (com.intellij.openapi.util.TextRange)3 DartServerData (com.jetbrains.lang.dart.analyzer.DartServerData)3 SourceEdit (org.dartlang.analysis.server.protocol.SourceEdit)3 Document (com.intellij.openapi.editor.Document)2 PsiElement (com.intellij.psi.PsiElement)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 UsageInfo (com.intellij.usageView.UsageInfo)2 List (java.util.List)2 SourceChange (org.dartlang.analysis.server.protocol.SourceChange)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