Overriding FoldingDescriptors [SOLVED]
Hello,
I have written a plug-in for facilitating work with translation library used in our PHP projects. This plug-in makes use of FoldingDescriptors to substitute generated class constant with the text, the constant stands for(in the default language of the project). I came across a problem, when some of my constants references aren't getting substituted:
This is how it looks without folding:

This is how looks with folding:

I discovered the source of problem is that IntelliJ ignores my FoldingDescriptors, as there are already FoldingDescriptors registered on the same TextRanges. Ad https://github.com/JetBrains/intellij-community/blob/master/platform/core-api/src/com/intellij/lang/folding/CompositeFoldingBuilder.java#L61 . These FoldingDescriptors come from the FoldingBuilder of the PHP language plugin and they are attached to node corresponding to MethodReference PSI element and their TextRange is from left bracket to the right bracket in method call. Funny thing is - and I am not sure if it isn't a bug - that these get only registered when there is a newline between the method call and the variable the method is called on. This manifests even without my plugin in use in following way -
Cannot be folded:

Hitting CTRL+period inside 'asd' folds the whole method:

Can be folded:

Hitting CTRL+period inside 'asd' folds the parameters of the method call:

The two questions are -
a) is there a way, when some other plug-in/official language plug-in registers a FoldingDescriptor to override it in my plug-in
b) is the way, how FoldingDescriptors are created for PHP MetodReference expected behavior and why
Please sign in to leave a comment.
The answer to a) - try using 'order' attribute (with 'first' or 'last' value) when registering your FoldingBuilder extension.
Works like a charm! Didn't know about the 'order' attribute. Thx!