This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
I am making a module to add a specific code completion to XML files. I can't add attributes to the schema in my XML, because the parser that read the XML does not support it. I created a simple XML and XSD file to test it out. The XML file: <note> <from>Me</from> <to>You</to> <content>I want some help.</content> </note> The XSD file: <xs:schema> <xs:element name="note"> <xs:complexType> <xs:sequence> <xs:element name="to" type="xs:string"/> <xs:element name="from" type="xs:string"/> <xs:element name="content" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> So what I tried to do was to use the addCompletionModel method of CompletionContextImpl to add my completion model but I don't get code completion. I looked at the source code of CompletionContextImpl and I found out that for completion models that have no namespace, I need to have the "noNamespaceSchemaLocation" attribute set in my XML document for the model to be set as the default "noNamespaceModel" of the CompletionContextImpl. I can clearly see that during "initModels", the line if(noNamespaceSchemaLocation != null && noNSModels.size() == 1) stop it from setting my "no namespace model" if I don't have the "noNamespaceSchemaLocation" in my XML. I tried it out and simply by changing my XML file to: <note noNamespaceSchemaLocation=""> <from>Me</from> <to>You</to> <content>I want some help.</content> </note> I will finally get code completion, but since I can't add the "noNamespaceSchemaLocation" in my XML, I can't use that solution.
Rather than using the addCompletionModel method directly, I created a CompletionModelProvider based on the code from MetaSchemaModelProvider. As expected, the result is still the same: no code completion unless I write down 'noNamespaceSchemaLocation=""'. The best solution for now that I was able to find is to create my own CompletionUtil class. In it, I changed my findAXIElementAtContext method to use getNoNamespaceModels rather than getActiveNoNSModel. By doing this I can get code completion like I need, but I doubt this is the right way to do it.
Marking as enhancement. Option #1: is to allow a extension module to specify the noNamespaceModel - if there's > 1 no namespace model, then the implementation cannot decide and simply ignores no namespaces. Option #2: allow the user to assign no namespace schema to any XML file; this will help when there's no specific module handling the file, but restrictions on contents are similar (e.g. nonstandard parser, which does not recognize standard attributes)