Resolve to FakePsiElement - Predefined classes in custom language
Hi, I want to have references to some predefined classes in my custom language plugin. However there is no standard library which I can reference to, I basically only have the definitions of those classes and methods available in them. Can anyone give me a bit detailed reference to a doc/guide on how to achieve this. One way I'm thinking is to create files containing those classes/methods and referencing to them later on. Is this a proper solution?
There was also a suggestion to create files in my code/resources and have reference to FakePsiElement but I couldn't find any examples of this and couldn't make it work.
To put it simple. I want my annotator to find class Array (predefined class) as well as user defined classes (which it currently can't for obvious reasons) and also to have ability to query methods inside Array class like I do on my classes defined during development.
Update: I managed to make additionalLibraryRootsProvider work, however it only works when I create the project because I have toolchain path at that moment and can copy files in toolchain lib from my resources files. However I can't retrieve the path to the toolchain on consecutive launches of the editor instance. How can I query the path used by the toolchain ? Or how can I save the path permanently on startup? Or maybe there is some other better solution for this?
Update 2: I'm stupid, I used projectSettings, got toolchain and it's location from there and everything works like a charm
Please sign in to leave a comment.
Hi,
There is no documentation for this problem.
The solution can be creating some source of definitions of the classes/methods/symbols that are predefined in your language. It could be a class with some list, map, enum, whatever. The purpose is to have a class where y hold what classes are predefined, what methods with what parameters it contains, etc.
Once you have such definitions, you can use them in code completion, documentation provider, etc.
Also, you can create a FakePsiElement object from the resolve() methods in your references. The resolve() method can check if a given symbol matches any definition you created and create an instance of PsiFakeElement holding information like class name, method name, etc. PsiReference.isReferenceTo() in other references should return true if a given reference also matches the predefined symbol usage.