Search in sources :

Example 6 with TextDocumentPositionParamsDTO

use of org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO in project che by eclipse.

the class HoverProvider method computeHover.

@Override
public JsPromise<OrionHoverOverlay> computeHover(OrionHoverContextOverlay context) {
    EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
    if (activeEditor == null || !(activeEditor instanceof TextEditor)) {
        return null;
    }
    TextEditor editor = ((TextEditor) activeEditor);
    if (!(editor.getConfiguration() instanceof LanguageServerEditorConfiguration)) {
        return null;
    }
    LanguageServerEditorConfiguration configuration = (LanguageServerEditorConfiguration) editor.getConfiguration();
    if (configuration.getServerCapabilities().isHoverProvider() == null || !configuration.getServerCapabilities().isHoverProvider()) {
        return null;
    }
    Document document = editor.getDocument();
    TextDocumentPositionParamsDTO paramsDTO = helper.createTDPP(document, context.getOffset());
    Promise<HoverDTO> promise = client.hover(paramsDTO);
    Promise<OrionHoverOverlay> then = promise.then(new Function<HoverDTO, OrionHoverOverlay>() {

        @Override
        public OrionHoverOverlay apply(HoverDTO arg) throws FunctionException {
            OrionHoverOverlay hover = OrionHoverOverlay.create();
            hover.setType("markdown");
            String content = renderContent(arg);
            //do not show hover with only white spaces
            if (StringUtils.isNullOrWhitespace(content)) {
                return null;
            }
            hover.setContent(content);
            return hover;
        }

        private String renderContent(HoverDTO hover) {
            List<String> contents = new ArrayList<String>();
            for (MarkedStringDTO dto : hover.getContents()) {
                String lang = dto.getLanguage();
                if (lang == null || MarkedString.PLAIN_STRING.equals(lang)) {
                    // plain markdown text
                    contents.add(dto.getValue());
                } else {
                    // markdown code block
                    contents.add("```" + lang + "\n" + dto.getValue() + "\n```");
                }
            }
            return Joiner.on("\n\n").join(contents);
        }
    });
    return (JsPromise<OrionHoverOverlay>) then;
}
Also used : TextDocumentPositionParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO) FunctionException(org.eclipse.che.api.promises.client.FunctionException) HoverDTO(org.eclipse.che.api.languageserver.shared.lsapi.HoverDTO) MarkedString(io.typefox.lsapi.MarkedString) JsPromise(org.eclipse.che.api.promises.client.js.JsPromise) Document(org.eclipse.che.ide.api.editor.document.Document) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) MarkedStringDTO(org.eclipse.che.api.languageserver.shared.lsapi.MarkedStringDTO) LanguageServerEditorConfiguration(org.eclipse.che.plugin.languageserver.ide.editor.LanguageServerEditorConfiguration) ArrayList(java.util.ArrayList) List(java.util.List) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) OrionHoverOverlay(org.eclipse.che.ide.editor.orion.client.jso.OrionHoverOverlay)

Example 7 with TextDocumentPositionParamsDTO

use of org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO in project che by eclipse.

the class FindDefinitionAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
    TextEditor textEditor = ((TextEditor) activeEditor);
    TextDocumentPositionParamsDTO paramsDTO = dtoBuildHelper.createTDPP(textEditor.getDocument(), textEditor.getCursorPosition());
    final Promise<List<LocationDTO>> promise = client.definition(paramsDTO);
    promise.then(new Operation<List<LocationDTO>>() {

        @Override
        public void apply(List<LocationDTO> arg) throws OperationException {
            if (arg.size() == 1) {
                presenter.onLocationSelected(arg.get(0));
            } else {
                presenter.openLocation(promise);
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            presenter.showError(arg);
        }
    });
}
Also used : TextDocumentPositionParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) Operation(org.eclipse.che.api.promises.client.Operation) LocationDTO(org.eclipse.che.api.languageserver.shared.lsapi.LocationDTO) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

TextDocumentPositionParamsDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO)7 TextDocumentIdentifierDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentIdentifierDTO)3 FunctionException (org.eclipse.che.api.promises.client.FunctionException)3 PromiseError (org.eclipse.che.api.promises.client.PromiseError)3 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)3 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)3 List (java.util.List)2 PositionDTO (org.eclipse.che.api.languageserver.shared.lsapi.PositionDTO)2 Operation (org.eclipse.che.api.promises.client.Operation)2 OperationException (org.eclipse.che.api.promises.client.OperationException)2 JsPromise (org.eclipse.che.api.promises.client.js.JsPromise)2 Document (org.eclipse.che.ide.api.editor.document.Document)2 LanguageServerEditorConfiguration (org.eclipse.che.plugin.languageserver.ide.editor.LanguageServerEditorConfiguration)2 Optional (com.google.common.base.Optional)1 MarkedString (io.typefox.lsapi.MarkedString)1 ArrayList (java.util.ArrayList)1 Collections.singletonList (java.util.Collections.singletonList)1 CompletionListDTO (org.eclipse.che.api.languageserver.shared.lsapi.CompletionListDTO)1 DocumentHighlightDTO (org.eclipse.che.api.languageserver.shared.lsapi.DocumentHighlightDTO)1 HoverDTO (org.eclipse.che.api.languageserver.shared.lsapi.HoverDTO)1