Search in sources :

Example 1 with Position

use of org.dartlang.analysis.server.protocol.Position 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)

Aggregations

DartAnalysisServerService (com.jetbrains.lang.dart.analyzer.DartAnalysisServerService)1 DartSourceEditException (com.jetbrains.lang.dart.assists.DartSourceEditException)1 Position (org.dartlang.analysis.server.protocol.Position)1 SourceChange (org.dartlang.analysis.server.protocol.SourceChange)1