Implementing the XML API for a custom language
Hi,
I have a plugin for the XQuery language which supports XML-style element construction (e.g. `<test>example</test>`), but also supports constructing them dynamically (e.g. `element test { "example" }`). I want the support to work when these are mixed, and when using XQuery-specific things like expression markers (e.g. `<a>{ 1, text { "2" } }</a>`) and escaping (e.g. `<a>{{ 1 }}</a>`).
I've implemented the language support for all these, but would like to better integrate it into IntelliJ by implementing the XML API (XmlTag, XmlAttribute, etc.). Are there any guides, references (aside from the IntelliJ source code), other language plugin sources for doing this that I can look at?
My main goal with this is to be able to support 1) XML/RNG schema based validation, auto-completion, etc., 2) XML-based language injections, e.g. JavaScript and CSS, and 3) other XML autocomplete and reference provider extensions.
Looking at the code, some of it is making assumptions that the root file is an XmlFile, and that certain XmlElementType tokens exist.
Kind regards,
Reece
请先登录再写评论。
Hi Reece, first of all, we appreciate your efforts to make such a valuable plugin!
As far as I know, XQuery is a mixture of xml and query elements. I'd recommend to implement com.intellij.psi.MultiplePsiFilesPerDocumentFileViewProvider, which is intended to provide multi-root PSI, so that you have one XmlFile and one query-language file mapped to the same VirtualFile.
Thanks. I'll take a look at that provider.
I've experimented with this and have concluded that I need to provide my own implementation of the IntelliJ functionality, like I've done with the XML breadcrumbs support. This is because the XQuery XML support is sufficiently different from the IntelliJ XML implementation that I cannot reuse that via MultiplePsiFilesPerDocumentFileViewProvider, nor reimplement the APIs.
I'm adding an abstraction layer that supports the IntelliJ XML API and XQuery's direct and computed XML, which is working well so far. Using that I've made some of my support for MarkLogic's rewriter XML work within XQuery, and am working to support the other areas as well.
This means I'll also need to replicate the language injection for CSS, JavaScript, etc. and implement an equivalent of the namespace/element/attribute descriptors as those use the IntelliJ XML APIs.