About language injection

Answered

Hello
  I have customized a language. If I inject it into the xml file, I cannot complete the parameter reference and parameter renaming operations, but if I use it as a separate file, I can automatically complete these operations, what is there? Is there a good way to handle this?

0
8 comments

Hi,

Please provide us with more details. What are host and injected languages? What are examples of not working cases? What are expected completions and how are they implemented?

0

Hello
   Like this https://github.com/JetBrains/intellij-sdk-code-samples/tree/main/simple_language_plugin
If I build the test.simple file with the following content:
       webUrl=https://plugins.jetbrains.com/docs/intellij/welcome.html
The content of the test.java main method is as follows:
         system.out.println("simple:webUrl"),
In this case, if I rename test.simple webUrl or webUrl in system.out.println("simple:webUrl"), test.simple will be updated
webUrlNewName=https://plugins.jetbrains.com/docs/intellij/welcome.html
and system.out.println("simple:webUrlNewName") .
but when i inject the simple language into the xml file, my xml file also has
webUrl=https://plugins.jetbrains.com/docs/intellij/welcome.html
, I can't complete the above operation

0

Hi,

Please share more information. If you have a language injector implemented, then please show its code. I can't guess what's the reason without the code.

If it is done for the Simple language from the tutorial, please share your full project code then, so I can easily reproduce it.

0

Hello
  This is the address of the language project after my transformation: 

https://github.com/zoulejiu/simple_language_plugin
This is the project address I use for testing:
https://github.com/zoulejiu/languageDemo

Below the simple_language_plugin project I created a new language injection class:
org.intellij.sdk.language.injector.MyMultiHostInjector

The languageDemo project is as follows:
There is a test.xml file with
     webUrl1 = www.test.com
The test.simple file contains
     googleUrl1 = www.google.com
com.example.Test
          System.out.println("simple:googleUrl1");
         System.out.println("simple:webUrl1");

When my cursor is in the Test class simple:googleUrl1 Using shift+F6, after changing the new name, it will also automatically change the key in the test.simple file
But when I change simple:webUrl1, the key in the corresponding xml file will change automatically, but it will not change itself

0

Simple language contributes references only in Java files, see SimpleReferenceContributor.

Your Simple element in the XML file doesn't resolve to any target. You should provide references for XML as well.

PS
This post seems to be about the same issue: https://intellij-support.jetbrains.com/hc/en-us/community/posts/4600595474962-problem-with-renaming

Please do not create multiple posts for the same issue.

0

Hello
  Now the xml file parameters can jump to Test.class, Test.class can also jump to the xml file, but when I modify the name of the Test.class webUrl1 parameter, the parameters in the xml file will change, Test.class The parameters won't, I don't know where I have a problem.
In order to quickly implement the test code, my parameter names are written dead, only webUrl1 can get them, please ignore, I have submitted my latest test code in the master branch

0

Sorry, but I misunderstood your case. I thought you want to inject simple language references in XML that resolve to declarations in *.simple files. If the references are in a Java file, then you can use the existing contributor and I can see that your try to find declarations in SimpleUtil.findProperties() - this is the correct approach.

The problem is in the find usages. For some reason, references cannot be found, but I don't see why. I suggest debugging references search mechanism and finding the difference between working "simple:googleUrl1" and not working "simple:webUrl1" cases.

0

Hello
  Yes, I have been debugging the difference between the two, but there are too many code call chains at the bottom, especially the ReferencesSearch.search() method cannot be debugged. The language I injected myself also had this problem. , Now using this simple language, the same problem occurs, so I don't know where the problem is now, only when it is injected into other languages.

0

Please sign in to leave a comment.