Search in sources :

Example 1 with Document

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

the class LanguageServerAnnotationModel method createPositionFromDiagnostic.

protected Position createPositionFromDiagnostic(final DiagnosticDTO diagnostic) {
    DocumentHandle documentHandle = getDocumentHandle();
    Document document = documentHandle.getDocument();
    RangeDTO range = diagnostic.getRange();
    int start = document.getIndexFromPosition(new TextPosition(range.getStart().getLine(), range.getStart().getCharacter()));
    int end = document.getIndexFromPosition(new TextPosition(range.getEnd().getLine(), range.getEnd().getCharacter()));
    if (start == -1 && end == -1) {
        return new Position(0);
    }
    if (start == -1) {
        return new Position(end);
    }
    if (end == -1) {
        return new Position(start);
    }
    int length = end - start;
    if (length < 0) {
        return null;
    }
    return new Position(start, length);
}
Also used : DocumentHandle(org.eclipse.che.ide.api.editor.document.DocumentHandle) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Position(org.eclipse.che.ide.api.editor.text.Position) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Document(org.eclipse.che.ide.api.editor.document.Document) RangeDTO(org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO)

Example 2 with Document

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

the class FullTextDocumentSynchronize method syncTextDocument.

@Override
public void syncTextDocument(DocumentChangeEvent event, int version) {
    Document document = event.getDocument().getDocument();
    DidChangeTextDocumentParamsDTO changeDTO = dtoFactory.createDto(DidChangeTextDocumentParamsDTO.class);
    String uri = document.getFile().getLocation().toString();
    changeDTO.setUri(uri);
    VersionedTextDocumentIdentifierDTO versionedDocId = dtoFactory.createDto(VersionedTextDocumentIdentifierDTO.class);
    versionedDocId.setUri(uri);
    versionedDocId.setVersion(version);
    changeDTO.setTextDocument(versionedDocId);
    TextDocumentContentChangeEventDTO actualChange = dtoFactory.createDto(TextDocumentContentChangeEventDTO.class);
    actualChange.setText(event.getDocument().getDocument().getContents());
    changeDTO.setContentChanges(Collections.singletonList(actualChange));
    textDocumentService.didChange(changeDTO);
}
Also used : VersionedTextDocumentIdentifierDTO(org.eclipse.che.api.languageserver.shared.lsapi.VersionedTextDocumentIdentifierDTO) TextDocumentContentChangeEventDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentContentChangeEventDTO) DidChangeTextDocumentParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.DidChangeTextDocumentParamsDTO) Document(org.eclipse.che.ide.api.editor.document.Document)

Example 3 with Document

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

the class IncrementalTextDocumentSynchronize method syncTextDocument.

@Override
public void syncTextDocument(DocumentChangeEvent event, int version) {
    Document document = event.getDocument().getDocument();
    TextPosition startPosition = document.getPositionFromIndex(event.getOffset());
    TextPosition endPosition;
    if (event.getRemoveCharCount() != 0) {
        endPosition = new TextPosition(startPosition.getLine(), startPosition.getCharacter() + event.getRemoveCharCount());
    } else {
        endPosition = new TextPosition(startPosition.getLine(), startPosition.getCharacter());
    }
    DidChangeTextDocumentParamsDTO changeDTO = dtoFactory.createDto(DidChangeTextDocumentParamsDTO.class);
    String uri = document.getFile().getLocation().toString();
    changeDTO.setUri(uri);
    VersionedTextDocumentIdentifierDTO versionedDocId = dtoFactory.createDto(VersionedTextDocumentIdentifierDTO.class);
    versionedDocId.setUri(uri);
    versionedDocId.setVersion(version);
    changeDTO.setTextDocument(versionedDocId);
    RangeDTO range = dtoFactory.createDto(RangeDTO.class);
    PositionDTO start = dtoFactory.createDto(PositionDTO.class);
    start.setLine(startPosition.getLine());
    start.setCharacter(startPosition.getCharacter());
    PositionDTO end = dtoFactory.createDto(PositionDTO.class);
    end.setLine(endPosition.getLine());
    end.setCharacter(endPosition.getCharacter());
    range.setStart(start);
    range.setEnd(end);
    TextDocumentContentChangeEventDTO actualChange = dtoFactory.createDto(TextDocumentContentChangeEventDTO.class);
    actualChange.setRange(range);
    actualChange.setText(event.getText());
    changeDTO.setContentChanges(Collections.singletonList(actualChange));
    textDocumentService.didChange(changeDTO);
}
Also used : VersionedTextDocumentIdentifierDTO(org.eclipse.che.api.languageserver.shared.lsapi.VersionedTextDocumentIdentifierDTO) TextDocumentContentChangeEventDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentContentChangeEventDTO) DidChangeTextDocumentParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.DidChangeTextDocumentParamsDTO) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Document(org.eclipse.che.ide.api.editor.document.Document) RangeDTO(org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO) PositionDTO(org.eclipse.che.api.languageserver.shared.lsapi.PositionDTO)

Example 4 with Document

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

the class BasicActiveFileHandler method scrollToLine.

protected void scrollToLine(EditorPartPresenter editor, int lineNumber) {
    if (editor instanceof TextEditor) {
        TextEditor textEditor = (TextEditor) editor;
        Document document = textEditor.getDocument();
        if (document != null) {
            TextPosition newPosition = new TextPosition(lineNumber, 0);
            document.setCursorPosition(newPosition);
        }
    }
}
Also used : TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Document(org.eclipse.che.ide.api.editor.document.Document)

Example 5 with Document

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

the class TestResultViewImpl method gotoClass.

@Override
public void gotoClass(String packagePath, int line) {
    lastWentLine = line;
    final Project project = appContext.getRootProject();
    String testSrcPath = project.getPath() + "/" + DEFAULT_TEST_SOURCE_FOLDER;
    appContext.getWorkspaceRoot().getFile(testSrcPath + packagePath).then(new Operation<Optional<File>>() {

        @Override
        public void apply(Optional<File> file) throws OperationException {
            if (file.isPresent()) {
                eventBus.fireEvent(FileEvent.createOpenFileEvent(file.get()));
                Timer t = new Timer() {

                    @Override
                    public void run() {
                        EditorPartPresenter editorPart = editorAgent.getActiveEditor();
                        Document doc = ((TextEditor) editorPart).getDocument();
                        doc.setCursorPosition(new TextPosition(lastWentLine - 1, 0));
                    }
                };
                t.schedule(500);
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            Log.info(TestResultViewImpl.class, error);
        }
    });
}
Also used : Optional(com.google.common.base.Optional) Operation(org.eclipse.che.api.promises.client.Operation) Document(org.eclipse.che.ide.api.editor.document.Document) Project(org.eclipse.che.ide.api.resources.Project) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) Timer(com.google.gwt.user.client.Timer) PromiseError(org.eclipse.che.api.promises.client.PromiseError) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) File(org.eclipse.che.ide.api.resources.File) OperationException(org.eclipse.che.api.promises.client.OperationException)

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