Search in sources :

Example 1 with PropertyInfo

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

the class ValueCompletionProcessor method computeProposalsForStringLiteral.

private void computeProposalsForStringLiteral(ASTNode node, List<ICompletionProposal> completions, int offset, IDocument doc, FuzzyMap<PropertyInfo> index) throws BadLocationException {
    String prefix = identifyPropertyPrefix(doc.get(node.getStartPosition() + 1, offset - (node.getStartPosition() + 1)), offset - (node.getStartPosition() + 1));
    int startOffset = offset - prefix.length();
    int endOffset = offset;
    String prePrefix = doc.get(node.getStartPosition() + 1, offset - prefix.length() - node.getStartPosition() - 1);
    String preCompletion;
    if (prePrefix.endsWith("${")) {
        preCompletion = "";
    } else if (prePrefix.endsWith("$")) {
        preCompletion = "{";
    } else {
        preCompletion = "${";
    }
    String fullNodeContent = doc.get(node.getStartPosition(), node.getLength());
    String postCompletion = isClosingBracketMissing(fullNodeContent + preCompletion) ? "}" : "";
    List<Match<PropertyInfo>> matches = findMatches(prefix, index);
    for (Match<PropertyInfo> match : matches) {
        DocumentEdits edits = new DocumentEdits(doc);
        edits.replace(startOffset, endOffset, preCompletion + match.data.getId() + postCompletion);
        ValuePropertyKeyProposal proposal = new ValuePropertyKeyProposal(edits, match.data.getId(), match.data.getName(), null);
        completions.add(proposal);
    }
}
Also used : DocumentEdits(org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits) PropertyInfo(org.springframework.ide.vscode.boot.metadata.PropertyInfo) Match(org.springframework.ide.vscode.commons.util.FuzzyMap.Match)

Example 2 with PropertyInfo

use of org.springframework.ide.vscode.boot.metadata.PropertyInfo 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 3 with PropertyInfo

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

the class PropertiesHoverCalculator method getPropertyHover.

private Tuple2<Renderable, IRegion> getPropertyHover(Key property) {
    PropertyInfo best = findBestHoverMatch(property.decode());
    if (best == null) {
        return null;
    } else {
        Renderable renderable = InformationTemplates.createHover(best);
        DocumentRegion region = createRegion(doc, property);
        return Tuples.of(renderable, region.asRegion());
    }
}
Also used : Renderable(org.springframework.ide.vscode.commons.util.Renderable) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion) PropertyInfo(org.springframework.ide.vscode.boot.metadata.PropertyInfo)

Example 4 with PropertyInfo

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

the class CommonLanguageTools method getValueHints.

public static Collection<StsValueHint> getValueHints(FuzzyMap<PropertyInfo> index, TypeUtil typeUtil, String query, String propertyName, EnumCaseMode caseMode) {
    Type type = getValueType(index, typeUtil, propertyName);
    if (TypeUtil.isSequencable(type)) {
        // It is useful to provide content assist for the values in the list when entering a list
        type = TypeUtil.getDomainType(type);
    }
    List<StsValueHint> allHints = new ArrayList<>();
    {
        Collection<StsValueHint> hints = typeUtil.getHintValues(type, query, caseMode);
        if (CollectionUtil.hasElements(hints)) {
            allHints.addAll(hints);
        }
    }
    {
        PropertyInfo prop = index.findLongestCommonPrefixEntry(propertyName);
        if (prop != null) {
            HintProvider hintProvider = prop.getHints(typeUtil, false);
            if (!HintProviders.isNull(hintProvider)) {
                allHints.addAll(hintProvider.getValueHints(query));
            }
        }
    }
    return allHints;
}
Also used : Type(org.springframework.ide.vscode.boot.metadata.types.Type) StsValueHint(org.springframework.ide.vscode.boot.metadata.hints.StsValueHint) ArrayList(java.util.ArrayList) Collection(java.util.Collection) HintProvider(org.springframework.ide.vscode.boot.metadata.hints.HintProvider) PropertyInfo(org.springframework.ide.vscode.boot.metadata.PropertyInfo)

Example 5 with PropertyInfo

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

the class ApplicationYamlEditorTest method testBootBug5905.

@Test
public void testBootBug5905() throws Exception {
    useProject(createPredefinedMavenProject("boot-1.3.3-app-with-resource-prop"));
    // Check the metadata reflects the 'handle-as':
    PropertyInfo metadata = getIndexProvider().getIndex(null).get("my.welcome.path");
    assertEquals("org.springframework.core.io.Resource", metadata.getType());
    // Check the content assist based on it works too:
    assertCompletionsDisplayString("my:\n" + "  welcome:\n" + "    path: <*>", // =>
    "classpath:", "classpath*:", "file:", "http://", "https://");
}
Also used : PropertyInfo(org.springframework.ide.vscode.boot.metadata.PropertyInfo) AbstractPropsEditorTest(org.springframework.ide.vscode.boot.editor.harness.AbstractPropsEditorTest) Test(org.junit.Test)

Aggregations

PropertyInfo (org.springframework.ide.vscode.boot.metadata.PropertyInfo)12 Type (org.springframework.ide.vscode.boot.metadata.types.Type)5 DocumentEdits (org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits)4 Match (org.springframework.ide.vscode.commons.util.FuzzyMap.Match)4 DocumentRegion (org.springframework.ide.vscode.commons.util.text.DocumentRegion)4 ArrayList (java.util.ArrayList)3 StsValueHint (org.springframework.ide.vscode.boot.metadata.hints.StsValueHint)3 ICompletionProposal (org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal)3 BadLocationException (org.springframework.ide.vscode.commons.util.BadLocationException)3 CommonLanguageTools.getValueType (org.springframework.ide.vscode.boot.common.CommonLanguageTools.getValueType)2 PropertyNavigator (org.springframework.ide.vscode.boot.properties.reconcile.PropertyNavigator)2 Collection (java.util.Collection)1 Annotation (org.eclipse.jdt.core.dom.Annotation)1 MemberValuePair (org.eclipse.jdt.core.dom.MemberValuePair)1 SimpleName (org.eclipse.jdt.core.dom.SimpleName)1 StringLiteral (org.eclipse.jdt.core.dom.StringLiteral)1 Test (org.junit.Test)1 AbstractPropsEditorTest (org.springframework.ide.vscode.boot.editor.harness.AbstractPropsEditorTest)1 IndexNavigator (org.springframework.ide.vscode.boot.metadata.IndexNavigator)1 HintProvider (org.springframework.ide.vscode.boot.metadata.hints.HintProvider)1