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.

Bug 201376 - EmbeddingProvider does not work for XML or Java
Summary: EmbeddingProvider does not work for XML or Java
Status: RESOLVED WORKSFORME
Alias: None
Product: editor
Classification: Unclassified
Component: Parsing & Indexing (show other bugs)
Version: 7.0.1
Hardware: Macintosh Mac OS X
: P3 normal (vote)
Assignee: Tomas Zezula
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-27 08:03 UTC by dbell
Modified: 2011-09-05 08:11 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description dbell 2011-08-27 08:03:40 UTC
Using EmbeddingProvider to create language embeddings in XML or Java does not result in any editor support for the language embeddings. However, if XML is embedded in another (CSL) language, embeddings created within the embedded XML are provided with some editor support.  E.G., for language path "text/xml/text/css". no highlighting/code completion is provided for the CSS embedding, but for language path "text/x-mylanguage/text/xml/text/css" both highlighting and code completion work for the CSS embedding.
Also, when creating a language embedding in Java using LanguageProvider.findLanguageEmbedding, lexical highlighting is added, but not code completion or syntax highlighting.
Comment 1 Tomas Zezula 2011-08-29 07:49:40 UTC
The EmbeddingProvider is executed correctly in Java, XML as in others.
There is no special handling of XML, Java in parsing.api.
The parsing api does NOT provide any editor support for the language embeddings it's up to language implementer, you can use CSL support for it or create it yourself.
>no highlighting/code completion - requires correct lexer and mime type.

Embedding into Java works fine (the javadoc support) uses it.
Please attach your project sources otherwise I cannot help.
Thanks
Comment 2 dbell 2011-08-29 14:13:48 UTC
(In reply to comment #1)
Thanks for the response. Could you please clarify your answers for me a little?

> The parsing api does NOT provide any editor support for the language embeddings
> it's up to language implementer, you can use CSL support for it or create it
> yourself.
For an existing CSL language embedded in existing non-CSL language, how do I use the CSL editor support for the embedded sections? E.G., for CSS embedded in XML (I'm using EmbeddingProvider here), how do I activate the existing CSS editor support (the support already implemented using CSL) for the embedded CSS sections?  

> >no highlighting/code completion - requires correct lexer and mime type.
What do you mean by that: do I need to manually make the lexer for the embedded language available to the outer language. E.G. for CSS embedded in XML, do I need to somehow make the CSS lexer available in Editors/text/xml in the filesystem?
Comment 3 Tomas Zezula 2011-08-29 18:52:49 UTC
First af all you need to create TokenSequence of correct embedded mime type. You can do it by TokenSequence.createEmbedding(). The EmbeddingProvider prepares sub languages for specific parsers, ParserResultTasks and UserTasks. But editor features operate on the TokenSequences so you need to create them. Without it highlighting/code completion does not work. Are you doing it?
Comment 4 dbell 2011-08-30 02:47:20 UTC
(In reply to comment #3)
> First af all you need to create TokenSequence of correct embedded mime type.
> You can do it by TokenSequence.createEmbedding(). The EmbeddingProvider
> prepares sub languages for specific parsers, ParserResultTasks and UserTasks.
> But editor features operate on the TokenSequences so you need to create them.
> Without it highlighting/code completion does not work. Are you doing it?

Yes. I am using TokenSequence.createEmbedding() for each XML token within each of the embedded sections that I return from my EmbeddingProvider. I call TokenSequence.createEmbedding() from within the EmbeddingProvider, before it returns.

Here is a simplified version of what I'm doing in the EmbeddingProvider. 

public List<Embedding> getEmbeddings(Snapshot snapshot) {
     TokenHierarchy th = snapshot.getTokenHierarchy();
     TokenSequence<XMLTokenId>  xml = th.getTokenSequence(XMLTokenId.language());
     List<OffsetRange> embeddedSections = getCssBits(xml);
     List<Embedding> embeddings = new ArrayList<Embedding>();
     for(OffsetRange section: embeddedSections) {
         xml.move(section.getStart());
         xml.moveNext();
         xml.createEmbedding(CssTokenId.language());
         embeddings.add(snapshot.create(section.getStart(), section.getLength(), "text/css"));
     }
     return embeddings;
}

There is still no editor support in the embedded sections though. Is there more that's required? I have verified in the logs that the embeddings are successfully created with TokenSequence.createEmbedding(), and that the embeddings are created at the right positions.
Comment 5 Tomas Zezula 2011-09-05 08:11:03 UTC
Sorry for delay I was quite busy with some other work.
The problem is in the following line:
TokenHierarchy th = snapshot.getTokenHierarchy();
The TokenHierarchy you  get is a snapshot not live object and making embedding on it does not change the editor document TokenHierarchy.
You need TokenHierarchy th = TokenHierarchy.get(document);
The rest of the EP seems good.