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