manifold-systems / manifold

Manifold is a Java compiler plugin, its features include Metaprogramming, Properties, Extension Methods, Operator Overloading, Templates, a Preprocessor, and more.
http://manifold.systems/
Apache License 2.0
2.42k stars 125 forks source link

manifold-strings: `this.` missing syntax highlighting & references in string templates #624

Closed s809 closed 1 month ago

s809 commented 1 month ago

When class members in string templates are prefixed with this, they have no syntax highlighting and they don't show up in references.

Works: image image

Does not work: image

rsmckinney commented 1 month ago

The manifold plugin integrates Java expressions in string templates using IntelliJ's language injection feature. In order to parse correctly, the injection API requires that expressions are wrapped in a class. Using your failed example, the expression is parsed something like this:

class Xxx { Object xxxfield = this.serverLevelWrapper.getDimensionName(); }

The problem appears to be that this is a reference to class Xxx, being a local inner class this does not have access to the outer serverLevelWrapper field. I would chalk this up as a general limitation of language injection. Or, perhaps there is another way to expose the expressions in a way where this works as expected?

s809 commented 1 month ago

I don't know much about IntelliJ's plugin system yet, but is there a way to at least somewhat transparently substitute this with ClassName.this in that case?

rsmckinney commented 1 month ago

is there a way to at least somewhat transparently substitute this with ClassName.this in that case?

For simple cases where the expression begins with this, that's not a bad idea, I'll look into that. But for more complex expressions where this is elsewhere in the expression, it may cause problems with injection parsing wrt location/offset .

rsmckinney commented 1 month ago

Latest plugin now supports the simple case where an expression begins with this.