eclipse / lsp4e

Language Server Protocol support in Eclipse IDE
Eclipse Public License 2.0
65 stars 54 forks source link

Add a protected method for easy configuration of retrieval of ConfigurationItem #1054

Closed rubenporras closed 2 months ago

rubenporras commented 2 months ago

Configuration Items

rubenporras commented 2 months ago

Hi @sebthom ,

I could not find a way to override the method CompletableFuture<List<@Nullable Object>> configuration(ConfigurationParams configurationParams) after the new annotations, as the definition in LanguageClientImpl and LanguageClient do not have the same annotations.

To me this is a bug in the JDT, but the new protected method is in any case a better API for subclasses than the previous one.

What do you think of this PR?

sebthom commented 2 months ago

Hi @rubenporras I don't understand why you can't find a way to override it. It seems to work fine for me:

package org.haxe4e.langserver;

import java.util.List;
import java.util.concurrent.CompletableFuture;

import org.eclipse.jdt.annotation.*;
import org.eclipse.lsp4e.LanguageClientImpl;
import org.eclipse.lsp4j.*;
import org.haxe4e.util.TreeBuilder;

@SuppressWarnings("restriction") // https://bugs.eclipse.org/bugs/show_bug.cgi?id=536215
public final class HaxeLangServerClientImpl extends LanguageClientImpl implements HaxeLangServerClient {

   private volatile boolean isInitTriggered = false;

   @Override
   public CompletableFuture<List<@Nullable Object>> configuration(final ConfigurationParams configurationParams) {
      return super.configuration(configurationParams);
   }

   @Override
   public @NonNullByDefault({}) CompletableFuture<Void> registerCapability(final RegistrationParams params) {
      if (!isInitTriggered) {
         // workaround for https://github.com/vshaxe/vshaxe/issues/501
         final var event = new DidChangeConfigurationParams(new TreeBuilder<String>() //
            .put("haxe", new TreeBuilder<String>() //
               .getMap() //
            ).getMap());

         getLanguageServer().getWorkspaceService().didChangeConfiguration(event);
         isInitTriggered = true;
      }

      return super.registerCapability(params);
   }
}

What is the error or warning you are seeing?

rubenporras commented 2 months ago

Hi @sebthom,

I do not know why, but changing the configuration item org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations from disabled to enabled and restarting eclipse seems to solve the problem. I have tried changing the configuration yesterday already but it looks like the build that is triggered afterwards is not enough, and a restart is needed.

Does it makes sense to you?

sebthom commented 2 months ago

do you still have the issue now that you merged the no-npe 1.0.4 version? I made a change to the EEA of LanguageClientImpl at https://github.com/vegardit/no-npe/commit/ec54909964f93ac9284383ae4ad34cfe731d1f29 which might solve the issue.

rubenporras commented 2 months ago

The problem is solved for me now. Thanks.

sebthom commented 2 months ago

Nice!