Search in sources :

Example 1 with SymbolInformationDTO

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

the class GoToSymbolAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    DocumentSymbolParamsDTO paramsDTO = dtoFactory.createDto(DocumentSymbolParamsDTO.class);
    TextDocumentIdentifierDTO identifierDTO = dtoFactory.createDto(TextDocumentIdentifierDTO.class);
    identifierDTO.setUri(editorAgent.getActiveEditor().getEditorInput().getFile().getLocation().toString());
    paramsDTO.setTextDocument(identifierDTO);
    activeEditor = (TextEditor) editorAgent.getActiveEditor();
    cursorPosition = activeEditor.getDocument().getCursorPosition();
    client.documentSymbol(paramsDTO).then(new Operation<List<SymbolInformationDTO>>() {

        @Override
        public void apply(List<SymbolInformationDTO> arg) throws OperationException {
            cachedItems = arg;
            presenter.run(GoToSymbolAction.this);
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            notificationManager.notify("Can't fetch document symbols.", arg.getMessage(), StatusNotification.Status.FAIL, StatusNotification.DisplayMode.FLOAT_MODE);
        }
    });
}
Also used : SymbolInformationDTO(org.eclipse.che.api.languageserver.shared.lsapi.SymbolInformationDTO) DocumentSymbolParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.DocumentSymbolParamsDTO) PromiseError(org.eclipse.che.api.promises.client.PromiseError) TextDocumentIdentifierDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentIdentifierDTO) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 2 with SymbolInformationDTO

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

the class FindSymbolAction method toSymbolEntries.

private List<SymbolEntry> toSymbolEntries(List<SymbolInformationDTO> types, String value) {
    List<SymbolEntry> result = new ArrayList<>();
    for (SymbolInformationDTO element : types) {
        if (!SUPPORTED_OPEN_TYPES.contains(symbolKindHelper.from(element.getKind()))) {
            continue;
        }
        List<Match> matches = fuzzyMatches.fuzzyMatch(value, element.getName());
        if (matches != null) {
            LocationDTO location = element.getLocation();
            if (location != null && location.getUri() != null) {
                String filePath = location.getUri();
                RangeDTO locationRange = location.getRange();
                TextRange range = null;
                if (locationRange != null) {
                    range = new TextRange(new TextPosition(locationRange.getStart().getLine(), locationRange.getStart().getCharacter()), new TextPosition(locationRange.getEnd().getLine(), locationRange.getEnd().getCharacter()));
                }
                result.add(new SymbolEntry(element.getName(), "", filePath, filePath, symbolKindHelper.from(element.getKind()), range, symbolKindHelper.getIcon(element.getKind()), editorHelper, matches));
            }
        }
    }
    //TODO add sorting
    return result;
}
Also used : SymbolInformationDTO(org.eclipse.che.api.languageserver.shared.lsapi.SymbolInformationDTO) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) ArrayList(java.util.ArrayList) TextRange(org.eclipse.che.ide.api.editor.text.TextRange) LocationDTO(org.eclipse.che.api.languageserver.shared.lsapi.LocationDTO) RangeDTO(org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO) Match(org.eclipse.che.plugin.languageserver.ide.filters.Match)

Example 3 with SymbolInformationDTO

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

the class FindSymbolAction method searchSymbols.

private Promise<List<SymbolEntry>> searchSymbols(final String value) {
    WorkspaceSymbolParamsDTO params = dtoFactory.createDto(WorkspaceSymbolParamsDTO.class);
    params.setQuery(value);
    params.setFileUri(editorAgent.getActiveEditor().getEditorInput().getFile().getLocation().toString());
    return workspaceServiceClient.symbol(params).then(new Function<List<SymbolInformationDTO>, List<SymbolEntry>>() {

        @Override
        public List<SymbolEntry> apply(List<SymbolInformationDTO> types) throws FunctionException {
            return toSymbolEntries(types, value);
        }
    });
}
Also used : SymbolInformationDTO(org.eclipse.che.api.languageserver.shared.lsapi.SymbolInformationDTO) FunctionException(org.eclipse.che.api.promises.client.FunctionException) WorkspaceSymbolParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.WorkspaceSymbolParamsDTO) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List)

Example 4 with SymbolInformationDTO

use of org.eclipse.che.api.languageserver.shared.lsapi.SymbolInformationDTO 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)

Aggregations

ArrayList (java.util.ArrayList)4 SymbolInformationDTO (org.eclipse.che.api.languageserver.shared.lsapi.SymbolInformationDTO)4 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 RangeDTO (org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO)2 TextPosition (org.eclipse.che.ide.api.editor.text.TextPosition)2 TextRange (org.eclipse.che.ide.api.editor.text.TextRange)2 Match (org.eclipse.che.plugin.languageserver.ide.filters.Match)2 DocumentSymbolParamsDTO (org.eclipse.che.api.languageserver.shared.lsapi.DocumentSymbolParamsDTO)1 LocationDTO (org.eclipse.che.api.languageserver.shared.lsapi.LocationDTO)1 TextDocumentIdentifierDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentIdentifierDTO)1 WorkspaceSymbolParamsDTO (org.eclipse.che.api.languageserver.shared.lsapi.WorkspaceSymbolParamsDTO)1 FunctionException (org.eclipse.che.api.promises.client.FunctionException)1 Operation (org.eclipse.che.api.promises.client.Operation)1 OperationException (org.eclipse.che.api.promises.client.OperationException)1 PromiseError (org.eclipse.che.api.promises.client.PromiseError)1 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)1