History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: IDEADEV-5499
Type: New Feature New Feature
Status: Resolved Resolved
Resolution: Fixed
Priority: Normal Normal
Assignee: Maxim Mossienko
Reporter: Keith Lea
Votes: 28
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
IDEA: Development

Add means of specifying XmlElementDescriptor for some XmlTag through OpenAPI

Created: 17 Aug 05 18:05   Updated: 11 May 06 19:22
Component/s: Plugin Support. API
Fix Version/s: Demetra 5231

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown
File Attachments: 1. Zip Archive Demetra XML test.zip (19 kb)
2. Zip Archive Demetra XML test.zip (10 kb)
3. Zip Archive IDEA test project.zip (8 kb)


Build: 3,448
Fixed in build: 5,227
Severity: Medium


 Description  « Hide
Currently I am writing custom inspections + completions + reference provider for custom XML language. However, my custom inspections are duplicating work from IDEA's parser, concerning required tags and attributes, accepted values, and so on. It would be more convenient to be able to plug in an XmlElementDescriptor for the tags instead, and let IDEA do that work.

 All   Comments   Work Log   Change History      Sort Order:
Sascha Weinreuter - 17 Aug 05 18:13
This is related to IDEA-624

Maxim Mossienko - 29 Sep 05 22:45
This is unofficial API that will work after 3507+:
Consider we have xml like following example to be bound to custom descriptors:
<ns:mytag xmlns:ns="myuri">
...
</ns:mytag>

One needs to map the uri ( "myuri") to (e.g.) xml schema file that has "myuri" as target namespace (via external resource manager mapping),
then add descriptor mapping like following:

MetaRegistry.addMetadataBinding(
new AndFilter(
new ClassFilter(XmlDocument.class),
new TargetNamespaceFilter("myuri")
),
MyNsDescriptor.class // class should be public and has public no arg constructor, it should implement XmlNsDescriptor interface
);

IDEA will instantiate the MyNsDescriptor and will query the instance for XmlElementDescriptor/XmlAttributeDescriptors for original document tags/attributes

IDEA uses XmlElementDescriptor / XmlAttributeDescriptor for the validation and completion in the xml.


Keith Lea - 29 Sep 05 22:50
Wow, I'm excited to use this in the next build. Thanks Maxim.

Keith Lea - 08 Feb 06 20:43
Maxim, I finally got to using this API. It looks like, when Filename.xml is opened, my ElementFilter is being called on some virtual document called Filename.xml.dtd, which contains full DTD specification PSI. It's never called on the actual elements of the XML file. Is this correct? Is there some way to figure out which file that DTD corresponds to?

Maxim Mossienko - 09 Feb 06 16:20
IDEA defaults to dtd creation when schema descriptor could not be found

Keith Lea - 09 Feb 06 17:41
Is there some way to figure out which file that DTD corresponds to?

Keith Lea - 10 Feb 06 02:08
Completion won't work. I think it worked at first, then I must have changed something to break it. I return a big array from getElementsDescriptors(XmlTag), and the popup shows "No suggestions." Why would this happen?

Maxim Mossienko - 06 Apr 06 23:01
Keith, I wonder if you have successfully attached your custom XmlElementDescriptors,

Keith Lea - 06 Apr 06 23:52
They are definitely attached, as validation works, but completion does not.

Maxim Mossienko - 07 Apr 06 00:05
Does the getName(PsiElement), getRootElementDescriptors(), getElementDescriptors called for your descriptors during completion?

Maxim Mossienko - 07 Apr 06 21:25
Keith, I am keen to know about completion issue with your descriptors. Could you answer previous question, please?

Keith Lea - 07 Apr 06 21:48
I'll check now, and report back soon. It's been a while since I touched that code as I couldn't get it working.

Keith Lea - 07 Apr 06 22:26
It looks like now completion works. Some fix must have been committed since February because I haven't changed the code.

However there's big problem with the API. The files are defined like this

<cool:root>
<etc/>
</cool:root>

There are no xmlns descriptors. IDEA highlights every cool:* tag in red as "Namespace cool is not bound." I wrote this code so long ago that I don't remember how this code works, so I can't guarantee that I'm not doing something wrong, but I'd appreciate any help.


Maxim Mossienko - 11 Apr 06 19:07
To provide your one info on used namespaces you may implement 'XmlFileNSInfoProvider' in your ProjectComponent. It will be quired for default prefixes and their namespaces for particular files.
You can register your PsiMetaData derived classes (XmlElementDescriptor/XmlNSDescriptor, etc) via MetaDataRegistrar that will be used as descriptors

Keith Lea - 11 Apr 06 19:32
Maxim, this does not work in 5.1.1. Will you provide 5.1-series EAP build with this fixed? This bug is preventing large number of people from upgrading from 5.0.2 here.

Maxim Mossienko - 11 Apr 06 19:37
The enhancement is implemented in Demetra branch, if something is not working in 5.1.1 please file separate request

Keith Lea - 11 Apr 06 19:51
In my comment above (07 Apr 06 22:26) I explain the problem. This is in 5.1.1. I am correctly using metadata registry I know, because validation and completion works. However, the entire file is highlighted in red for "namespace cool not bound". Can I do something to avoid this in 5.1.1?

