Search in sources :

Example 6 with DocumentRegion

use of org.springframework.ide.vscode.commons.util.text.DocumentRegion 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)

Example 7 with DocumentRegion

use of org.springframework.ide.vscode.commons.util.text.DocumentRegion 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 8 with DocumentRegion

use of org.springframework.ide.vscode.commons.util.text.DocumentRegion in project sts4 by spring-projects.

the class DuplicateNameChecker method check.

public void check(DocumentRegion nameRegion) throws Exception {
    String name = PropertiesFileEscapes.unescape(nameRegion.toString());
    if (!name.isEmpty()) {
        if (seen.containsKey(name)) {
            DocumentRegion pending = seen.get(name);
            if (pending != null) {
                reportDuplicate(pending);
                seen.put(name, null);
            }
            reportDuplicate(nameRegion);
        } else {
            seen.put(name, nameRegion);
        }
    }
}
Also used : DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion)

Example 9 with DocumentRegion

use of org.springframework.ide.vscode.commons.util.text.DocumentRegion in project sts4 by spring-projects.

the class IndentUtil method getReferenceIndent.

public String getReferenceIndent(int offset, IDocument doc) {
    // Apply indentfix, this is magic vscode seems to apply to edits returned by language server. So our harness has to
    // mimick that behavior. See https://github.com/Microsoft/language-server-protocol/issues/83
    IRegion referenceLine = doc.getLineInformationOfOffset(offset);
    DocumentRegion queryPrefix = new DocumentRegion(doc, referenceLine.getOffset(), offset);
    return queryPrefix.leadingWhitespace().toString();
}
Also used : DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion) IRegion(org.springframework.ide.vscode.commons.util.text.IRegion)

Example 10 with DocumentRegion

use of org.springframework.ide.vscode.commons.util.text.DocumentRegion in project sts4 by spring-projects.

the class ReconcileProblemImpl method makeVisible.

/**
 * Attempt to enlarge a empty document region to include a
 * character that can be visibly underlined.
 */
protected static DocumentRegion makeVisible(DocumentRegion region) {
    DocumentRegion altRegion = region.textAfter(1);
    if (!altRegion.isEmpty() && canUnderline(altRegion.charAt(0))) {
        return altRegion;
    }
    altRegion = region.textBefore(1);
    if (!altRegion.isEmpty() && canUnderline(altRegion.charAt(0))) {
        return altRegion;
    }
    return region;
}
Also used : DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion)

Aggregations

DocumentRegion (org.springframework.ide.vscode.commons.util.text.DocumentRegion)25 ICompletionProposal (org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal)6 PropertyInfo (org.springframework.ide.vscode.boot.metadata.PropertyInfo)5 ArrayList (java.util.ArrayList)4 BadLocationException (org.springframework.ide.vscode.commons.util.BadLocationException)4 ValueParseException (org.springframework.ide.vscode.commons.util.ValueParseException)4 StsValueHint (org.springframework.ide.vscode.boot.metadata.hints.StsValueHint)3 Type (org.springframework.ide.vscode.boot.metadata.types.Type)3 DocumentEdits (org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits)3 Renderable (org.springframework.ide.vscode.commons.util.Renderable)3 IRegion (org.springframework.ide.vscode.commons.util.text.IRegion)3 ImmutableList (com.google.common.collect.ImmutableList)2 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)2 Location (org.eclipse.lsp4j.Location)2 SymbolInformation (org.eclipse.lsp4j.SymbolInformation)2 CommonLanguageTools.getValueType (org.springframework.ide.vscode.boot.common.CommonLanguageTools.getValueType)2 EnumCaseMode (org.springframework.ide.vscode.boot.metadata.types.TypeUtil.EnumCaseMode)2 PropertyNavigator (org.springframework.ide.vscode.boot.properties.reconcile.PropertyNavigator)2 ReconcileException (org.springframework.ide.vscode.commons.languageserver.reconcile.ReconcileException)2 IDocument (org.springframework.ide.vscode.commons.util.text.IDocument)2