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.
Summary: | EmbeddingProvider does not work for XML or Java | ||
---|---|---|---|
Product: | editor | Reporter: | dbell |
Component: | Parsing & Indexing | Assignee: | Tomas Zezula <tzezula> |
Status: | RESOLVED WORKSFORME | ||
Severity: | normal | CC: | dbell |
Priority: | P3 | ||
Version: | 7.0.1 | ||
Hardware: | Macintosh | ||
OS: | Mac OS X | ||
Issue Type: | DEFECT | Exception Reporter: |
Description
dbell
2011-08-27 08:03: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
(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? 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? (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. 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. |