Custom Language generated code reference

Answered

Hello,

I have implemented a framework that utilizes a custom DSL to generate Java code. The code is the compiled using a maven plugin. This has been done separately from the IntelliJ ecosystem and is already working.

In order to support development using said framework, I started working on an IntelliJ custom language plugin. It's looking good and has got me excited. However I have been struggling with defining references to my custom language files. What I wish to do is have the generated classes reference my PSI element as a source and also have any usages of those classes in Java code linked as well, so that I can utilize autocompletion, find usages etc.

I followed the Reference Contributor tutorial as well as the References and Resolve guide, but I am not sure I am on the right track.
Is there any example I can follow? Any guidance will be appreciated.

Thanks in advance,

Christos

0
4 comments

Hi Christos,

The pages you linked are correct. Please explain what is the issue you are facing.

0

The example that is provided, shows how to reference an element of my language from within Java. I need to do the opposite.
For example, my framework generates a class based on some code and configuration.

#package com.test
#class Test

which generates Test.java containing the Test class.

package com.test

public class Test(){
}

 Let's now say that my user has some code instantiate the Test class with 

new Test();

What should I do so that the generated class shows my custom code as its source and the usage refers to my code instead of the generated Test.java file?

0

Hi Christos,

Unfortunately, it doesn't seem possible in your case. Java elements like new Test() do not allow contributing references (they don't implement ContributedReferenceHost).

An alternative solution can be to use gutter icons, which will navigate to your language elements. See https://plugins.jetbrains.com/docs/intellij/line-marker-provider.html for details.

0

Thank you very much for your response.

I thought since other languages such as Kotlin could do something like this, that maybe there was something I was missing.

But I guess from your response that this just isn't part of the open API.

Anyway, thanks for your time, you were really helpful!

 

EDIT: I will try using symbols instead. I really want to be able to use features such as go to definition with my project

0

Please sign in to leave a comment.