use of org.springframework.ide.vscode.commons.util.FuzzyMap.Match 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);
}
}
use of org.springframework.ide.vscode.commons.util.FuzzyMap.Match 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();
}
use of org.springframework.ide.vscode.commons.util.FuzzyMap.Match 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);
}
}
use of org.springframework.ide.vscode.commons.util.FuzzyMap.Match in project sts4 by spring-projects.
the class ValueCompletionProcessor method provideCompletions.
@Override
public Collection<ICompletionProposal> provideCompletions(ASTNode node, Annotation annotation, ITypeBinding type, int offset, IDocument doc) {
List<ICompletionProposal> result = new ArrayList<>();
try {
FuzzyMap<PropertyInfo> index = indexProvider.getIndex(doc);
// case: @Value(<*>)
if (node == annotation && doc.get(offset - 1, 2).endsWith("()")) {
List<Match<PropertyInfo>> matches = findMatches("", index);
for (Match<PropertyInfo> match : matches) {
DocumentEdits edits = new DocumentEdits(doc);
edits.replace(offset, offset, "\"${" + match.data.getId() + "}\"");
ValuePropertyKeyProposal proposal = new ValuePropertyKeyProposal(edits, match.data.getId(), match.data.getName(), null);
result.add(proposal);
}
} else // case: @Value(prefix<*>)
if (node instanceof SimpleName && node.getParent() instanceof Annotation) {
computeProposalsForSimpleName(node, result, offset, doc, index);
} else // case: @Value(value=<*>)
if (node instanceof SimpleName && node.getParent() instanceof MemberValuePair && "value".equals(((MemberValuePair) node.getParent()).getName().toString())) {
computeProposalsForSimpleName(node, result, offset, doc, index);
} else // case: @Value("prefix<*>")
if (node instanceof StringLiteral && node.getParent() instanceof Annotation) {
if (node.toString().startsWith("\"") && node.toString().endsWith("\"")) {
computeProposalsForStringLiteral(node, result, offset, doc, index);
}
} else // case: @Value(value="prefix<*>")
if (node instanceof StringLiteral && node.getParent() instanceof MemberValuePair && "value".equals(((MemberValuePair) node.getParent()).getName().toString())) {
if (node.toString().startsWith("\"") && node.toString().endsWith("\"")) {
computeProposalsForStringLiteral(node, result, offset, doc, index);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
Aggregations