Search in sources :

Example 1 with EnumCaseMode

use of org.springframework.ide.vscode.boot.metadata.types.TypeUtil.EnumCaseMode in project sts4 by spring-projects.

the class PropertiesCompletionProposalsCalculator method getNavigationProposals.

/**
 * @param type Type of the expression leading upto the 'nav' operator
 * @param navOffset Offset of the nav operator (either ']' or '.'
 * @param offset Offset of the cursor where CA was requested.
 */
private Collection<ICompletionProposal> getNavigationProposals(Type type, int navOffset) {
    try {
        char navOp = doc.getChar(navOffset);
        if (navOp == '.') {
            String prefix = doc.get(navOffset + 1, offset - (navOffset + 1));
            EnumCaseMode caseMode = caseMode(prefix);
            List<TypedProperty> objectProperties = typeUtil.getProperties(type, caseMode, BeanPropertyNameMode.HYPHENATED);
            // Note: properties editor itself deals with relaxed names. So it expects the properties here to be returned in hyphenated form only.
            if (objectProperties != null && !objectProperties.isEmpty()) {
                return createPropertyProposals(type, navOffset, prefix, objectProperties);
            }
        } else {
        // TODO: other cases ']' or '[' ?
        }
    } catch (Exception e) {
        Log.log(e);
    }
    return Collections.emptyList();
}
Also used : EnumCaseMode(org.springframework.ide.vscode.boot.metadata.types.TypeUtil.EnumCaseMode) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException) TypedProperty(org.springframework.ide.vscode.boot.metadata.types.TypedProperty)

Example 2 with EnumCaseMode

use of org.springframework.ide.vscode.boot.metadata.types.TypeUtil.EnumCaseMode in project sts4 by spring-projects.

the class PropertiesCompletionProposalsCalculator method getValueCompletions.

private Collection<ICompletionProposal> getValueCompletions(Value value) {
    DocumentRegion valueRegion = createRegion(doc, value).trimStart(SPACES).trimEnd(SPACES);
    String query = valuePrefixFinder.getPrefix(doc, offset, valueRegion.getStart());
    int startOfValue = offset - query.length();
    EnumCaseMode caseMode = caseMode(query);
    // note: no need to skip whitespace backwards.
    String propertyName = /*fuzzySearchPrefix.getPrefix(doc, pair.getOffset())*/
    value.getParent().getKey().decode();
    // because value partition includes whitespace around the assignment
    if (propertyName != null) {
        Collection<StsValueHint> valueCompletions = getValueHints(index, typeUtil, query, propertyName, caseMode);
        if (valueCompletions != null && !valueCompletions.isEmpty()) {
            ArrayList<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
            for (StsValueHint hint : valueCompletions) {
                String valueCandidate = hint.getValue();
                double score = FuzzyMatcher.matchScore(query, valueCandidate);
                if (score != 0) {
                    DocumentEdits edits = new DocumentEdits(doc);
                    edits.delete(startOfValue, offset);
                    edits.insert(offset, valueCandidate);
                    String valueTypeName = typeUtil.niceTypeName(getValueType(index, typeUtil, propertyName));
                    proposals.add(completionFactory.valueProposal(valueCandidate, query, valueTypeName, score, edits, ValueHintHoverInfo.create(hint)));
                }
            }
            return proposals;
        }
    }
    return Collections.emptyList();
}
Also used : EnumCaseMode(org.springframework.ide.vscode.boot.metadata.types.TypeUtil.EnumCaseMode) DocumentEdits(org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits) StsValueHint(org.springframework.ide.vscode.boot.metadata.hints.StsValueHint) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion) ICompletionProposal(org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal) ArrayList(java.util.ArrayList) StsValueHint(org.springframework.ide.vscode.boot.metadata.hints.StsValueHint)

Aggregations

EnumCaseMode (org.springframework.ide.vscode.boot.metadata.types.TypeUtil.EnumCaseMode)2 ArrayList (java.util.ArrayList)1 StsValueHint (org.springframework.ide.vscode.boot.metadata.hints.StsValueHint)1 TypedProperty (org.springframework.ide.vscode.boot.metadata.types.TypedProperty)1 DocumentEdits (org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits)1 ICompletionProposal (org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal)1 BadLocationException (org.springframework.ide.vscode.commons.util.BadLocationException)1 DocumentRegion (org.springframework.ide.vscode.commons.util.text.DocumentRegion)1