@@ -64,7 +64,7 @@ public class DynamicCapabilities {
6464
6565 private final LanguageClient client ;
6666 private final Executor exec ;
67- private final Supplier <CompletableFuture <Void >> noop ;
67+ private final Supplier <CompletableFuture <Boolean >> falsy ;
6868 private final Collection <AbstractDynamicCapability <?>> supportedCapabilities ;
6969
7070 // Set of capabilities that should bre registered statically instead of dynamically
@@ -82,7 +82,7 @@ public class DynamicCapabilities {
8282 public DynamicCapabilities (LanguageClient client , Executor exec , List <AbstractDynamicCapability <?>> supportedCapabilities , ClientCapabilities clientCapabilities ) {
8383 this .client = client ;
8484 this .exec = exec ;
85- this .noop = () -> CompletableFutureUtils .completedFuture (null , exec );
85+ this .falsy = () -> CompletableFutureUtils .completedFuture (false , exec );
8686 this .supportedCapabilities = List .copyOf (supportedCapabilities );
8787
8888 // Check which capabilities to register statically
@@ -123,7 +123,7 @@ public CompletableFuture<Void> updateCapabilities(Collection<ILanguageContributi
123123 .thenAccept (_l -> {}); // List<Void> -> Void
124124 }
125125
126- private <T > CompletableFuture <Void > updateRegistration (Pair <AbstractDynamicCapability <T >, @ Nullable Registration > entry ) {
126+ private <T > CompletableFuture <Boolean > updateRegistration (Pair <AbstractDynamicCapability <T >, @ Nullable Registration > entry ) {
127127 var cap = entry .getLeft ();
128128 var registration = entry .getRight ();
129129 var method = cap .methodName ();
@@ -136,13 +136,13 @@ private <T> CompletableFuture<Void> updateRegistration(Pair<AbstractDynamicCapab
136136 return unregister (existingRegistration );
137137 }
138138 // nothing more to do
139- return noop .get ();
139+ return falsy .get ();
140140 }
141141
142142 if (existingRegistration != null ) {
143143 if (Objects .deepEquals (registration .getRegisterOptions (), existingRegistration .getRegisterOptions ())) {
144144 logger .trace ("Options for {} did not change since last registration: {}" , method , registration .getRegisterOptions ());
145- return noop .get ();
145+ return falsy .get ();
146146 }
147147 logger .trace ("Options for {} changed since the previous registration; remove before adding again" , method );
148148 return changeOptions (registration , existingRegistration );
@@ -152,39 +152,50 @@ private <T> CompletableFuture<Void> updateRegistration(Pair<AbstractDynamicCapab
152152 return register (registration );
153153 }
154154
155- private <T > CompletableFuture <Void > unregister (Registration reg ) {
155+ private <T > CompletableFuture <Boolean > unregister (Registration reg ) {
156156 // If our administration contains exactly this registration, remove it and inform the client
157157 if (!currentRegistrations .remove (reg .getMethod (), reg )) {
158- return noop .get ();
158+ return falsy .get ();
159159 }
160160
161161 return client .unregisterCapability (new UnregistrationParams (List .of (new Unregistration (reg .getId (), reg .getMethod ()))))
162- .exceptionally (t -> {
162+ .handle ((_v , t ) -> {
163+ if (t == null ) {
164+ return true ;
165+ }
163166 logger .error ("Exception while unregistering {}" , reg .getMethod (), t );
164167 // Unregistration failed; put this back in our administration
165168 currentRegistrations .putIfAbsent (reg .getMethod (), reg );
166- return null ;
169+ return false ;
167170 });
168171 }
169172
170- private <T > CompletableFuture <Void > register (Registration reg ) {
173+ private <T > CompletableFuture <Boolean > register (Registration reg ) {
171174 // If our administration contains no registration, inform the client
172175 if (currentRegistrations .putIfAbsent (reg .getMethod (), reg ) != null ) {
173- return noop .get ();
176+ return falsy .get ();
174177 }
175178
176179 return client .registerCapability (new RegistrationParams (List .of (reg )))
177- .exceptionally (t -> {
180+ .handle ((_v , t ) -> {
181+ if (t == null ) {
182+ return true ;
183+ }
178184 logger .error ("Exception while registering {}" , reg .getMethod (), t );
179185 // Registration failed; remove this from our administration
180186 currentRegistrations .remove (reg .getMethod (), reg );
181- return null ;
187+ return false ;
182188 });
183189 }
184190
185- private <T > CompletableFuture <Void > changeOptions (Registration newRegistration , Registration existingRegistration ) {
191+ private <T > CompletableFuture <Boolean > changeOptions (Registration newRegistration , Registration existingRegistration ) {
186192 return unregister (existingRegistration )
187- .thenCompose (_v -> register (newRegistration ));
193+ .thenCompose (b -> {
194+ if (!b ) {
195+ return falsy .get ();
196+ }
197+ return register (newRegistration );
198+ });
188199 }
189200
190201 private <T > CompletableFuture <Pair <AbstractDynamicCapability <T >, @ Nullable Registration >> tryBuildRegistration (AbstractDynamicCapability <T > cap , Collection <ILanguageContributions > contribs ) {
0 commit comments