Skip to content
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

Merged
merged 6 commits into from
Mar 4, 2024

Conversation

ghentschke
Copy link
Contributor

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

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);
Copy link
Contributor Author

@ghentschke ghentschke Feb 28, 2024

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.

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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.

@rubenporras
Copy link
Contributor

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"?

@ghentschke
Copy link
Contributor Author

ghentschke commented Feb 29, 2024

Are we fixing a problem with ProjectionAnnotationModel.modifyAnnotations?

Not really. IMO we haven't used the proper method. And theProjectionAnnotationModel.modifyAnnotationPosition(foldingAnnotation, newPos)
does exactly what we want: update the position of a Annotation.

@rubenporras
Copy link
Contributor

Are we fixing a problem with ProjectionAnnotationModel.modifyAnnotations?

Not really. IMO we haven't used the proper method. And theProjectionAnnotationModel.modifyAnnotationPosition(foldingAnnotation, newPos) does exactly what we want: update the position of a Annotation.

I guess that you mean that call projectionAnnotationModel.modifyAnnotations(deletions.toArray(new Annotation[1]), additions, modifications.toArray(new Annotation[0])) is not the proper method. Why not?

@ghentschke
Copy link
Contributor Author

ghentschke commented Feb 29, 2024

I guess that you mean that call projectionAnnotationModel.modifyAnnotations(deletions.toArray(new Annotation[1]), additions, modifications.toArray(new Annotation[0])) is not the proper method. Why not?

That was my assumption I made after some debugging to determine why the folding annotations disappear as described in my issue #934.
Unfortunately, I had not the time to determine the root cause why the previous method does not work on large files. The theProjectionAnnotationModel.modifyAnnotationPosition(foldingAnnotation, newPos) seems to be more appropriate for what we wanted and it works as expected also on large files.

- 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(),
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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]);
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Contributor

@rubenporras rubenporras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

@ghentschke ghentschke merged commit 0beab27 into eclipse-lsp4e:master Mar 4, 2024
1 of 2 checks passed
@ghentschke
Copy link
Contributor Author

@rubenporras thank you for quick review!

@ghentschke ghentschke deleted the fix-folding branch March 4, 2024 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Folding annotations gets removed on large files while editing
3 participants