use of org.eclipse.xtext.util.ITextRegion in project xtext-core by eclipse.
the class ContentAssistContextFactory method doCreateContext.
public ContentAssistContext.Builder doCreateContext(INode lastCompleteNode, EObject currentModel, EObject previousModel, INode currentNode, String prefix) {
ContentAssistContext.Builder context = contentAssistContextProvider.get();
context.setRootNode(rootNode);
context.setLastCompleteNode(lastCompleteNode);
context.setCurrentNode(currentNode);
context.setRootModel(parseResult.getRootASTElement());
context.setCurrentModel(currentModel);
context.setPreviousModel(previousModel);
context.setOffset(completionOffset);
context.setPrefix(prefix);
int regionLength = prefix.length();
if (selection.getLength() > 0) {
regionLength = regionLength + selection.getLength();
}
ITextRegion region = new TextRegion(completionOffset - prefix.length(), regionLength);
if (selection.getOffset() >= 0 && selection.getLength() >= 0) {
context.setSelectedText(document.substring(selection.getOffset(), selection.getOffset() + selection.getLength()));
}
context.setReplaceRegion(region);
context.setResource(resource);
return context;
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-core by eclipse.
the class DefaultFoldingRangeProvider method acceptObjectFolding.
protected void acceptObjectFolding(EObject eObject, IFoldingRangeAcceptor foldingRangeAcceptor) {
ITextRegion region = locationInFileProvider.getFullTextRegion(eObject);
if (region != null) {
INode eObjectNode = NodeModelUtils.getNode(eObject);
ITextRegion significant = buildSignificantRegion(locationInFileProvider.getSignificantTextRegion(eObject), eObjectNode);
foldingRangeAcceptor.accept(region.getOffset(), region.getLength(), null, false, significant);
}
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-core by eclipse.
the class DocumentExtensions method newLocation.
public Location newLocation(EObject owner, EStructuralFeature feature, int indexInList) {
Resource resource = owner.eResource();
ITextRegion textRegion = locationInFileProvider.getSignificantTextRegion(owner, feature, indexInList);
return newLocation(resource, textRegion);
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-core by eclipse.
the class IndentationAwareCompletionPrefixProvider method getLastCompleteNodeByOffset.
protected INode getLastCompleteNodeByOffset(INode node, int offset) {
BidiTreeIterator<INode> iterator = node.getRootNode().getAsTreeIterable().iterator();
INode result = node;
ITextRegion candidateTextRegion = node.getTextRegion();
while (iterator.hasNext()) {
INode candidate = iterator.next();
ITextRegion textRegion = candidate.getTextRegion();
if (textRegion.getOffset() >= offset && !(textRegion.getOffset() == offset && textRegion.getLength() == 0)) {
if (!candidateTextRegion.equals(textRegion) && candidate instanceof ILeafNode && textRegion.getLength() + textRegion.getOffset() >= offset) {
break;
}
}
if ((candidate instanceof ILeafNode) && (candidate.getGrammarElement() == null || candidate.getGrammarElement() instanceof AbstractElement || candidate.getGrammarElement() instanceof ParserRule)) {
if (textRegion.getLength() == 0) {
if (candidateTextRegion.getOffset() + candidateTextRegion.getLength() < offset || candidateTextRegion.getLength() == 0 && candidateTextRegion.getOffset() <= offset) {
result = candidate;
candidateTextRegion = candidate.getTextRegion();
}
} else {
result = candidate;
candidateTextRegion = candidate.getTextRegion();
}
}
}
return result;
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-core by eclipse.
the class DefaultSemanticHighlightingCalculator method highlightNode.
/**
* Highlights the non-hidden parts of {@code node} with the styles given by the {@code styleIds}
*/
protected void highlightNode(IHighlightedPositionAcceptor acceptor, INode node, String... styleIds) {
if (node == null)
return;
if (node instanceof ILeafNode) {
ITextRegion textRegion = node.getTextRegion();
acceptor.addPosition(textRegion.getOffset(), textRegion.getLength(), styleIds);
} else {
for (ILeafNode leaf : node.getLeafNodes()) {
if (!leaf.isHidden()) {
ITextRegion leafRegion = leaf.getTextRegion();
acceptor.addPosition(leafRegion.getOffset(), leafRegion.getLength(), styleIds);
}
}
}
}
Aggregations