Search in sources :

Example 1 with PropertyNavigator

use of org.springframework.ide.vscode.boot.properties.reconcile.PropertyNavigator in project sts4 by spring-projects.

the class PropertiesCompletionProposalsCalculator method getNavigationProposals.

private Collection<ICompletionProposal> getNavigationProposals() {
    String navPrefix = navigationPrefixFinder.getPrefix(doc, offset);
    try {
        if (navPrefix != null) {
            // offset of 'nav' operator char (i.e. '.' or ']').
            int navOffset = offset - navPrefix.length() - 1;
            navPrefix = fuzzySearchPrefix.getPrefix(doc, navOffset);
            if (navPrefix != null && !navPrefix.isEmpty()) {
                PropertyInfo prop = findLongestValidProperty(index, navPrefix);
                if (prop != null) {
                    int regionStart = navOffset - navPrefix.length();
                    Collection<ICompletionProposal> hintProposals = getKeyHintProposals(prop, navOffset);
                    if (CollectionUtil.hasElements(hintProposals)) {
                        return hintProposals;
                    }
                    PropertyNavigator navigator = new PropertyNavigator(doc, null, typeUtil, new DocumentRegion(doc, regionStart, navOffset));
                    Type type = navigator.navigate(regionStart + prop.getId().length(), TypeParser.parse(prop.getType()));
                    if (type != null) {
                        return getNavigationProposals(type, navOffset);
                    }
                }
            }
        }
    } catch (Exception e) {
        Log.log(e);
    }
    return Collections.emptyList();
}
Also used : CommonLanguageTools.getValueType(org.springframework.ide.vscode.boot.common.CommonLanguageTools.getValueType) Type(org.springframework.ide.vscode.boot.metadata.types.Type) ICompletionProposal(org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion) PropertyNavigator(org.springframework.ide.vscode.boot.properties.reconcile.PropertyNavigator) PropertyInfo(org.springframework.ide.vscode.boot.metadata.PropertyInfo) StsValueHint(org.springframework.ide.vscode.boot.metadata.hints.StsValueHint) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException)

Example 2 with PropertyNavigator

use of org.springframework.ide.vscode.boot.properties.reconcile.PropertyNavigator in project sts4 by spring-projects.

the class CommonLanguageTools method getValueType.

/**
 * Determine the value type for a give propertyName.
 */
public static Type getValueType(FuzzyMap<PropertyInfo> index, TypeUtil typeUtil, String propertyName) {
    try {
        PropertyInfo prop = index.get(propertyName);
        if (prop != null) {
            return TypeParser.parse(prop.getType());
        } else {
            prop = CommonLanguageTools.findLongestValidProperty(index, propertyName);
            if (prop != null) {
                TextDocument doc = new TextDocument(null, LanguageId.PLAINTEXT);
                doc.setText(propertyName);
                PropertyNavigator navigator = new PropertyNavigator(doc, null, typeUtil, new DocumentRegion(doc, 0, doc.getLength()));
                return navigator.navigate(prop.getId().length(), TypeParser.parse(prop.getType()));
            }
        }
    } catch (Exception e) {
        Log.log(e);
    }
    return null;
}
Also used : TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion) PropertyNavigator(org.springframework.ide.vscode.boot.properties.reconcile.PropertyNavigator) PropertyInfo(org.springframework.ide.vscode.boot.metadata.PropertyInfo)

Aggregations

PropertyInfo (org.springframework.ide.vscode.boot.metadata.PropertyInfo)2 PropertyNavigator (org.springframework.ide.vscode.boot.properties.reconcile.PropertyNavigator)2 DocumentRegion (org.springframework.ide.vscode.commons.util.text.DocumentRegion)2 CommonLanguageTools.getValueType (org.springframework.ide.vscode.boot.common.CommonLanguageTools.getValueType)1 StsValueHint (org.springframework.ide.vscode.boot.metadata.hints.StsValueHint)1 Type (org.springframework.ide.vscode.boot.metadata.types.Type)1 ICompletionProposal (org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal)1 BadLocationException (org.springframework.ide.vscode.commons.util.BadLocationException)1 TextDocument (org.springframework.ide.vscode.commons.util.text.TextDocument)1