Search in sources :

Example 16 with TextEditor

use of org.eclipse.che.ide.api.editor.texteditor.TextEditor in project che by eclipse.

the class GoToSymbolAction method toQuickOpenEntries.

private List<SymbolEntry> toQuickOpenEntries(List<SymbolInformationDTO> items, final String value) {
    List<SymbolEntry> result = new ArrayList<>();
    String normalValue = value;
    if (value.startsWith(SCOPE_PREFIX)) {
        normalValue = normalValue.substring(SCOPE_PREFIX.length());
    }
    for (SymbolInformationDTO item : items) {
        String label = item.getName().trim();
        List<Match> highlights = fuzzyMatches.fuzzyMatch(normalValue, label);
        if (highlights != null) {
            String description = null;
            if (item.getContainerName() != null) {
                description = item.getContainerName();
            }
            RangeDTO range = item.getLocation().getRange();
            TextRange textRange = new TextRange(new TextPosition(range.getStart().getLine(), range.getStart().getCharacter()), new TextPosition(range.getEnd().getLine(), range.getEnd().getCharacter()));
            //TODO add icons
            result.add(new SymbolEntry(label, symbolKindHelper.from(item.getKind()), description, textRange, (TextEditor) editorAgent.getActiveEditor(), highlights, symbolKindHelper.getIcon(item.getKind())));
        }
    }
    if (!value.isEmpty()) {
        if (value.startsWith(SCOPE_PREFIX)) {
            Collections.sort(result, new Comparator<SymbolEntry>() {

                @Override
                public int compare(SymbolEntry o1, SymbolEntry o2) {
                    return sortScoped(value.toLowerCase(), o1, o2);
                }
            });
        } else {
            Collections.sort(result, new Comparator<SymbolEntry>() {

                @Override
                public int compare(SymbolEntry o1, SymbolEntry o2) {
                    return sortNormal(value.toLowerCase(), o1, o2);
                }
            });
        }
    }
    if (!result.isEmpty() && value.startsWith(SCOPE_PREFIX)) {
        String currentType = null;
        SymbolEntry currentEntry = null;
        int counter = 0;
        for (int i = 0; i < result.size(); i++) {
            SymbolEntry res = result.get(i);
            if (!res.getType().equals(currentType)) {
                if (currentEntry != null) {
                    currentEntry.setGroupLabel(typeToLabel(currentType, counter));
                }
                currentType = res.getType();
                currentEntry = res;
                counter = 1;
                res.setWithBorder(i > 0);
            } else {
                counter++;
            }
        }
        if (currentEntry != null) {
            currentEntry.setGroupLabel(typeToLabel(currentType, counter));
        }
    } else if (!result.isEmpty()) {
        result.get(0).setGroupLabel(localization.goToSymbolSymbols(result.size()));
    }
    return result;
}
Also used : SymbolInformationDTO(org.eclipse.che.api.languageserver.shared.lsapi.SymbolInformationDTO) ArrayList(java.util.ArrayList) TextRange(org.eclipse.che.ide.api.editor.text.TextRange) RangeDTO(org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO) Match(org.eclipse.che.plugin.languageserver.ide.filters.Match) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition)

Example 17 with TextEditor

use of org.eclipse.che.ide.api.editor.texteditor.TextEditor in project che by eclipse.

the class GoToSymbolAction method updateInPerspective.

@Override
public void updateInPerspective(@NotNull ActionEvent event) {
    EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
    if (activeEditor instanceof TextEditor) {
        TextEditorConfiguration configuration = ((TextEditor) activeEditor).getConfiguration();
        if (configuration instanceof LanguageServerEditorConfiguration) {
            ServerCapabilities capabilities = ((LanguageServerEditorConfiguration) configuration).getServerCapabilities();
            event.getPresentation().setEnabledAndVisible(capabilities.isDocumentSymbolProvider() != null && capabilities.isDocumentSymbolProvider());
            return;
        }
    }
    event.getPresentation().setEnabledAndVisible(false);
}
Also used : TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) LanguageServerEditorConfiguration(org.eclipse.che.plugin.languageserver.ide.editor.LanguageServerEditorConfiguration) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) TextEditorConfiguration(org.eclipse.che.ide.api.editor.editorconfig.TextEditorConfiguration) ServerCapabilities(io.typefox.lsapi.ServerCapabilities)

