Skip to content

Commit

Permalink
[#934] fix removed folding annotations on document change
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ghentschke committed Mar 4, 2024
1 parent 5e04ccf commit 0beab27
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion org.eclipse.lsp4e/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Language Server Protocol client for Eclipse IDE (Incubation)
Bundle-SymbolicName: org.eclipse.lsp4e;singleton:=true
Bundle-Version: 0.18.5.qualifier
Bundle-Version: 0.18.6.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-17
Require-Bundle: org.eclipse.core.runtime;bundle-version="3.12.0",
org.eclipse.equinox.common;bundle-version="3.8.0",
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.lsp4e/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</parent>
<artifactId>org.eclipse.lsp4e</artifactId>
<packaging>eclipse-plugin</packaging>
<version>0.18.5-SNAPSHOT</version>
<version>0.18.6-SNAPSHOT</version>

<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,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, can be removed later with the deprecated updateAnnotations method
final var deletions = new ArrayList<FoldingAnnotation>();
final var existing = new ArrayList<FoldingAnnotation>();
final var additions = new HashMap<Annotation, Position>();
Expand Down Expand Up @@ -255,13 +255,10 @@ private void updateAnnotation(List<Annotation> modifications, List<FoldingAnnota
* @param newPos
* the new position that caused the annotations need for updating and
* null otherwise.
* @param modifications
* the list of annotations to be modified
* @param deletions
* the list of annotations to be deleted
*/
protected void updateAnnotations(Annotation existingAnnotation, Position newPos, List<Annotation> modifications,
List<FoldingAnnotation> deletions) {
protected void updateAnnotations(Annotation existingAnnotation, Position newPos, List<FoldingAnnotation> deletions) {
if (existingAnnotation instanceof FoldingAnnotation foldingAnnotation) {
// if a new position can be calculated then update the position of
// the annotation,
Expand All @@ -271,16 +268,35 @@ 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);
theProjectionAnnotationModel.modifyAnnotationPosition(foldingAnnotation, newPos);
}
} else {
deletions.add(foldingAnnotation);
}
}
}

/**
* Update annotations.
*
* @param existingAnnotation
* the existing annotations that need to be updated based on the
* given dirtied IndexRegion
* @param newPos
* the new position that caused the annotations need for updating and
* null otherwise.
* @param modifications
* the list of annotations to be modified - not used anymore, that's why this method is deprecated.
* @param deletions
* the list of annotations to be deleted
* @deprecated use {@link LSPFoldingReconcilingStrategy#updateAnnotations(Annotation, Position, List)}
*/
@Deprecated(since = "0.18.6", forRemoval = true)
protected void updateAnnotations(Annotation existingAnnotation, Position newPos, List<Annotation> modifications,
List<FoldingAnnotation> deletions) {
updateAnnotations(existingAnnotation, newPos, deletions);
}

/**
* <p>
* Searches the given {@link DirtyRegion} for annotations that now have a length
Expand Down

0 comments on commit 0beab27

Please sign in to comment.