Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 356185

Summary: No hovers for completion proposals based on IEObjectDescriptions from the index
Product: [Modeling] TMF Reporter: Vladimir Piskarev <vpiskarov>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: christophkulla, dpwegener, Holger.Schill, sebastian.zarnekow
Version: 2.0.1   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
call stack
none
Sample language projects
none
'example' project none

Description Vladimir Piskarev CLA 2011-08-30 08:17:54 EDT
Build Identifier: 

AbstractJavaBasedContentProposalProvider.DefaultProposalCreator creates completion proposals based on corresponding IEObjectDescriptions. In particular, it sets 'additionalProposalInfo' to the IEObjectDescription's 'eObjectOrProxy'. In case where the IEObjectDescription in question comes from the index (i.e. it is an EObjectDescriptionImpl), that 'additionalProposalInfo' will always be a proxy. That proxy will be used when ConfigurableCompletionProposal attempts to obtain hover info (in #getAdditionalProposalInfo(IProgressMonitor) method), delegating some parts of computation to such components as IQualifiedNameProvider and ILabelProvider. 

In most cases, implementations of those components are not prepared to deal with proxies (and more importantly, they fundamentally cannot do well with proxies - usually they have no context against which the proxies could be resolved). For example, DefaultDeclarativeQualifiedNameProvider (if not overriden) just returns 'null' for the proxy, so DefaultEObjectHoverProvider decides there is no hover (in #hasHover(EObject) method). See the call stack attached.

Note that if e.g. a custom implementation of IQualifiedNameProvider is used, it may fail on proxies even less gracefully, leading to runtime exceptions thrown directly on the user.

Reproducible: Always

Steps to Reproduce:
1. Import the attached projects 'org.xtext.example.dmodel' and
'org.xtext.example.dmodel.ui' into the workspace

2. Run the runtime workbench and import the attached project 'example' into the
runtime workspace

3. Open 'Bar.dmodel' and invoke content assist after the 'extends' clause. Note that there is a hover for 'Bar', but no hover for 'Foo'
Comment 1 Vladimir Piskarev CLA 2011-08-30 08:28:36 EDT
Created attachment 202410 [details]
call stack
Comment 2 Vladimir Piskarev CLA 2011-08-30 08:29:57 EDT
Created attachment 202411 [details]
Sample language projects
Comment 3 Vladimir Piskarev CLA 2011-08-30 08:31:24 EDT
Created attachment 202412 [details]
'example' project
Comment 4 Sebastian Zarnekow CLA 2011-10-17 16:41:41 EDT
We'd have to load the resource for the currently selected proposal and extract the documentation on demand.
Comment 5 Holger Schill CLA 2012-03-23 07:38:09 EDT
I am a little bit scared to resolve the currently selected proposal. I would suggest to avoid hovercomputation for proxies with a guard in the DefaultEobjectHoverprovider. If someone would like to have such things a custom hoverprovider is the way to go. For Xbase I already introduced this guard.
Comment 6 Sebastian Zarnekow CLA 2012-03-23 16:07:29 EDT
Well only the documentation of the selected proposal will be displayed and therefore only the proxy has to be resolved. I don't think this imposes a problem. Why did you introduce the guard in Xbase? Did you face any problems with resource loading?
Comment 7 Holger Schill CLA 2012-03-24 15:03:38 EDT
I introduced the guard to avoid Nullpointer because at the moment we do not resolve proxies. 
But when this is the way to go I will remove it and introduce the proxy resolution. Do not see problems with resource loading. Just was a little bit scared to resolve proxies to show hover on proposals. We will see if it is expensive or not.
Comment 8 David Wegener CLA 2012-07-04 12:58:38 EDT
This issue is causing a NullPointer exception in the example arithmetics project provided with Xtext.  If you import a module, all of the definitions in the imported module result in NullPointerExceptions being thrown in the log and no hover window being displayed.

Steps to reproduce:
1. File->New->Xtext->arithmetic example.
2. Launch workspace and create Java Project adding Xtext nature
3. Create lib.calc with the following:
module lib

def abc(a,b): a+b;

4. Create main.calc with the following:
module main
import lib

def xxx(a,b): a-b;

5. Open up main.calc and invoke content assist at the end of the file after the def xxx. Content proposals window is shown including both abc and xxx.  NullPointerException should be immediately throw as abc should be selected in the proposal list.  Each time the proposal list changes to abc, the exception is thrown.

Stack Trace:
!ENTRY org.eclipse.jface.text 2 0 2012-07-04 11:29:35.639
!MESSAGE 
!STACK 0
java.lang.NullPointerException
	at org.eclipse.xtext.example.arithmetics.arithmetics.util.ArithmeticsSwitch.doSwitch(ArithmeticsSwitch.java:58)
	at org.eclipse.xtext.example.arithmetics.scoping.NameProvider$1.caseDefinition(NameProvider.java:43)
	at org.eclipse.xtext.example.arithmetics.scoping.NameProvider$1.caseDefinition(NameProvider.java:1)
	at org.eclipse.xtext.example.arithmetics.arithmetics.util.ArithmeticsSwitch.doSwitch(ArithmeticsSwitch.java:119)
	at org.eclipse.xtext.example.arithmetics.arithmetics.util.ArithmeticsSwitch.doSwitch(ArithmeticsSwitch.java:72)
	at org.eclipse.xtext.example.arithmetics.arithmetics.util.ArithmeticsSwitch.doSwitch(ArithmeticsSwitch.java:58)
	at org.eclipse.xtext.example.arithmetics.scoping.NameProvider.getFullyQualifiedName(NameProvider.java:66)
	at org.eclipse.xtext.ui.editor.hover.html.DefaultEObjectHoverProvider.hasHover(DefaultEObjectHoverProvider.java:103)
	at org.eclipse.xtext.ui.editor.hover.html.DefaultEObjectHoverProvider.getHoverInfoAsHtml(DefaultEObjectHoverProvider.java:76)
	at org.eclipse.xtext.ui.editor.hover.html.DefaultEObjectHoverProvider.getHoverInfo(DefaultEObjectHoverProvider.java:91)
	at org.eclipse.xtext.ui.editor.hover.html.DefaultEObjectHoverProvider$2.getInfo(DefaultEObjectHoverProvider.java:519)
	at org.eclipse.xtext.ui.editor.hover.DispatchingEObjectTextHover.getHoverInfo(DispatchingEObjectTextHover.java:38)
	at org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal.getAdditionalProposalInfo(ConfigurableCompletionProposal.java:540)
	at org.eclipse.jface.text.contentassist.AdditionalInfoController$3.run(AdditionalInfoController.java:106)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Comment 9 Sebastian Zarnekow CLA 2012-07-05 05:06:21 EDT
Moved issue from comment #8 to bug 384334
Comment 10 Holger Schill CLA 2012-11-29 08:44:24 EST
pushed fix and test to master
Comment 11 Eclipse Webmaster CLA 2017-10-31 11:05:32 EDT
Requested via bug 522520.

-M.
Comment 12 Eclipse Webmaster CLA 2017-10-31 11:16:49 EDT
Requested via bug 522520.

-M.