Bug 157254 - Code hinting does not display correct <xsd:documentation /> value with <xsd:attribute /> that uses 'ref' attribute.
Summary: Code hinting does not display correct <xsd:documentation /> value with <xsd:a...
Status: CLOSED FIXED
Alias: None
Product: WTP Source Editing
Classification: WebTools
Component: wst.xsd (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows XP
: P2 normal with 2 votes (vote)
Target Milestone: 3.0 RC3   Edit
Assignee: Keith Chong CLA
QA Contact: Nitin Dahyabhai CLA
URL:
Whiteboard: PMC_approved
Keywords: contributed
Depends on:
Blocks: 195028
  Show dependency tree
 
Reported: 2006-09-13 21:44 EDT by Mark Mandel CLA
Modified: 2008-06-09 18:40 EDT (History)
7 users (show)

See Also:
david_williams: pmc_approved+
valentinbaciu: pmc_approved? (raghunathan.srinivasan)
valentinbaciu: pmc_approved? (naci.dai)
deboer: pmc_approved+
valentinbaciu: pmc_approved? (neil.hauge)
valentinbaciu: pmc_approved? (kaloyan)
valentinbaciu: review+


Attachments
instance document of 'tweaked' schema (166 bytes, text/plain)
2006-09-23 00:48 EDT, Craig Salter CLA
no flags Details
'tweaked' schema to demo a case where things work (750 bytes, text/plain)
2006-09-23 00:54 EDT, Craig Salter CLA
no flags Details
Patch to correctly get documentation from referrenced attributes and elements (2.39 KB, patch)
2007-12-28 18:03 EST, David Carver CLA
no flags Details | Diff
Tweaked Patch to handle situations were annotation has appinfo but no documentation elements (3.35 KB, patch)
2007-12-28 19:53 EST, David Carver CLA
no flags Details | Diff
Unit Test for supplied patch (3.35 KB, patch)
2008-03-24 11:43 EDT, David Carver CLA
no flags Details | Diff
Corrected Unit Test Patch (6.56 KB, patch)
2008-03-25 11:38 EDT, David Carver CLA
no flags Details | Diff
Updated patch (3.51 KB, patch)
2008-05-22 13:25 EDT, Keith Chong CLA
bjorn.freeman-benson: iplog+
Details | Diff
Test for attribute refs (169 bytes, text/plain)
2008-05-22 13:27 EDT, Keith Chong CLA
no flags Details
Test attribute refs XSD file (2.38 KB, text/plain)
2008-05-22 13:28 EDT, Keith Chong CLA
no flags Details
Global Element and Global Attribute documentation unit tests (13.82 KB, text/plain)
2008-05-22 21:03 EDT, David Carver CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Mandel CLA 2006-09-13 21:44:10 EDT
On code hinting from an XSD stylesheet - 

If the XSD stylesheet looks like this :

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!-- some stuff here -->
<xsd:complexType name="object">
<xsd:attribute ref="name" use="required">
	<xsd:annotation><xsd:documentation>
	The name of this object, e.g. 'User'
	</xsd:documentation></xsd:annotation>
</xsd:attribute>
</xsd:complexType>

<xsd:attribute name="name">
	<xsd:simpleType>
		<xsd:restriction base="xsd:string">
		<xsd:pattern value="[a-zA-Z0-9_]+"></xsd:pattern>
		</xsd:restriction>
	</xsd:simpleType>
</xsd:attribute>
</xsd:schema>

When I display code hinting for the 'name' attribute when displaying an in an <object> element, the <xsd:documentation> block does not display, as the code hint looks to the <xsd:attribute name="name"> declaration.

This should not be the case, as the attribute 'name' could have different meanings depending on what element it is applied to, and therefore the code hint should look to the documentation that is applied to the attribute as it is done above.

(I hope that made sense)
Comment 1 David Williams CLA 2006-09-23 00:10:59 EDT
Craig, is this an error in our namespace algorithms, or, 

Amy, do our "hint lookups" need a little more sophistication? 

Comment 2 Craig Salter CLA 2006-09-23 00:41:03 EDT
Let me clarify the bug report with some steps to reproduce (correct me if i'm wrong here)...

- create an XML document that is an instance of XML Schema pasted above (you'll need to tweak this schema to add an element declaration in order to create a valid document)
- position the cursor inside like this... <object |> ...and invoke content assist
- the 'name' attribute is suggested which is good
- the information in the description window for the 'name' suggestion is not what is expected (the content of the documentation element is not shown)
Comment 3 Craig Salter CLA 2006-09-23 00:46:00 EDT
I'm guessing the issue here is that the XSD content model skips over the attribute reference to the actual attribute to get the documentation.  We need to fix the XSD content model implementation to ensure it checks for documentation in the attribute ref first, before walking over the the attribute.

Notice that if I put the documentation on the attribute declaration that the information window displays the expected content (see test.xml and test.xsd attached above).
Comment 4 Craig Salter CLA 2006-09-23 00:48:45 EDT
Created attachment 50751 [details]
instance document of 'tweaked' schema
Comment 5 Craig Salter CLA 2006-09-23 00:54:04 EDT
Created attachment 50752 [details]
'tweaked' schema to demo a case where things work

I've added attachment to demo the case where things work as expected.  In this case the user will see "Here's some documentation!" but really what they want to see is "The name of this object, e.g. 'User'".  So our fix for this bug should be to check the reference first and use it's doc if present... otherwise walk over to the definition and use it's doc.  The same goes the various ref constructs in XML Schema though elements and attributes are the important ones that are likely to be exposed in content assist.
Comment 6 Craig Salter CLA 2007-01-12 03:03:06 EST
Valentin, can you review and commit this?
Comment 7 Valentin Baciu CLA 2007-01-12 14:30:52 EST
Hi Craig, I assume you meant I should fix this bug. I don't see any patch attached. Did you maybe forgot to attach it if you have one?
Comment 8 David Carver CLA 2007-12-28 17:05:27 EST
Version: 3.3.1.1
Build id: M20071023-1652

Web Tools 2.0.1.

I'm experiencing this issue or a very similar one with xsd:elements that have a ref attribute.

XSD snippet that exhibits the problem:

<xs:element name="call-template" substitutionGroup="xsl:instruction">
  <xs:annotation>
     <xs:documentation source="http://www.w3.org/TR/xslt">
        Specifies the name of a template to be called. A called template
        is only executed when it is called.  It is not executed directly by
        an apply-templates command.
     </xs:documentation>
  </xs:annotation>

  <xs:complexType>
    <xs:complexContent>
      <xs:extension base="xsl:element-only-versioned-element-type">
        <xs:sequence>
          <xs:element ref="xsl:with-param" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="name" type="xsl:QName" use="required">
           <xs:annotation>
              <xs:documentation source="http://www.w3.org/TR/xslt">
                 Required.  The name of the template to be called.
              </xs:documentation>
           </xs:annotation>
        </xs:attribute>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
</xs:element>

<xs:element name="with-param">
  <xs:annotation>
     <xs:documentation source="http://www.w3.org/TR/xslt">
        Defines the value of a parameter to be passed to a called template.
     </xs:documentation>
  </xs:annotation>
  <xs:complexType>
    <xs:complexContent mixed="true">
      <xs:extension base="xsl:sequence-constructor">
        <xs:attribute name="name" type="xsl:QName" use="required">
           <xs:annotation>
              <xs:documentation source="http://www.w3.org/TR/xslt">
                  Required.  The name of the parameter to be set.  This
                  must exist in the template that is being called.
              </xs:documentation>
           </xs:annotation>
        </xs:attribute>
        <xs:attribute name="select" type="xsl:expression">
           <xs:annotation>
              <xs:documentation source="http://www.w3.org/TR/xslt">
                  Optional.  An XPath expression that is used to set
                  the value for the parameter being passed to a template.
              </xs:documentation>
           </xs:annotation>
        </xs:attribute>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
</xs:element>


The issue here is this...the element "with-param" doesn't display any annotation information when you hover over it.   The global element with-param has annotation information attached to it.   It appears that when the ContentModel is grabbing the annotation information, it is not going back to the referrenced element to get that information if none is attached directly to it.

Regardless of whether an element or attribute is a referrence, the following order should be checked to see if there is annotation/documentation for the particular item:

1.  Check the local definition of the element.  If their is locally defined annotation/documentation then use that for that particular point.

2.  Otherwise, go to the refferenced item and grab the annotation/documentation information and get it from there.

This is important because there are many industry standard schemas out that make use of global elements to document a particular element, and the current implementation only looks for annotation information if it is locally defined.  Now where it does work for globals, is when an item is being used as part of a substitution group.  This issue only seems to appear when the element is refferenced from within a ComplexType, and not being used by a substitution group.

This bug will affect the proposed use of the WTP Incubator xslt project's use of xsd schemas for XSLT 1.0 content assist.

Comment 9 David Carver CLA 2007-12-28 18:00:13 EST
changed to wst.xsd for component as that is where the bug resides.  Attaching patch to fix the issue.
Comment 10 David Carver CLA 2007-12-28 18:03:09 EST
Created attachment 85917 [details]
Patch to correctly get documentation from referrenced attributes and elements

This patch will correctly get the documentation when an attribute or element is referrenced, and the local declaration does not contain any annotations.   What it does first is check to see if there are no annotations for the local element.  If there are none, then it gets the documentation from the global declaration of the element or attribute.
Comment 11 David Carver CLA 2007-12-28 19:53:40 EST
Created attachment 85919 [details]
Tweaked Patch to handle situations were annotation has appinfo but no documentation elements

This tweaks the patch to handle those situations where an attribute or element may have an xsd:annotation/xsd:appinfo combination but doesn't necessarily have an xsd:annotation/xsd:documentation combination.   If this was not checked, it would not check to see if the referenced item contained the documentation.

This should now handle all situations correctly for elements and attribute documentation.
Comment 12 David Carver CLA 2008-03-23 12:31:22 EDT
Valentin, any update on this bug?
Comment 13 Valentin Baciu CLA 2008-03-23 12:41:40 EDT
Hi David, it's on my todo list for M6. Any chance you have time to create a JUnit for the fix as part of org.eclipse.wst.xsd.core.tests?
Comment 14 David Carver CLA 2008-03-23 13:10:29 EDT
(In reply to comment #13)
> Hi David, it's on my todo list for M6. Any chance you have time to create a
> JUnit for the fix as part of org.eclipse.wst.xsd.core.tests?
> 

Sure. let me look into it today...should have something no later than Wednesday.
Comment 15 David Carver CLA 2008-03-24 11:43:24 EDT
Created attachment 93281 [details]
Unit Test for supplied patch

This provides a unit test for the patch provided.  It loads the provided schema in this patch file, and makes appropriate checks against the content model, to make sure that information that is expected to be returned is returned.  If not it fails the test.   The schema attached in this unit test patch is original, and available under the EPL.  Appropriate header information included.  I created this schema myself.
Comment 16 Valentin Baciu CLA 2008-03-25 10:56:21 EDT
Dave, the unit test patch seems to be identical to the code patch. Perhaps you've attached the wrong file?
Comment 17 David Carver CLA 2008-03-25 11:34:02 EDT
Yeah, it looks like I exported the wrong patch.  I'll correct this in a few.
Comment 18 David Carver CLA 2008-03-25 11:38:05 EDT
Created attachment 93405 [details]
Corrected Unit Test Patch

Attached the corrected patch.
Comment 19 Valentin Baciu CLA 2008-03-25 17:52:11 EDT
Hi Dave, thanks for the patch and the test. I've given them a try and I think they are good but need a little bit more work. 

The issue is with the support for attribute refs documentation. The way the patch is written now, the code will always check the actual referenced attribute declaration and not the attribute ref. This is because XSDAttributUse#getAttributeDeclaration() will return the actual global attribute. If you want to get the attribute declaration representing the ref you could use something like this 

XSDAttributeDeclaration xsdAttributeDeclaration = xsdAttributeUse.getContent();      	

Your unit test could also be enhanced to test documentation for attribute declaration, which is the original intent of this bug.

I hope this helps. Thank you again for your contribution.
Comment 20 Valentin Baciu CLA 2008-03-26 23:30:00 EDT
Sorry, we're out of time for M6, moving to M7.
Comment 21 Valentin Baciu CLA 2008-04-23 13:55:09 EDT
Keith, perhaps we can try this fix for RC1.
Comment 22 Keith Chong CLA 2008-05-22 13:25:31 EDT
Created attachment 101564 [details]
Updated patch
Comment 23 Keith Chong CLA 2008-05-22 13:27:29 EDT
Created attachment 101565 [details]
Test for attribute refs
Comment 24 Keith Chong CLA 2008-05-22 13:28:19 EDT
Created attachment 101566 [details]
Test attribute refs XSD file
Comment 25 Keith Chong CLA 2008-05-22 13:34:59 EDT
I've attached an updated patch to fix the documentation for attribute refs.

Dave, please retry.  Also, if you agree with the fix, can you please update your unit test?  Thanks.
Comment 26 David Carver CLA 2008-05-22 13:51:44 EDT
(In reply to comment #25)
> I've attached an updated patch to fix the documentation for attribute refs.
> 
> Dave, please retry.  Also, if you agree with the fix, can you please update
> your unit test?  Thanks.
> 

Sure.  I'll try and verify this, this evening, and provide an updated unit test.
Comment 27 Valentin Baciu CLA 2008-05-22 14:18:41 EDT
Doesn't look like we'll be able to get this into RC2. 

Dave, do you think this fix can wait for 3.0.1? Or is it a must for 3.0? In that case, please make the argument accordingly to support the PMC approval.
Comment 28 David Carver CLA 2008-05-22 14:27:14 EDT
(In reply to comment #27)
> Doesn't look like we'll be able to get this into RC2. 
> 
> Dave, do you think this fix can wait for 3.0.1? Or is it a must for 3.0? In
> that case, please make the argument accordingly to support the PMC approval.
> 

I would prefer if we can get this in for 3.0.  The reason being is that as it currently stands, none of the documentation appears for the elements that use a ref attribute and don't have local documentation.  This makes it appears as there is no documentation at all.   When would 3.0.1 be done, if it is going to be September, as I'm not releasing my latest version built on 3.0 until late October.

But the sooner the better.
Comment 29 David Carver CLA 2008-05-22 21:03:59 EDT
Created attachment 101669 [details]
Global Element and Global Attribute documentation unit tests

I've added the unit tests for the global attributes as well as testing the local elements.  Keith, the XML file isn't needed for the unit tests, just your XSD file is needed to test the files.  This patch contains the unit test and the source xsd files.
Comment 30 David Carver CLA 2008-05-22 21:05:26 EDT
added contributed keyword.
Comment 31 Keith Chong CLA 2008-05-26 16:08:38 EDT
Thanks Dave, I ran your junits with the patch and it works fine.   Yes, agreed the XML file is not needed.  I attached it so that you can readily test out content assist manually.
Comment 32 Keith Chong CLA 2008-05-26 16:32:17 EDT
PMC Approval Info:

* Explain why you believe this is a stop-ship defect. Or, if it is a "hotbug"
(requested by an adopter) please document it as such. 

Adopter wants this fix for the incubating XSLT project.

* Is there a work-around? If so, why do you believe the work-around is
insufficient?

No workaround.

* How has the fix been tested? Is there a test case attached to the bugzilla
record? Has a JUnit Test been added? 

Dave Carver added a junit test.  It works correctly with the patch applied...(and fails if the patch is not applied).   I also tested the patch manually.

* Give a brief technical overview. Who has reviewed this fix?

The content model currently gets the documentation elements from the resolved attribute/element declaration when determining the text to display for content assist.  However, this assumption does not work when dealing with references.  The documentation element can be attached to the reference, which can lead to no content assist documention showing when there really should be.   The fix is to 'enhance' the getDocumentation method for elements and attributes to check if the references have documentation.  If so, present that to the user.  If not, then use the resolved reference declaration's documentation.

See patch.  I've documented the changes for attributes.  Dave Carver documented the changes for elements.

* What is the risk associated with this fix? 
This is a safe fix.  The change is isolated to getting the documentation for elements and attributes and their references.
Comment 33 Valentin Baciu CLA 2008-05-26 17:24:06 EDT
Dave, Keith, the fix looks good and works fine. Thank you for the unit tests! 

One small suggestions would be to move the new test resources in the samples folder and double check to make sure the case of the file name is right to avoid any issues when running the tests under Linux.
Comment 34 Valentin Baciu CLA 2008-05-26 17:28:20 EDT
PMC, please review and consider approving this fix for RC3. See comment #32 for details.
Comment 35 David Carver CLA 2008-05-26 19:51:30 EDT
(In reply to comment #33)
> Dave, Keith, the fix looks good and works fine. Thank you for the unit tests! 
> 
> One small suggestions would be to move the new test resources in the samples
> folder and double check to make sure the case of the file name is right to
> avoid any issues when running the tests under Linux.
> 

My development environment is is Ubunutu Linux so I know the test cases work there as well.  So there is no case sensitivity issue.

Comment 36 David Williams CLA 2008-05-27 02:43:53 EDT
I'm fine with this. Seems important, since it's such an old bug. 
Comment 37 Keith Chong CLA 2008-05-28 16:15:26 EDT
Fix released for WTP 3.0 RC3.

Map entry tag for xsd.core and xsd.core.tests should be >= v200805282012
Comment 38 Keith Chong CLA 2008-05-29 09:56:33 EDT
The junits are successfully running in the S-3.0RC3-20080528220621 build
Comment 39 David Carver CLA 2008-05-29 10:05:14 EDT
Thanks for getting this in.
Comment 40 Amy Wu CLA 2008-06-09 18:40:45 EDT
verified in wtp3.0RC4 20080609110539 sdk that the original use case submitted by Mark works now. and based on comment #38, other use cases work too, so I'm closing this bug.

Mark & Dave, please reopen asap if this is still an issue.