From 0beab275245e24b4144c306a2a66ed5dbc79c1cd Mon Sep 17 00:00:00 2001 From: "G. Hentschke" <123444711+ghentschke@users.noreply.github.com> Date: Mon, 4 Mar 2024 12:00:06 +0100 Subject: [PATCH] [#934] fix removed folding annotations on document change The method ProjectionAnnotationModel.modifyAnnotations(Annotation[], Map, 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. --- org.eclipse.lsp4e/META-INF/MANIFEST.MF | 2 +- org.eclipse.lsp4e/pom.xml | 2 +- .../LSPFoldingReconcilingStrategy.java | 32 ++++++++++++++----- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/org.eclipse.lsp4e/META-INF/MANIFEST.MF b/org.eclipse.lsp4e/META-INF/MANIFEST.MF index 5826694f7..9462bedbd 100644 --- a/org.eclipse.lsp4e/META-INF/MANIFEST.MF +++ b/org.eclipse.lsp4e/META-INF/MANIFEST.MF @@ -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", diff --git a/org.eclipse.lsp4e/pom.xml b/org.eclipse.lsp4e/pom.xml index 7a622805f..cd56c3ad6 100644 --- a/org.eclipse.lsp4e/pom.xml +++ b/org.eclipse.lsp4e/pom.xml @@ -7,7 +7,7 @@ org.eclipse.lsp4e eclipse-plugin - 0.18.5-SNAPSHOT + 0.18.6-SNAPSHOT diff --git a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/folding/LSPFoldingReconcilingStrategy.java b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/folding/LSPFoldingReconcilingStrategy.java index 2605c36b3..f438474a1 100644 --- a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/folding/LSPFoldingReconcilingStrategy.java +++ b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/folding/LSPFoldingReconcilingStrategy.java @@ -141,7 +141,7 @@ public void reconcile(IRegion subRegion) { private void applyFolding(List ranges) { // these are what are passed off to the annotation model to // actually create and maintain the annotations - final var modifications = new ArrayList(); + final var modifications = new ArrayList(); // not used anymore, can be removed later with the deprecated updateAnnotations method final var deletions = new ArrayList(); final var existing = new ArrayList(); final var additions = new HashMap(); @@ -255,13 +255,10 @@ private void updateAnnotation(List modifications, List modifications, - List deletions) { + protected void updateAnnotations(Annotation existingAnnotation, Position newPos, List deletions) { if (existingAnnotation instanceof FoldingAnnotation foldingAnnotation) { // if a new position can be calculated then update the position of // the annotation, @@ -271,9 +268,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); + theProjectionAnnotationModel.modifyAnnotationPosition(foldingAnnotation, newPos); } } else { deletions.add(foldingAnnotation); @@ -281,6 +276,27 @@ protected void updateAnnotations(Annotation existingAnnotation, Position newPos, } } + /** + * 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 modifications, + List deletions) { + updateAnnotations(existingAnnotation, newPos, deletions); + } + /** *

* Searches the given {@link DirtyRegion} for annotations that now have a length