Search in sources :

Example 1 with QuickAssistInvocationContext

use of org.eclipse.xtext.ui.editor.quickfix.QuickAssistInvocationContext in project xtext-eclipse by eclipse.

the class AnnotationWithQuickFixesHover method getHoverInfoInternal.

// DIFF: this code is entirely different, as the hover subclasses from AbstractProblemHover and
// hooks different methods
@Override
protected Object getHoverInfoInternal(ITextViewer textViewer, final int lineNumber, final int offset) {
    AnnotationInfo result = recentAnnotationInfo;
    if (result != null)
        return result;
    List<Annotation> annotations = getAnnotations(lineNumber, offset);
    if (annotations != null) {
        for (Annotation annotation : annotations) {
            Position position = getAnnotationModel().getPosition(annotation);
            if (annotation.getText() != null && position != null) {
                final QuickAssistInvocationContext invocationContext = new QuickAssistInvocationContext(sourceViewer, position.getOffset(), position.getLength(), true);
                CompletionProposalRunnable runnable = new CompletionProposalRunnable(invocationContext);
                // Note: the resolutions have to be retrieved from the UI thread, otherwise
                // workbench.getActiveWorkbenchWindow() will return null in LanguageSpecificURIEditorOpener and
                // cause an exception
                Display.getDefault().syncExec(runnable);
                if (invocationContext.isMarkedCancelled()) {
                    return null;
                }
                result = new AnnotationInfo(annotation, position, sourceViewer, runnable.proposals);
                recentAnnotationInfo = result;
                return result;
            }
        }
    }
    return null;
}
Also used : Position(org.eclipse.jface.text.Position) IQuickAssistInvocationContext(org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext) QuickAssistInvocationContext(org.eclipse.xtext.ui.editor.quickfix.QuickAssistInvocationContext) Annotation(org.eclipse.jface.text.source.Annotation)

Aggregations

Position (org.eclipse.jface.text.Position)1 IQuickAssistInvocationContext (org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext)1 Annotation (org.eclipse.jface.text.source.Annotation)1 QuickAssistInvocationContext (org.eclipse.xtext.ui.editor.quickfix.QuickAssistInvocationContext)1