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();
}
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());
}
}
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);
}
}
}
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();
}
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;
}
Aggregations