use of org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal 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.languageserver.completion.ICompletionProposal in project sts4 by spring-projects.
the class ScopeCompletionProcessor method provideCompletions.
@Override
public Collection<ICompletionProposal> provideCompletions(ASTNode node, Annotation annotation, ITypeBinding type, int offset, IDocument doc) {
List<ICompletionProposal> result = new ArrayList<>();
try {
if (node instanceof SimpleName && node.getParent() instanceof MemberValuePair) {
MemberValuePair memberPair = (MemberValuePair) node.getParent();
// case: @Scope(value=<*>)
if ("value".equals(memberPair.getName().toString()) && memberPair.getValue().toString().equals("$missing$")) {
for (ScopeNameCompletion completion : ScopeNameCompletionProposal.COMPLETIONS) {
ICompletionProposal proposal = new ScopeNameCompletionProposal(completion, doc, offset, offset, "");
result.add(proposal);
}
}
} else // case: @Scope(<*>)
if (node == annotation && doc.get(offset - 1, 2).endsWith("()")) {
for (ScopeNameCompletion completion : ScopeNameCompletionProposal.COMPLETIONS) {
ICompletionProposal proposal = new ScopeNameCompletionProposal(completion, doc, offset, offset, "");
result.add(proposal);
}
} else if (node instanceof StringLiteral && node.getParent() instanceof Annotation) {
// case: @Scope("...")
if (node.toString().startsWith("\"") && node.toString().endsWith("\"")) {
String prefix = doc.get(node.getStartPosition(), offset - node.getStartPosition());
for (ScopeNameCompletion completion : ScopeNameCompletionProposal.COMPLETIONS) {
if (completion.getValue().startsWith(prefix)) {
ICompletionProposal proposal = new ScopeNameCompletionProposal(completion, doc, node.getStartPosition(), node.getStartPosition() + node.getLength(), prefix);
result.add(proposal);
}
}
}
} else if (node instanceof StringLiteral && node.getParent() instanceof MemberValuePair) {
MemberValuePair memberPair = (MemberValuePair) node.getParent();
// case: @Scope(value=<*>)
if ("value".equals(memberPair.getName().toString()) && node.toString().startsWith("\"") && node.toString().endsWith("\"")) {
String prefix = doc.get(node.getStartPosition(), offset - node.getStartPosition());
for (ScopeNameCompletion completion : ScopeNameCompletionProposal.COMPLETIONS) {
if (completion.getValue().startsWith(prefix)) {
ICompletionProposal proposal = new ScopeNameCompletionProposal(completion, doc, node.getStartPosition(), node.getStartPosition() + node.getLength(), prefix);
result.add(proposal);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
use of org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal in project sts4 by spring-projects.
the class GithubRepoContentAssistant method getCompletions.
@Override
public List<ICompletionProposal> getCompletions(CompletionFactory f, DocumentRegion region, int offset) {
DocumentRegion query = region.subSequence(0, offset);
// If uri prefix is already there, we provide CA for owner / repo
for (String uriPrefix : URI_PREFIXES) {
if (query.startsWith(uriPrefix)) {
return getOwnerOrRepoCompletions(f, query.subSequence(uriPrefix.length()));
}
}
// If uri prefix is not yet there, maybe we can suggest it (if it matches the query)
List<ICompletionProposal> proposals = new ArrayList<>(URI_PREFIXES.length);
for (String uriPrefix : URI_PREFIXES) {
if (FuzzyMatcher.matchScore(query, uriPrefix) != 0.0) {
proposals.add(SimpleCompletionFactory.simpleProposal(query, CompletionItemKind.Text, uriPrefix, null, null));
}
}
return proposals;
}
use of org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal in project sts4 by spring-projects.
the class BootJavaCompletionEngine method getCompletions.
@Override
public Collection<ICompletionProposal> getCompletions(TextDocument document, int offset) throws Exception {
return server.getCompilationUnitCache().withCompilationUnit(document, cu -> {
if (cu != null) {
ASTNode node = NodeFinder.perform(cu, offset, 0);
if (node != null) {
Collection<ICompletionProposal> completions = new ArrayList<ICompletionProposal>();
completions.addAll(collectCompletionsForAnnotations(node, offset, document));
completions.addAll(snippets.getCompletions(document, offset, node, cu));
return completions;
}
}
return Collections.emptyList();
});
}
use of org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal in project sts4 by spring-projects.
the class RouteContentAssistant method getCompletions.
@Override
public List<ICompletionProposal> getCompletions(CompletionFactory f, DocumentRegion region, int offset) {
// offset = 2 means: "ab<*>c"
try {
region = chopEnd(region, offset);
// So offset > 3 means we are 'our of bounds for this content assistant
if (offset <= region.length()) {
String[] queries = getQueries(region.subSequence(0, offset));
Collection<YValueHint> domains = domainsProvider.call();
List<ICompletionProposal> proposals = new ArrayList<>();
for (YValueHint domain : domains) {
for (String query : queries) {
double score = FuzzyMatcher.matchScore(query, domain.getValue());
if (score != 0.0) {
proposals.add(createProposal(f, region, offset, query, score, domain));
// break here so we select the first (i.e. longest) query that matches
break;
}
}
}
return proposals;
}
} catch (Exception e) {
Log.log(e);
// Ignore. This is somewhat expected. Stuff can go wrong resolving the domains
// and CA engine just doesn't provide CA in that case.
}
return ImmutableList.of();
}
Aggregations