Search in sources :

Example 1 with ISubCompletionEngine

use of org.springframework.ide.vscode.commons.yaml.schema.ISubCompletionEngine in project sts4 by spring-projects.

the class YTypeAssistContext method getCompletions.

@Override
public Collection<ICompletionProposal> getCompletions(YamlDocument doc, SNode node, int offset) throws Exception {
    ISubCompletionEngine customContentAssistant = typeUtil.getCustomContentAssistant(type);
    if (customContentAssistant != null) {
        DocumentRegion region = getCustomAssistRegion(doc, node, offset);
        if (region != null) {
            return customContentAssistant.getCompletions(completionFactory(), region, region.toRelative(offset));
        }
    }
    String query = getPrefix(doc, node, offset);
    List<ICompletionProposal> completions = getValueCompletions(doc, node, offset, query);
    if (completions.isEmpty()) {
        TypeBasedSnippetProvider snippetProvider = typeUtil.getSnippetProvider();
        if (snippetProvider != null) {
            Collection<Snippet> snippets = snippetProvider.getSnippets(type);
            YamlIndentUtil indenter = new YamlIndentUtil(doc);
            for (Snippet snippet : snippets) {
                String snippetName = snippet.getName();
                double score = FuzzyMatcher.matchScore(query, snippetName);
                if (score != 0.0 && snippet.isApplicable(getSchemaContext())) {
                    DocumentEdits edits = createEditFromSnippet(doc, node, offset, query, indenter, snippet);
                    completions.add(completionFactory().valueProposal(snippetName, query, snippetName, type, null, score, edits, typeUtil));
                }
            }
        }
        completions.addAll(getKeyCompletions(doc, node, offset, query));
    }
    if (typeUtil.isSequencable(type)) {
        completions = new ArrayList<>(completions);
        completions.addAll(getDashedCompletions(doc, node, offset));
    }
    return completions;
}
Also used : DocumentEdits(org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits) YamlIndentUtil(org.springframework.ide.vscode.commons.yaml.util.YamlIndentUtil) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion) ICompletionProposal(org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal) TypeBasedSnippetProvider(org.springframework.ide.vscode.commons.yaml.snippet.TypeBasedSnippetProvider) Snippet(org.springframework.ide.vscode.commons.yaml.snippet.Snippet) ISubCompletionEngine(org.springframework.ide.vscode.commons.yaml.schema.ISubCompletionEngine)

Aggregations

DocumentEdits (org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits)1 ICompletionProposal (org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal)1 DocumentRegion (org.springframework.ide.vscode.commons.util.text.DocumentRegion)1 ISubCompletionEngine (org.springframework.ide.vscode.commons.yaml.schema.ISubCompletionEngine)1 Snippet (org.springframework.ide.vscode.commons.yaml.snippet.Snippet)1 TypeBasedSnippetProvider (org.springframework.ide.vscode.commons.yaml.snippet.TypeBasedSnippetProvider)1 YamlIndentUtil (org.springframework.ide.vscode.commons.yaml.util.YamlIndentUtil)1