-
Notifications
You must be signed in to change notification settings - Fork 905
Move CSL/GSF mark occurrences handling into API module and fix PHP highlighting #8844
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Move CSL/GSF mark occurrences handling into API module and fix PHP highlighting #8844
Conversation
…age, PHP OccurrencesFinderImpl
…ep Marks" Handling According to the documentation of OccurrencesFinder the occurrences scanning should be stateless. The current API holds a calculate and a getter method, but in the spirit of keeping it mostly stateless, more state should not be added. The OccurrencesFinder implementation returns a set of occurrenes corresponding to the currently highlighted area. These areas are described by integer arrays (2 elements, start and end index). Given the return types these areas are only valid until the next edit occurrs. On each input the highlights are recalculated. That works fine until "Keep Marks" is activated. "Keep Marks" keeps the marks, when the caret is moved of a highlightable variable. If "Keep Marks" is enabled the marks will be retained then until the caret is placed onto another highlightable element. The marks in this case must adapt to changes of the content of the element. Swing Document provides the "Position" class for this. That class is used by GsfSemanticLayer to hold the areas returned by the OccurrencesFinder implementation. So to support "Keep Marks" the CSL/GSF layer has to be aware of this, so that the GsfSemanticLayer can retain the highlights. In addition to this there is no need to scan for occurrences if the highlighting is disabled, so that also moves to the CSL/GSF layer. Closes: apache#8803
…ion Language, CSS, JS, JSON
657adc6
to
5f76b96
Compare
@matthiasblaesing I tested the dev build. Everything works great. Thank you very much! |
@lahodaj @junichi11 @tmysik @lkishalmi it would be great if you could have a look at this. The storage of preferences in the antlr and javascript modules feels a bit strange, but I think it is in line with the established usage in the Java and PHP modules. The API addition should be safe from my POV. Implementors might already implement the new methods, but I think the names match their usecase, so that should not be a problem. Differing return values would violate the JavaBeans contract. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looked trough this. Nothing jumped out.
Nice work. Thanks!
import org.openide.awt.*; | ||
import org.openide.util.Exceptions; | ||
|
||
public class MarkOccurencesPanel extends javax.swing.JPanel { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: FQNs used, here and below.
|
||
OccurrencesMarkProvider.get(doc).setOccurrences(OccurrencesMarkProvider.createMarks(doc, bag, ES_COLOR, NbBundle.getMessage(MarkOccurrencesHighlighter.class, "LBL_ES_TOOLTIP"))); | ||
boolean updateHighlights = false; | ||
if(seqs.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(seqs.isEmpty()) { | |
if (seqs.isEmpty()) { |
updateHighlights = true; | ||
} | ||
|
||
if(updateHighlights) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(updateHighlights) { | |
if (updateHighlights) { |
import javax.swing.JCheckBox; | ||
import org.openide.util.Exceptions; | ||
|
||
public class MarkOccurencesPanel extends javax.swing.JPanel { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: more FQNs usages, here and possibly in other files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thank you.
Several classes are very similar, but since they are in different modules, we can hardly (don't want to) do anything about it.
Pushed changesets with the points raised by @tmysik (these will be squashed before merge). |
its a bit unfortunate that things like this add so much duplicated UI code :( But other than that a great addition of course. (e.g was working on fixes for the go-to (ctrl+o) dialogs when I saw that its 3 different impls which diverged over time.) |
@mipaaa @troizet @lkishalmi @mbien @tmysik thanks for testing/review/checking. I intent to merge this by the end of the week unless there are objections raised till then. |
The CSL/GSF infrastructure of NetBeans provides the basic infrastructure for the editor to highlight other occurrences corresponding to the element the caret is currently being placed on.
For Java and PHP there is an option offered to keep the occurrences, even when the caret is moved of the highlightable element. The occurrences hightlights are then retained until another highlightable element is selected. This is called "Keep Marks" in NetBeans options.
In NB27 for PHP the option to switch "Keep Marks" was wired up, but proved to be problematic. The OccurrenceFinder class, GSF/CSL implementors have to implement, returns highlighting areas. The return consists of indexes into the text content. For normal operation the finder can trivially be run again when the text is modified to update the highlights, this is not the case for the "Keep Marks" case. As the positions of the characters change, caused by deletions and insertions, the highlights can't be updated, as the originating element is not accessible anymore (the caret was moved of it).
The Swing Document class has a solution for this: javax.swing.text.Position. Under the hood CSL/GSF already uses this in the GsfSemanticLayer, so the problem is solved there.
To support "Keep Marks", handling of this configuration has to move to the CSL/GSF level.
In addition to this there is no need to scan for occurrences if the highlighting is disabled, so that also moves to the CSL/GSF layer.
With the infrastructure in place, in addition to Java and PHP (now fixed), support is added for:
Closes: #8803