antlr / intellij-plugin-v4

An IntelliJ plugin for ANTLR v4
https://plugins.jetbrains.com/plugin/7358-antlr-v4
BSD 3-Clause "New" or "Revised" License
461 stars 103 forks source link

live templates stopped to work #700

Open tbabczynski opened 4 months ago

tbabczynski commented 4 months ago

After IntelliJ update (to 2024.1) live templates stopped to work in .g4 editor. More, in settings for the live templates, they are not associated to anything and "no applicable contexts." warning appear. BTW. Should they be grouped in generic "user" group?

tbabczynski commented 4 months ago

Here, I discovered that it is not only the update issue but also the new Jetbrains' view. The live templates for ANTLR 2023.1.6 don't work in new UI but they work in the old one. The ANTLR doesn't appear on the context list. (I didn't check all versions between them.)

EDIT: In 2023.2.6 it doesn't work. In 2023.1.6 on my laptop it works in classic UI view, doesn't work in the new one. On the laptop of one of my students, who had this version and never had any newer, the live templates worked in both views. I don't know why. I discovered that even in the newest version the live templates work if one choose the "other" checkbox in the context define dialogue. Just the ANTLR context disappeared in the 2.6 version. Something must have changed in the editor registration process and the way the plugin used to do it stopped working.

tbabczynski commented 4 months ago

Maybe it will help. I checked the com.intellij.codeInsight.template.TemplateContextType in the jetbrains repository. It has a bunch of @deprecated marks in methods you used in the plugin, e.g. public boolean isInContext(@NotNull PsiFile file, int offset) - * @deprecated use {@link #isInContext(TemplateActionContext)}

public OutsideRuleContext() {
    super("ANTLR_OUTSIDE", "Outside rule", ANTLRGenericContext.class);
}
/**  @deprecated Set contextId and baseContextId in plugin.xml instead */
@Deprecated
  protected TemplateContextType( String id,  String presentableName,  
    Class<? extends TemplateContextType> baseContextType)

They were deprecated in 2022 but maybe now they work no longer.

bjansen commented 4 months ago

The new method still delegates to the old one that we override, so I don't think the problem is there. I made changes recently to fix compatibility with 2024.1, but it's possible I missed something. I'll look into it.

tbabczynski commented 4 months ago

Wouldn't be better to put templates to "ANTLR" group instead of "user"? And contextID also "ANTLR" or "ANTLRLex", "ANTLRv4"? I don't know how IntelliJ plugins work, never have written any, but I have a little experience with eclipse plugins, so I understand the key ideas behind the process. Unfortunately I have critical low disk space on my laptop so I cannot compile plugin from github. Do you have any nightly build snapshot available to test?