Example 18 with TextEditor

use of org.eclipse.che.ide.api.editor.texteditor.TextEditor in project che by eclipse.

the class OccurrencesProvider method computeOccurrences.

@Override
public JsPromise<OrionOccurrenceOverlay[]> computeOccurrences(OrionOccurrenceContextOverlay context) {
    final EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
    if (activeEditor == null || !(activeEditor instanceof TextEditor)) {
        return null;
    }
    final TextEditor editor = ((TextEditor) activeEditor);
    if (!(editor.getConfiguration() instanceof LanguageServerEditorConfiguration)) {
        return null;
    }
    final LanguageServerEditorConfiguration configuration = (LanguageServerEditorConfiguration) editor.getConfiguration();
    if (configuration.getServerCapabilities().isDocumentHighlightProvider() == null || !configuration.getServerCapabilities().isDocumentHighlightProvider()) {
        return null;
    }
    final Document document = editor.getDocument();
    final TextDocumentPositionParamsDTO paramsDTO = helper.createTDPP(document, context.getStart());
    // FIXME: the result should be a Promise<List<DocumentHighlightDTO>> but the typefox API returns a single DocumentHighlightDTO
    Promise<DocumentHighlightDTO> promise = client.documentHighlight(paramsDTO);
    Promise<OrionOccurrenceOverlay[]> then = promise.then(new Function<DocumentHighlightDTO, OrionOccurrenceOverlay[]>() {

        @Override
        public OrionOccurrenceOverlay[] apply(DocumentHighlightDTO highlight) throws FunctionException {
            if (highlight == null) {
                return new OrionOccurrenceOverlay[0];
            }
            final OrionOccurrenceOverlay[] occurrences = new OrionOccurrenceOverlay[1];
            final OrionOccurrenceOverlay occurrence = OrionOccurrenceOverlay.create();
            // FIXME: this assumes that the language server will
            // compute a range based on 'line 1', ie, the whole
            // file content is on line 1 and the location to
            // highlight is given by the 'character' position
            // only.
            occurrence.setStart(highlight.getRange().getStart().getCharacter());
            occurrence.setEnd(highlight.getRange().getEnd().getCharacter() + 1);
            occurrences[0] = occurrence;
            return occurrences;
        }
    });
    return (JsPromise<OrionOccurrenceOverlay[]>) then;
}
Also used : TextDocumentPositionParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO) FunctionException(org.eclipse.che.api.promises.client.FunctionException) JsPromise(org.eclipse.che.api.promises.client.js.JsPromise) Document(org.eclipse.che.ide.api.editor.document.Document) OrionOccurrenceOverlay(org.eclipse.che.ide.editor.orion.client.jso.OrionOccurrenceOverlay) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) LanguageServerEditorConfiguration(org.eclipse.che.plugin.languageserver.ide.editor.LanguageServerEditorConfiguration) DocumentHighlightDTO(org.eclipse.che.api.languageserver.shared.lsapi.DocumentHighlightDTO) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Example 19 with TextEditor

use of org.eclipse.che.ide.api.editor.texteditor.TextEditor 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 20 with TextEditor

use of org.eclipse.che.ide.api.editor.texteditor.TextEditor 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

TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)33 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)21 Project (org.eclipse.che.ide.api.resources.Project)8 Resource (org.eclipse.che.ide.api.resources.Resource)8 OperationException (org.eclipse.che.api.promises.client.OperationException)7 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)7 Operation (org.eclipse.che.api.promises.client.Operation)6 Document (org.eclipse.che.ide.api.editor.document.Document)5 TextEditorConfiguration (org.eclipse.che.ide.api.editor.editorconfig.TextEditorConfiguration)5 LanguageServerEditorConfiguration (org.eclipse.che.plugin.languageserver.ide.editor.LanguageServerEditorConfiguration)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 PromiseError (org.eclipse.che.api.promises.client.PromiseError)4 File (org.eclipse.che.ide.api.resources.File)4 Optional (com.google.common.base.Optional)3 ServerCapabilities (io.typefox.lsapi.ServerCapabilities)3 TextDocumentPositionParamsDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO)3 Collections.singletonList (java.util.Collections.singletonList)2 FunctionException (org.eclipse.che.api.promises.client.FunctionException)2 JsPromise (org.eclipse.che.api.promises.client.js.JsPromise)2