Search in sources :

Example 6 with DocumentEdits

use of org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits in project sts4 by spring-projects.

the class PropertiesCompletionProposalsCalculator method getFuzzyCompletions.

protected Collection<ICompletionProposal> getFuzzyCompletions() {
    final String prefix = fuzzySearchPrefix.getPrefix(doc, offset);
    if (prefix != null) {
        Collection<Match<PropertyInfo>> matches = findMatches(prefix);
        if (matches != null && !matches.isEmpty()) {
            ArrayList<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>(matches.size());
            for (final Match<PropertyInfo> match : matches) {
                DocumentEdits docEdits;
                try {
                    docEdits = LazyProposalApplier.from(() -> {
                        try {
                            Type type = TypeParser.parse(match.data.getType());
                            DocumentEdits edits = new DocumentEdits(doc);
                            edits.delete(offset - prefix.length(), offset);
                            edits.insert(offset, match.data.getId() + propertyCompletionPostfix(typeUtil, type));
                            return edits;
                        } catch (Throwable t) {
                            Log.log(t);
                            return new DocumentEdits(doc);
                        }
                    });
                    proposals.add(completionFactory.property(doc, docEdits, match, typeUtil));
                } catch (Throwable e) {
                    Log.log(e);
                }
            }
            return proposals;
        }
    }
    return Collections.emptyList();
}
Also used : CommonLanguageTools.getValueType(org.springframework.ide.vscode.boot.common.CommonLanguageTools.getValueType) Type(org.springframework.ide.vscode.boot.metadata.types.Type) DocumentEdits(org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits) ICompletionProposal(org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal) ArrayList(java.util.ArrayList) PropertyInfo(org.springframework.ide.vscode.boot.metadata.PropertyInfo) Match(org.springframework.ide.vscode.commons.util.FuzzyMap.Match)

Example 7 with DocumentEdits

use of org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits in project sts4 by spring-projects.

the class ScopeNameCompletionProposal method getTextEdit.

@Override
public DocumentEdits getTextEdit() {
    DocumentEdits edits = new DocumentEdits(doc);
    edits.replace(startOffset + prefix.length(), endOffset, completion.getValue().substring(prefix.length()));
    return edits;
}
Also used : DocumentEdits(org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits)

Example 8 with DocumentEdits

use of org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits in project sts4 by spring-projects.

the class JavaSnippetBuilder method createEdit.

public DocumentEdits createEdit(DocumentRegion query, String template) {
    IDocument doc = query.getDocument();
    IndentUtil indentUtil = new IndentUtil(doc);
    DocumentEdits edit = new DocumentEdits(doc);
    String snippet = createSnippet(template);
    String referenceIndent = indentUtil.getReferenceIndent(query.getStart(), doc);
    if (!referenceIndent.contains("\t")) {
        snippet = indentUtil.covertTabsToSpace(snippet);
    }
    String indentedSnippet = indentUtil.applyIndentation(snippet, referenceIndent);
    edit.replace(query.getStart(), query.getEnd(), indentedSnippet);
    return edit;
}
Also used : DocumentEdits(org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits) IndentUtil(org.springframework.ide.vscode.commons.languageserver.completion.IndentUtil) IDocument(org.springframework.ide.vscode.commons.util.text.IDocument)

Example 9 with DocumentEdits

use of org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits in project sts4 by spring-projects.

the class JavaSnippetCompletion method getAdditionalEdit.

@Override
public Optional<DocumentEdits> getAdditionalEdit() {
    ImportRewrite rewrite = ImportRewrite.create(cu, true);
    javaSnippet.getImports().ifPresent((imprts -> {
        for (String imprt : imprts) {
            rewrite.addImport(imprt);
        }
    }));
    DocumentEdits edit = rewrite.createEdit(query.getDocument());
    return edit != null ? Optional.of(edit) : Optional.empty();
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) CompletionItemKind(org.eclipse.lsp4j.CompletionItemKind) ImportRewrite(org.springframework.ide.vscode.boot.java.jdt.imports.ImportRewrite) DocumentEdits(org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits) ICompletionProposal(org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion) Renderables(org.springframework.ide.vscode.commons.util.Renderables) Supplier(com.google.common.base.Supplier) Optional(java.util.Optional) Renderable(org.springframework.ide.vscode.commons.util.Renderable) SnippetBuilder(org.springframework.ide.vscode.commons.languageserver.util.SnippetBuilder) ImportRewrite(org.springframework.ide.vscode.boot.java.jdt.imports.ImportRewrite) DocumentEdits(org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits)

Example 10 with DocumentEdits

use of org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits in project sts4 by spring-projects.

the class ValueCompletionProcessor method computeProposalsForSimpleName.

private void computeProposalsForSimpleName(ASTNode node, List<ICompletionProposal> completions, int offset, IDocument doc, FuzzyMap<PropertyInfo> index) {
    String prefix = identifyPropertyPrefix(node.toString(), offset - node.getStartPosition());
    int startOffset = node.getStartPosition();
    int endOffset = node.getStartPosition() + node.getLength();
    String proposalPrefix = "\"";
    String proposalPostfix = "\"";
    List<Match<PropertyInfo>> matches = findMatches(prefix, index);
    for (Match<PropertyInfo> match : matches) {
        DocumentEdits edits = new DocumentEdits(doc);
        edits.replace(startOffset, endOffset, proposalPrefix + "${" + match.data.getId() + "}" + proposalPostfix);
        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)

Aggregations

DocumentEdits (org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits)18 ICompletionProposal (org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal)8 ArrayList (java.util.ArrayList)7 DocumentRegion (org.springframework.ide.vscode.commons.util.text.DocumentRegion)5 YamlIndentUtil (org.springframework.ide.vscode.commons.yaml.util.YamlIndentUtil)5 PropertyInfo (org.springframework.ide.vscode.boot.metadata.PropertyInfo)4 Match (org.springframework.ide.vscode.commons.util.FuzzyMap.Match)4 ScoreableProposal (org.springframework.ide.vscode.commons.languageserver.completion.ScoreableProposal)3 YValueHint (org.springframework.ide.vscode.commons.yaml.schema.YValueHint)3 ImmutableList (com.google.common.collect.ImmutableList)2 List (java.util.List)2 CommonLanguageTools.getValueType (org.springframework.ide.vscode.boot.common.CommonLanguageTools.getValueType)2 Type (org.springframework.ide.vscode.boot.metadata.types.Type)2 Renderable (org.springframework.ide.vscode.commons.util.Renderable)2 Strings (com.google.common.base.Strings)1 Supplier (com.google.common.base.Supplier)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Optional (java.util.Optional)1