Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 194935 - [EditorMgmt] External files opened with the wrong editor when using File->Open file...
Summary: [EditorMgmt] External files opened with the wrong editor when using File->Ope...
Status: RESOLVED DUPLICATE of bug 230865
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Resources (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Szymon Brandys CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 107951
  Show dependency tree
 
Reported: 2007-06-29 12:07 EDT by Valentin Baciu CLA
Modified: 2008-05-13 12:07 EDT (History)
7 users (show)

See Also:


Attachments
Sample test plug-in (13.25 KB, application/x-zip-compressed)
2007-06-29 12:08 EDT, Valentin Baciu CLA
no flags Details
3.2.2 stack trace (1.68 KB, text/plain)
2007-06-29 12:09 EDT, Valentin Baciu CLA
no flags Details
3.3 stack trace (1.93 KB, text/plain)
2007-06-29 12:09 EDT, Valentin Baciu CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Valentin Baciu CLA 2007-06-29 12:07:04 EDT
I thought about logging this against runtime since it's content type related but I figured I'd start up here in UI since it's a visible behaviour.

I was trying to verify whether an old WTP bug 107951 is still alive and kicking or not, and decided to try the scenario with WTP 2.0 (based on Eclipse 3.3).

What I noticed is that xsd and wsdl files from outside the workspace are not opened with the proper editor anymore, based on their content type. This used to work with WTP 1.5.4 (Eclipse 3.2.2). Instead of the WSDL and XSD editor the wsdl and xsd files are always opened with the XML editor.

I started to debug a bit thinking I may have run into another incarnation of our old friend bug 146951 -  wrong icons in the navigator. To avoid any WTP interference, I created a sample plug-in that tries to mimic the content type hierarchy declared by WTP. The WTP hierarchy looks like this:

org.eclipse.core.runtime.text
    org.eclipse.wst.xml.core.xmlsource - xml, xsd, wsdl extensions - XML source editor
    org.eclipse.core.runtime.xml - xml extension - XML source editor
        org.eclipse.wst.wsd.wsdlsource - wsdl extension	- WSDL editor
        org.eclipse.wst.xsd.core.xsdsource - xsd extension - XSD editor
			
So I created my test content type hierarchy to look like this:

org.eclipse.core.runtime.text
    maskingContentType - base,derived,third extensions - base editor
    baseContentType - base extension - base editor
        derivedContentType - derived extension - derived editor
        thirdContentType - third extension - third editor

I've been able to reproduce the WTP behaviour with my little example and through some debugging and experimentation I realized that the issue seems to be the fact that the wsdl and xsd extensions declared by the xmlsource content type are masking the ones declared lower in the hierarchy. Similarly the extensions declared in the maskingContentType are masking the derived and third extensions. Everything starts working by removing the extensions declared in xmlsource respectively in the maskingContentType. 

As a bonus, I also noticed that as soon as I removed the wsdl and xsd extensions from the xmlsource content type, the proper icons also showed up in the navigator - yay! Same with my little test.

I've also managed to find out why the two versions (3.2 and 3.3) are behaving differently. Here are two stack traces showing that opening an editor on an external file takes two different paths:
- the 3.2.2 code path uses this type of call to get the content type: Platform.getContentTypeManager().findContentTypeFor(stream, fileStore.getName()) 
- the 3.3 code path uses this type of call to get the content type: Platform.getContentTypeManager().findContentTypeFor(name) 

Further, the two code paths appear to use different content type matching policies: 
- the 3.2.2 code path uses a lexicographical policy org.eclipse.core.internal.content.ContentTypeCatalog.policyLexicographical 
- the 3.3 code path uses a "general is better" policy org.eclipse.core.internal.content.ContentTypeCatalog.policyGeneralIsBetter.

If I take the 3.2.2 case, I would venture to speculate that it worked by pure luck because somehow the more specific content type won in the lexicographic comparison.

In 3.3 the code seems to assume that the content types to be sorted are part of the same inheritance hierarchy. So the masking content type is found to be more generic than the derived content type by comparing their depths in the hierarchy.  In fact, they are in two different inheritance hierarchies. So even though they define the same extension and get lumped  together by the extension they define, they are not really parent/child.

$1000 question: What's wrong: the sorting code or the way WTP defines the hierarchy? 

Possible answers:
1) This works as designed and WTP is going outside the beaten path with using the same extension in two branches at different levels
2) The "general is better" sort policy is not accommodating this scenario

I'm opening the bug against the platform initially but based on the answer to the above question the bug may be reassigned to WTP, the wst.xml component. This information is also relevant to bug 146951 so I'll cross reference there.
Comment 1 Valentin Baciu CLA 2007-06-29 12:08:13 EDT
Created attachment 72783 [details]
Sample test plug-in

Demonstrates the issue in a WTP-free way.
Comment 2 Valentin Baciu CLA 2007-06-29 12:09:07 EDT
Created attachment 72785 [details]
3.2.2 stack trace

Shows the code path for opening external editors in 3.2.2
Comment 3 Valentin Baciu CLA 2007-06-29 12:09:48 EDT
Created attachment 72786 [details]
3.3 stack trace

Shows the code path for opening editors on external files in 3.3
Comment 4 Valentin Baciu CLA 2007-09-12 11:31:30 EDT
The content type bug 198544 seems related, if not the same.
Comment 5 Boris Bokowski CLA 2007-09-14 10:51:19 EDT
Moving to Resources.
Comment 6 Szymon Brandys CLA 2008-05-09 04:23:57 EDT
Mass update - removing 3.4 target. This was one of the bugs marked for
investigation (and potential fixing) in 3.4 but we ran out of time. Please ping
on the bug if fixing it would be really important for 3.4, and does not require
API changes or feature work.
Comment 7 Boris Bokowski CLA 2008-05-09 08:33:01 EDT
(In reply to comment #0)
> What I noticed is that xsd and wsdl files from outside the workspace are not
> opened with the proper editor anymore, based on their content type. This used
> to work with WTP 1.5.4 (Eclipse 3.2.2). Instead of the WSDL and XSD editor the
> wsdl and xsd files are always opened with the XML editor.

Could this be a duplicate of bug 230865? Valentin, would you mind testing this again with a build >= I20080508-2000 ?
Comment 8 Valentin Baciu CLA 2008-05-13 11:59:12 EDT
Hi Boris, you are right, this can be marked as a duplicate of bug 230865. I have tested the scenario by using a WTP builds based on I20080509-2000 - XSD and WSDL documents located outside the workspace are opened with the proper editors.
Comment 9 Szymon Brandys CLA 2008-05-13 12:07:03 EDT
Thanks Valentin.

*** This bug has been marked as a duplicate of bug 230865 ***