-
Notifications
You must be signed in to change notification settings - Fork 58
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
[#934] fix removed folding annotations on document change #935
Conversation
The method ProjectionAnnotationModel.modifyAnnotations(Annotation[], Map<? extends Annotation, ? extends Position>, Annotation[]) does not consider Position changes in any cases. On large annotations the positions won't get updated properly which leads to removed folding annotations. fixes eclipse-lsp4e#934
@@ -269,9 +269,7 @@ protected void updateAnnotations(Annotation existingAnnotation, Position newPos, | |||
Position oldPos = theProjectionAnnotationModel.getPosition(foldingAnnotation); | |||
// only update the position if we have to | |||
if (!newPos.equals(oldPos)) { | |||
oldPos.setOffset(newPos.offset); | |||
oldPos.setLength(newPos.length); | |||
modifications.add(foldingAnnotation); |
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.
modifications can be removed from the arguments list of this method. But this would be an API break.
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.
I do not think there will be many subclasses of LSPFoldingReconcilingStrategy, so I would prefer that we modify the signature accordingly (or probably just remove the method, as it does not update anything any longer.)
@mickaelistria , what do you think?
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.
FYI Mickael is not available this week.
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.
Since Mickael is not available this week, could you mark the method as deprecated for removal and document on the javadoc that the parameter is unused? Then we can cleanup on a later iteration.
Are we fixing a problem with ProjectionAnnotationModel.modifyAnnotations? Or how is it that "On large annotations the positions won't get updated properly which leads to removed folding annotations"? |
Not really. IMO we haven't used the proper method. And |
I guess that you mean that call |
That was my assumption I made after some debugging to determine why the folding annotations disappear as described in my issue #934. |
- Users should use the new method with updated signature.
@@ -151,7 +150,7 @@ private void applyFolding(List<FoldingRange> ranges) { | |||
if (ranges != null) { | |||
Collections.sort(ranges, Comparator.comparing(FoldingRange::getEndLine)); | |||
for (FoldingRange foldingRange : ranges) { | |||
updateAnnotation(modifications, deletions, existing, additions, foldingRange.getStartLine(), | |||
updateAnnotation(deletions, existing, additions, foldingRange.getStartLine(), |
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 we think anyone could be using the deprecated method, we still need to call it, otherwise we would be breaking the customized code.
For me, if you could revert to use the old method, we could merge.
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.
we still need to call it, otherwise we would be breaking the customized code
Hm, I am not sure I am understand you here. The modifications is always empty, because its not written anymore in LSPFoldingReconcilingStrategy.updateAnnotations(existingAnnotation, newPos, deletions)
. The updateAnnotation
which is called here in line 153 is a private method.
Theres no need to call the deprecated LSPFoldingReconcilingStrategy.updateAnnotations(existingAnnotation, newPos, modifications, deletions)
method here.
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.
Hm, I am not sure I am understand you here. The modifications is always empty, because its not written anymore in
LSPFoldingReconcilingStrategy.updateAnnotations(existingAnnotation, newPos, deletions)
Yes, the method as we have rewritten it will return empty annotations, but if some subclass subclassed the method, we still need to call it, otherwise we would break the customization.
@@ -167,8 +167,7 @@ private void applyFolding(List<FoldingRange> ranges) { | |||
} | |||
// send the calculated updates to the annotations to the | |||
// annotation model | |||
theProjectionAnnotationModel.modifyAnnotations(deletions.toArray(new Annotation[1]), additions, | |||
modifications.toArray(new Annotation[0])); | |||
theProjectionAnnotationModel.modifyAnnotations(deletions.toArray(new Annotation[1]), additions, new Annotation[0]); |
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.
We still need to pass modifications
to theProjectionAnnotationModel.modifyAnnotations
, as a subclass can have added some there, should we not?
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.
applyFolding is a private method. Subclasses can't have added something here. Or not?
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.
Ah, I think I got your point here now :-)
@@ -238,7 +238,7 @@ private void updateAnnotation(List<Annotation> modifications, List<FoldingAnnota | |||
final var newPos = new Position(startOffset, endOffset - startOffset); | |||
if (!existing.isEmpty()) { | |||
FoldingAnnotation existingAnnotation = existing.remove(existing.size() - 1); | |||
updateAnnotations(existingAnnotation, newPos, modifications, deletions); | |||
updateAnnotations(existingAnnotation, newPos, deletions); |
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.
updateAnnotations(existingAnnotation, newPos, deletions); | |
updateAnnotations(existingAnnotation, newPos, modifications, deletions); |
@@ -139,7 +139,7 @@ public void reconcile(IRegion subRegion) { | |||
private void applyFolding(List<FoldingRange> ranges) { | |||
// these are what are passed off to the annotation model to | |||
// actually create and maintain the annotations | |||
final var modifications = new ArrayList<Annotation>(); | |||
final var modifications = new ArrayList<Annotation>(); // not used anymore |
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.
final var modifications = new ArrayList<Annotation>(); // not used anymore | |
final var modifications = new ArrayList<Annotation>(); // not used anymore, can be removed later with the deprecated updateAnnotations method |
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.
Thanks a lot!
@rubenporras thank you for quick review! |
The method
ProjectionAnnotationModel.modifyAnnotations(Annotation[], Map<? extends Annotation, ? extends Position>, Annotation[]) does not consider Position changes in any cases. On large annotations the positions won't get updated properly which leads to removed folding annotations.
fixes #934