Search in sources :

Example 11 with Document

use of org.eclipse.che.ide.api.editor.document.Document in project che by eclipse.

the class ParametersHintsPresenter method getLineStartOffset.

private int getLineStartOffset(TextEditor activeEditor, int offset) {
    Document document = activeEditor.getDocument();
    int lineIndex = document.getLineAtOffset(offset);
    return document.getLineStart(lineIndex);
}
Also used : Document(org.eclipse.che.ide.api.editor.document.Document)

Example 12 with Document

use of org.eclipse.che.ide.api.editor.document.Document in project che by eclipse.

the class JavaQuickAssistProcessor method computeQuickAssistProposals.

@Override
public void computeQuickAssistProposals(final QuickAssistInvocationContext quickAssistContext, final CodeAssistCallback callback) {
    final TextEditor textEditor = quickAssistContext.getTextEditor();
    final Document document = textEditor.getDocument();
    LinearRange tempRange;
    tempRange = textEditor.getSelectedLinearRange();
    final LinearRange range = tempRange;
    final boolean goToClosest = (range.getLength() == 0);
    final QueryAnnotationsEvent.AnnotationFilter filter = new QueryAnnotationsEvent.AnnotationFilter() {

        @Override
        public boolean accept(final Annotation annotation) {
            if (!(annotation instanceof JavaAnnotation)) {
                return false;
            } else {
                JavaAnnotation javaAnnotation = (JavaAnnotation) annotation;
                return (!javaAnnotation.isMarkedDeleted());
            }
        }
    };
    final QueryAnnotationsEvent.QueryCallback queryCallback = new QueryAnnotationsEvent.QueryCallback() {

        @Override
        public void respond(final Map<Annotation, Position> annotations) {
            List<Problem> problems = new ArrayList<>();
            /*final Map<Annotation, Position> problems =*/
            int offset = collectQuickFixableAnnotations(range, document, annotations, goToClosest, problems);
            if (offset != range.getStartOffset()) {
                TextEditor presenter = ((TextEditor) textEditor);
                presenter.getCursorModel().setCursorPosition(offset);
            }
            setupProposals(callback, textEditor, offset, problems);
        }
    };
    final QueryAnnotationsEvent event = new QueryAnnotationsEvent.Builder().withFilter(filter).withCallback(queryCallback).build();
    document.getDocumentHandle().getDocEventBus().fireEvent(event);
}
Also used : LinearRange(org.eclipse.che.ide.api.editor.text.LinearRange) ArrayList(java.util.ArrayList) Document(org.eclipse.che.ide.api.editor.document.Document) QueryAnnotationsEvent(org.eclipse.che.ide.api.editor.annotation.QueryAnnotationsEvent) Annotation(org.eclipse.che.ide.api.editor.text.annotation.Annotation) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) Problem(org.eclipse.che.ide.ext.java.shared.dto.Problem) Map(java.util.Map)

Example 13 with Document

use of org.eclipse.che.ide.api.editor.document.Document in project che by eclipse.

the class EditorGroupSynchronizationImpl method updateContent.

private void updateContent(String newContent, String oldStamp, VirtualFile virtualFile) {
    final DocumentHandle documentHandle = getDocumentHandleFor(groupLeaderEditor);
    if (documentHandle == null) {
        return;
    }
    final Document document = documentHandle.getDocument();
    final String oldContent = document.getContents();
    final TextPosition cursorPosition = document.getCursorPosition();
    if (!(virtualFile instanceof File)) {
        replaceContent(document, newContent, oldContent, cursorPosition);
        return;
    }
    final File file = (File) virtualFile;
    final String newStamp = file.getModificationStamp();
    if (oldStamp == null && !Objects.equals(newContent, oldContent)) {
        replaceContent(document, newContent, oldContent, cursorPosition);
        return;
    }
    if (!Objects.equals(oldStamp, newStamp)) {
        replaceContent(document, newContent, oldContent, cursorPosition);
        notificationManager.notify("External operation", "File '" + file.getName() + "' is updated", SUCCESS, EMERGE_MODE);
    }
}
Also used : DocumentHandle(org.eclipse.che.ide.api.editor.document.DocumentHandle) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Document(org.eclipse.che.ide.api.editor.document.Document) File(org.eclipse.che.ide.api.resources.File) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile)

Aggregations

Document (org.eclipse.che.ide.api.editor.document.Document)13 TextPosition (org.eclipse.che.ide.api.editor.text.TextPosition)6 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)5 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)3 ArrayList (java.util.ArrayList)2 DidChangeTextDocumentParamsDTO (org.eclipse.che.api.languageserver.shared.lsapi.DidChangeTextDocumentParamsDTO)2 RangeDTO (org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO)2 TextDocumentContentChangeEventDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentContentChangeEventDTO)2 TextDocumentPositionParamsDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO)2 VersionedTextDocumentIdentifierDTO (org.eclipse.che.api.languageserver.shared.lsapi.VersionedTextDocumentIdentifierDTO)2 FunctionException (org.eclipse.che.api.promises.client.FunctionException)2 JsPromise (org.eclipse.che.api.promises.client.js.JsPromise)2 DocumentHandle (org.eclipse.che.ide.api.editor.document.DocumentHandle)2 File (org.eclipse.che.ide.api.resources.File)2 LanguageServerEditorConfiguration (org.eclipse.che.plugin.languageserver.ide.editor.LanguageServerEditorConfiguration)2 Optional (com.google.common.base.Optional)1 Timer (com.google.gwt.user.client.Timer)1 MarkedString (io.typefox.lsapi.MarkedString)1 List (java.util.List)1 Map (java.util.Map)1