Search in sources :

Example 1 with HoverContext

use of org.eclipse.xtext.ide.server.hover.HoverContext in project xtext-core by eclipse.

the class HoverService method hover.

@Override
public Hover hover(final Document document, final XtextResource resource, final TextDocumentPositionParams params, final CancelIndicator cancelIndicator) {
    final int offset = document.getOffSet(params.getPosition());
    final HoverContext context = this.createContext(document, resource, offset);
    return this.hover(context);
}
Also used : HoverContext(org.eclipse.xtext.ide.server.hover.HoverContext)

Example 2 with HoverContext

use of org.eclipse.xtext.ide.server.hover.HoverContext in project xtext-core by eclipse.

the class HoverService method createContext.

protected HoverContext createContext(final Document document, final XtextResource resource, final int offset) {
    final EObject crossLinkedEObject = this._eObjectAtOffsetHelper.resolveCrossReferencedElementAt(resource, offset);
    if ((crossLinkedEObject != null)) {
        boolean _eIsProxy = crossLinkedEObject.eIsProxy();
        if (_eIsProxy) {
            return null;
        }
        final IParseResult parseResult = resource.getParseResult();
        if ((parseResult == null)) {
            return null;
        }
        ILeafNode leafNode = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), offset);
        if ((((leafNode != null) && leafNode.isHidden()) && (leafNode.getOffset() == offset))) {
            leafNode = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), (offset - 1));
        }
        if ((leafNode == null)) {
            return null;
        }
        final ITextRegion leafRegion = leafNode.getTextRegion();
        return new HoverContext(document, resource, offset, leafRegion, crossLinkedEObject);
    }
    final EObject element = this._eObjectAtOffsetHelper.resolveElementAt(resource, offset);
    if ((element == null)) {
        return null;
    }
    final ITextRegion region = this._iLocationInFileProvider.getSignificantTextRegion(element);
    return new HoverContext(document, resource, offset, region, element);
}
Also used : ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) ITextRegion(org.eclipse.xtext.util.ITextRegion) EObject(org.eclipse.emf.ecore.EObject) IParseResult(org.eclipse.xtext.parser.IParseResult) HoverContext(org.eclipse.xtext.ide.server.hover.HoverContext)

Aggregations

HoverContext (org.eclipse.xtext.ide.server.hover.HoverContext)2 EObject (org.eclipse.emf.ecore.EObject)1 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)1 IParseResult (org.eclipse.xtext.parser.IParseResult)1 ITextRegion (org.eclipse.xtext.util.ITextRegion)1