use of org.springframework.ide.vscode.commons.util.text.DocumentRegion in project sts4 by spring-projects.
the class AbstractYamlAssistContext method getCustomAssistRegion.
protected DocumentRegion getCustomAssistRegion(YamlDocument doc, SNode node, int offset) {
if (node.getNodeType() == SNodeType.KEY) {
SKeyNode keyNode = (SKeyNode) node;
if (keyNode.isInValue(offset)) {
int valueStart = keyNode.getColonOffset() + 1;
// assumes we only look at the current line, good enough for now
int valueEnd = keyNode.getNodeEnd();
DocumentRegion region = new DocumentRegion(doc.getDocument(), valueStart, valueEnd);
if (region.startsWith(" ")) {
region = region.subSequence(1);
}
return region;
}
}
// TODO Reaching here might mean support for calling the custom assistant isn't
return null;
// implemented for this kind of context yet. It will have to be expanded upon
// as the need for it arises in real use-cases.
}
use of org.springframework.ide.vscode.commons.util.text.DocumentRegion in project sts4 by spring-projects.
the class YTypeAssistContext method getCompletions.
@Override
public Collection<ICompletionProposal> getCompletions(YamlDocument doc, SNode node, int offset) throws Exception {
ISubCompletionEngine customContentAssistant = typeUtil.getCustomContentAssistant(type);
if (customContentAssistant != null) {
DocumentRegion region = getCustomAssistRegion(doc, node, offset);
if (region != null) {
return customContentAssistant.getCompletions(completionFactory(), region, region.toRelative(offset));
}
}
String query = getPrefix(doc, node, offset);
List<ICompletionProposal> completions = getValueCompletions(doc, node, offset, query);
if (completions.isEmpty()) {
TypeBasedSnippetProvider snippetProvider = typeUtil.getSnippetProvider();
if (snippetProvider != null) {
Collection<Snippet> snippets = snippetProvider.getSnippets(type);
YamlIndentUtil indenter = new YamlIndentUtil(doc);
for (Snippet snippet : snippets) {
String snippetName = snippet.getName();
double score = FuzzyMatcher.matchScore(query, snippetName);
if (score != 0.0 && snippet.isApplicable(getSchemaContext())) {
DocumentEdits edits = createEditFromSnippet(doc, node, offset, query, indenter, snippet);
completions.add(completionFactory().valueProposal(snippetName, query, snippetName, type, null, score, edits, typeUtil));
}
}
}
completions.addAll(getKeyCompletions(doc, node, offset, query));
}
if (typeUtil.isSequencable(type)) {
completions = new ArrayList<>(completions);
completions.addAll(getDashedCompletions(doc, node, offset));
}
return completions;
}
use of org.springframework.ide.vscode.commons.util.text.DocumentRegion in project sts4 by spring-projects.
the class SchemaBasedYamlASTReconciler method dashesAtStartOf.
private DocumentRegion dashesAtStartOf(YamlFileAST ast, Node node) {
try {
int start = node.getStartMark().getIndex();
DocumentRegion textBefore = new DocumentRegion(ast.getDocument(), 0, start).trimEnd(Pattern.compile("\\s*"));
DocumentRegion dashes = textBefore.subSequence(textBefore.getLength() - 3);
if (dashes.toString().equals("---")) {
return dashes;
}
} catch (Exception e) {
Log.log(e);
}
// something unexpected... we couldn't find the '---'. So just mark the entire node.
return allOf(ast, node);
}
use of org.springframework.ide.vscode.commons.util.text.DocumentRegion in project sts4 by spring-projects.
the class SchemaBasedYamlASTReconciler method getRegion.
protected DocumentRegion getRegion(Exception e, IDocument doc, Node node) {
DocumentRegion region = new DocumentRegion(doc, node.getStartMark().getIndex(), node.getEndMark().getIndex());
if (e instanceof ValueParseException) {
ValueParseException parseException = (ValueParseException) e;
int start = parseException.getStartIndex() >= 0 ? Math.min(node.getStartMark().getIndex() + parseException.getStartIndex(), node.getEndMark().getIndex()) : node.getStartMark().getIndex();
int end = parseException.getEndIndex() >= 0 ? Math.min(node.getStartMark().getIndex() + parseException.getEndIndex(), node.getEndMark().getIndex()) : node.getEndMark().getIndex();
region = new DocumentRegion(doc, start, end);
}
return region;
}
use of org.springframework.ide.vscode.commons.util.text.DocumentRegion in project sts4 by spring-projects.
the class PropertiesCompletionProposalsCalculator method getNavigationProposals.
private Collection<ICompletionProposal> getNavigationProposals() {
String navPrefix = navigationPrefixFinder.getPrefix(doc, offset);
try {
if (navPrefix != null) {
// offset of 'nav' operator char (i.e. '.' or ']').
int navOffset = offset - navPrefix.length() - 1;
navPrefix = fuzzySearchPrefix.getPrefix(doc, navOffset);
if (navPrefix != null && !navPrefix.isEmpty()) {
PropertyInfo prop = findLongestValidProperty(index, navPrefix);
if (prop != null) {
int regionStart = navOffset - navPrefix.length();
Collection<ICompletionProposal> hintProposals = getKeyHintProposals(prop, navOffset);
if (CollectionUtil.hasElements(hintProposals)) {
return hintProposals;
}
PropertyNavigator navigator = new PropertyNavigator(doc, null, typeUtil, new DocumentRegion(doc, regionStart, navOffset));
Type type = navigator.navigate(regionStart + prop.getId().length(), TypeParser.parse(prop.getType()));
if (type != null) {
return getNavigationProposals(type, navOffset);
}
}
}
}
} catch (Exception e) {
Log.log(e);
}
return Collections.emptyList();
}
Aggregations