Better way to interact with AST?

Hello!

I’ve been working on a plugin for a bit now and I started working on a feature which has to read the AST. The issue I’m facing is that the implementation seems to be very IDE-dependant, and unstandardized.

For instance, if I want to find a “function” ASTNode, the elementType is different for each language. So far my approach was to match all types into my own and use that within my code, but I feel like that’s not gonna work great in the long run. Today I looked at a C++ AST within Rider and functions were “DummyNodes” and “DummyBlocks” (so, first the block isn’t even a child of the function, and second, are they dummy?)

So anyhow, I’m wondering if instead there’s a better way to interact with the AST, that would be more language and IDE agnostic. Otherwise I’ll have to manually test each language I want to support which will take a lot of time.

Thanks!

I have also encountered similar problems. Since CLion started using the Nova language engine, the AST and PSI APIs have become practically useless. Just as you pointed out, DummyNodes are everywhere. My plugin also cannot support Nova for the time being. I can only suggest users switch back to the Classic Language engine to be able to use it.

In general, you need extension point and implementations for different languages. Sometimes, the platform tries to generalize some aspects of PSI tree, such as PsiLanguageInjectionHost or ContributedReferencesHost interfaces, but methods/funstions are definitely all different in various languages.

It is also not really AST but more like PSI = AST + Semantics