Creating a language plugin, the custom PsiImplUtil class can't be detected

Answered

I seem unable to correctly make the GrammarKit parser generator detect the custom PsiImplUtil I've written as per the tutorial. This is somewhat mystifying as I've now gone through a bunch of other plugins and as far as I can tell I am not doing anything different.

This is the output:

> Task :generateC3Parser
classpath='[/Users/lerno/.gradle/caches/modules-2/files-2.1/org.jetbrains/grammar-kit/2021.1.2/8ff81b930c29ac479c49600f83acbaf4a248d2a7/grammar-kit-2021.1.2.jar, /Users/lerno/.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/24.0.0/69b8b443c437fdeefa8d20c18d257b94836a92b9/annotations-24.0.0.jar, /Users/lerno/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIC/2022.1.4/e3ffd300c9b86b78a24cd23fdc358ac8493afdf5/ideaIC-2022.1.4/lib/3rd-party-rt.jar, /Users/lerno/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIC/2022.1.4/e3ffd300c9b86b78a24cd23fdc358ac8493afdf5/ideaIC-2022.1.4/lib/app.jar, /Users/lerno/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIC/2022.1.4/e3ffd300c9b86b78a24cd23fdc358ac8493afdf5/ideaIC-2022.1.4/lib/testFramework.jar, /Users/lerno/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIC/2022.1.4/e3ffd300c9b86b78a24cd23fdc358ac8493afdf5/ideaIC-2022.1.4/lib/util.jar, /Users/lerno/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIC/2022.1.4/e3ffd300c9b86b78a24cd23fdc358ac8493afdf5/ideaIC-2022.1.4/lib/util_rt.jar]'
WARN: Attempt to load key 'psi.incremental.reparse.depth.limit' for not yet loaded registry
org.c3lang.intellij.psi.impl.C3PsiImplUtils class not found (PSI method signatures will not be detected)
C3PsiImplUtils.getModuleName(C3Module, ...) method not found
C3PsiImplUtils.getName(C3Module, ...) method not found
C3PsiImplUtils.getNameIdentifier(C3Module, ...) method not found
C3.bnf parser generated to /Users/lerno/Projects/Java/c3intellij/src/main/gen

Settings in the .bnf file:

elementTypeHolderClass = "org.c3lang.intellij.psi.C3Types"
elementTypeClass = "org.c3lang.intellij.psi.C3ElementType"
tokenTypeClass = "org.c3lang.intellij.psi.C3TokenType"
psiImplUtilClass="org.c3lang.intellij.psi.impl.C3PsiImplUtils"

I've verified multiple times that the package is correct. Here is the top of the decompiled class:

package org.c3lang.intellij.psi.impl;

import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import org.c3lang.intellij.psi.C3Module;
import org.c3lang.intellij.psi.C3Types;

public class C3PsiImplUtils {
public C3PsiImplUtils() {
}

public static String getModuleName(C3Module module) {
ASTNode moduleNode = module.getNode().findChildByType(C3Types.PATH);
return moduleNode == null ? null : moduleNode.getText().replaceAll(" ", "");
}

public static String getName(C3Module module) {
return getModuleName(module);
}

public static PsiElement getNameIdentifier(C3Module module) {
ASTNode moduleNode = module.getNode().findChildByType(C3Types.PATH);
return moduleNode == null ? null : moduleNode.getPsi();
}
}

So it's clearly there, but I wonder about how this file is detected. It depends on C3Module, which in turn is depending on the detection of how C3PsiImplUtils looks like. If there is some text parsing used to find the methods, then all is well, except that clearly it is unable to find the sources and I am unsure of how the search actually occurs.

Anything I can try?

0
3 comments

Since the plugin was published, I assume this is obsolete?

0

No, the two first versions of the plugin aren't using the psiUmplUtilClass setting. After researching this in depth it turns out that this just happens any time you're using the Gradle plugin with psiUmplUtilClass. Which is something that might be highlighted much more clearly in the tutorials. I spent way too many hours trying to fix what I thought was my own mistake.

 

0

There are some limitiations when using Gradle task for generating Parser/PSI, but I don't think this would be one of them. If you have a reproducible case, please file issue here https://github.com/JetBrains/gradle-grammar-kit-plugin

0

Please sign in to leave a comment.