Maxim Mossienko - 11 Apr 06 19:54
You may ask the Hector to not inspect the XML files

Keith Lea - 11 Apr 06 19:57
I want my custom XML descriptor validation to occur. I don't want the "namespace not bound" inspection to occur. Hector won't do this. I will not tell my plugin's users to click hector for every xml file they ever edit, anyway.

Maxim Mossienko - 11 Apr 06 20:06
Custom XML descriptor validation should work independent from the Hector setting (or you mean ExternalAnnotator?). I believe the plugin could set HighlightingSettingsPerFile per needed file.

Keith Lea - 11 Apr 06 20:23
Max, there are two problems with that:

1. Part of XML validation does not occur (such as "tag is not allowed here")
2. My custom XML inspections do not occur

Is there another workaround?


Maxim Mossienko - 11 Apr 06 20:43
Keith, WHERE have you been in the EAP of 5.1?
First problem is most likely because one of your parent descriptors does not provide the descriptor for child tag
As to inspections, you could run them if your descriptor implements Validator

Keith Lea - 11 Apr 06 21:47
I was here, waiting for your response to my comments in February I'll look into how to work around this problem. As I said I'm not super familiar with this code because I abandoned it in February because it didn't work.

Maxim Mossienko - 12 Apr 06 15:38
Have you solved the problems with work around above?

Keith Lea - 12 Apr 06 17:28
I will try to get it all working today. I will let you know how it goes.

Keith Lea - 12 Apr 06 23:51
No, this won't work, it's too painful. I have about 30 inspections defined for this xml language and I won't convert them all to Validators. Additionally that would prevent them from being run in batch without me having to write custom batch inspection engine.

It would be great if you could make this work in 5.1 series and release EAP build. Until then most of us will not upgrade to 5.1.


Maxim Mossienko - 13 Apr 06 11:39
There is no plans about any development for IDEA 5.1, you need to discuss it with Max or Alex

Maxim Shafirov - 13 Apr 06 20:19
5.1 branch is closed for new features and API change. Period.

Keith Lea - 13 Apr 06 21:45
We cannot upgrade to 5.1 then. Is there some channel we could use to avoid this in the future? We waited for 2 months for a response to this, and by then the EAP was closed. You guys are generally not responsive to posts on openapi forums or jira requests.

Maxim Mossienko - 13 Apr 06 22:53
Your post (http://www.jetbrains.net/jira/browse/IDEADEV-5499#action_47324) for API problem was after the EAP for 5.1/5.1.1 had ended...
Probably, you may "inject" your namespace ids and xmlemenentdescriptors via reflection...

Maxim Mossienko - 25 Apr 06 15:09
Keith, could you, please, check api in Demetra?

Keith Lea - 25 Apr 06 17:01
Sure, I'll try to write up some code today that produces correct result in demetra but wrong result in 5.1.1.

Keith Lea - 26 Apr 06 07:23
Okay, so it'll be tomorrow.

Keith Lea - 28 Apr 06 00:01
Maxim, it still shows the error. I'll attach sample project.

Maxim Mossienko - 28 Apr 06 16:45
Your Loader doesn't implement 'XmlFileNSInfoProvider' interface that was added (and described in my comment)
Adding following code fix esthe unbound ns error.

public static final String MY_NS = "net.kano";

@Nullable
public String[][] getDefaultNamespaces(@NotNull XmlFile xmlFile) {
if (isAcceptableFile(xmlFile.getName()))
return new String[][] {new String[] {"cool",MY_NS}};
return null;
}

private boolean isAcceptableFile(String name) { return name != null && name.toLowerCase().endsWith(".cool"); }


Keith Lea - 28 Apr 06 20:22
Yes, you're right. However, now illegal tags are not highlighted like <cool:illegal/>

Maxim Mossienko - 28 Apr 06 20:35
IDEA complains about
<cool:illegal/>
that element is not allowed here

Keith Lea - 28 Apr 06 22:02
It doesn't highlight in red for me, when it's the root element.

Maxim Mossienko - 28 Apr 06 23:08
when <cool:invalid/> is root tag it is red with 'element should be declared' message

Keith Lea - 02 May 06 23:15
I've attached udpated plugin project, and sample project to load with it. When I do this, I don't see any red marks in the file "test.cool", using build 5245.

Maxim Mossienko - 03 May 06 19:02
Keith, the problem is with your code, check out result of isAcceptableFile call results.

Keith Lea - 10 May 06 19:50
Maxim, in 5.1.2 this seems to work, but there are a few things:
  • It is not documented how to set default namespace (for non-prefixed elements)
  • Returning an array containing { null, "http://myuri" } seems to break it completely

Am I right in assuming returning an array with { "", "http://myuri" } is how to set default namespace?


Maxim Mossienko - 10 May 06 20:18
nonprefixed items have "" prefix,
IDEA does not use provider that gives wrong (null) info, check '#com.intellij.xml.util.XmlUtil' debug messages

Keith Lea - 11 May 06 19:22
You should add javadoc explaining that.