use of org.springframework.ide.vscode.commons.yaml.schema.YValueHint in project sts4 by spring-projects.
the class YTypeAssistContext method getValueCompletions.
private List<ICompletionProposal> getValueCompletions(YamlDocument doc, SNode node, int offset, String query) {
PartialCollection<YValueHint> _values = typeUtil.getHintValues(type, getSchemaContext());
if (_values.getExplanation() != null && _values.getElements().isEmpty() && !Boolean.getBoolean("lsp.yaml.completions.errors.disable")) {
return ImmutableList.of(completionFactory().errorMessage(query, getMessage(_values.getExplanation())));
}
Collection<YValueHint> values = _values.getElements();
if (values != null) {
ArrayList<ICompletionProposal> completions = new ArrayList<>();
YamlIndentUtil indenter = new YamlIndentUtil(doc);
int referenceIndent;
try {
referenceIndent = getContextNode().getIndent();
} catch (Exception e) {
// Getting it from the node isn't always correct, but more often than not it is.
// So this fallback is better than nothing.
referenceIndent = node.getIndent();
}
for (YValueHint value : values) {
double score = FuzzyMatcher.matchScore(query, value.getValue());
if (score != 0 && value != null && !query.equals(value.getValue())) {
int queryStart = offset - query.length();
DocumentEdits edits = new DocumentEdits(doc.getDocument());
edits.delete(queryStart, offset);
if (!Character.isWhitespace(doc.getChar(queryStart - 1))) {
edits.insert(offset, " ");
}
edits.insert(offset, value.getValue());
String extraInsertion = value.getExtraInsertion();
if (extraInsertion != null) {
edits.insert(offset, indenter.applyIndentation(extraInsertion, referenceIndent));
}
completions.add(completionFactory().valueProposal(value.getValue(), query, value.getLabel(), type, value.getDocumentation(), score, edits, typeUtil));
}
}
return completions;
}
return Collections.emptyList();
}
use of org.springframework.ide.vscode.commons.yaml.schema.YValueHint in project sts4 by spring-projects.
the class ConcourseModel method addExtraInsertion.
private YValueHint addExtraInsertion(YValueHint h, DynamicSchemaContext dc) {
return new BasicYValueHint(h.getValue(), h.getLabel()).setExtraInsertion(() -> {
String resourceTypeName = h.getValue();
AbstractType sourceType = (AbstractType) resourceTypes.getSourceType(resourceTypeName);
if (sourceType != null && getParentPropertyNode("source", dc) == null) {
// don't auto insert what's already there!
List<YTypedProperty> requiredProps = sourceType.getProperties().stream().filter(p -> p.isRequired()).collect(Collectors.toList());
if (!requiredProps.isEmpty()) {
SnippetBuilder snippet = snippetBuilderFactory.get();
snippet.text("\nsource:");
for (YTypedProperty p : requiredProps) {
snippet.text("\n " + p.getName() + ": ");
snippet.placeHolder();
}
return snippet.toString();
}
}
return null;
});
}
use of org.springframework.ide.vscode.commons.yaml.schema.YValueHint 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();
}
use of org.springframework.ide.vscode.commons.yaml.schema.YValueHint in project sts4 by spring-projects.
the class ConcourseModel method getResourceTypeNameHints.
public Collection<YValueHint> getResourceTypeNameHints(DynamicSchemaContext dc) {
IDocument doc = dc.getDocument();
Multiset<String> userDefined = getStringsFromAst(doc, RESOURCE_TYPE_NAMES_PATH);
if (userDefined != null) {
Builder<YValueHint> builder = ImmutableMultiset.builder();
builder.addAll(YTypeFactory.hints(userDefined));
builder.addAll(Arrays.stream(PipelineYmlSchema.BUILT_IN_RESOURCE_TYPES).map(h -> addExtraInsertion(h, dc)).collect(Collectors.toList()));
return builder.build();
}
return null;
}
use of org.springframework.ide.vscode.commons.yaml.schema.YValueHint in project sts4 by spring-projects.
the class AbstractCFHintsProvider method getHints.
/**
* @return non-null list of hints. Return empty if no hints available
*/
protected Collection<YValueHint> getHints(List<CFTarget> targets) throws Exception {
if (targets == null || targets.isEmpty()) {
// this "don't know" value will suppress bogus warnings in the reconciler.
return null;
}
List<YValueHint> hints = new ArrayList<>();
boolean validTargetsPresent = false;
for (CFTarget cfTarget : targets) {
try {
// TODO: check if duplicate proposals can be the list of all hints. Duplicates don't seem to cause duplicate proposals. Verify this!
getHints(cfTarget).stream().filter(hint -> !hints.contains(hint)).forEach(hint -> hints.add(hint));
validTargetsPresent = true;
} catch (Exception e) {
// Drop individual target error
}
}
if (validTargetsPresent) {
return hints;
} else {
throw new ConnectionException(targetCache.getCfClientConfig().getClientParamsProvider().getMessages().noNetworkConnection());
}
}
Aggregations