Making a language without a file type
I am working on the Rust language plugin for intellij. There is a much simpler language used by rust for their format strings with it's own grammar and it's own lexer. I have made the spec for the language and am able to generate the parser, but I'm having trouble registering it in the plugin.xml. The ParserDefinition for this language requires a PsiFile. This requires a file type, which requires a file extension. This language is only meant to be injectable into string literals, it does not coorespond to a file or file type. How do I register the parser definition that I've made with intellij without a file type and then make it available as an injectable language?
请先登录再写评论。
The language must implement "InjectableLanguage",
but you still have to define FileType (return "" as default extension).
Yup, your assist was right on the money. I've now gotten my injector working to implicitly parse and highlight string literals matching certain criteria like where they are.
Now I'm stuck on one thing. On regular string literals, I would like to be able to manually inject the language. To make the element injectable to begin with, I had it implement PsiLanguageInjectionHost. In the UI, the drop down to inject a language is now available on alt + enter, but when I select the language I've just made, it does not get highlighted or parsed (to my knowledge). Do you have any tips for debugging this? It looks like every call to isValidHost resolves true when I put a breakpoint in it so it's not that.
Technically any language I try to inject into the PsiLanguageInjectionHost block is ignored. Am I missing something here on my injectable elements?
Possible breakpoint locations: