Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
Signed-off-by: sheche <[email protected]>
  • Loading branch information
jdneo committed Aug 11, 2022
1 parent 2ae628a commit 652639b
Showing 1 changed file with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

package org.eclipse.jdt.ls.core.internal.handlers;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
Expand Down Expand Up @@ -43,8 +42,6 @@
import org.eclipse.lsp4j.jsonrpc.messages.ResponseError;
import org.eclipse.lsp4j.jsonrpc.messages.ResponseErrorCode;

import com.google.common.base.Objects;

public class WorkspaceExecuteCommandHandler implements IRegistryEventListener {

private WorkspaceExecuteCommandHandler() {}
Expand Down Expand Up @@ -138,10 +135,16 @@ public static String createId(IConfigurationElement element) {
private Map<String, DelegateCommandHandlerDescriptor> fgContributedCommandHandlers;

private synchronized Collection<DelegateCommandHandlerDescriptor> getDelegateCommandHandlerDescriptors() {
if (fgContributedCommandHandlers == null) {
return getDelegateCommandHandlerDescriptors(false);
}

private synchronized Collection<DelegateCommandHandlerDescriptor> getDelegateCommandHandlerDescriptors(boolean force) {
if (fgContributedCommandHandlers == null || force) {

IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_POINT_ID);
fgContributedCommandHandlers = Stream.of(elements).collect(Collectors.toMap(DelegateCommandHandlerDescriptor::createId, DelegateCommandHandlerDescriptor::new, (value1, value2) -> value2));

Platform.getExtensionRegistry().removeListener(this);
Platform.getExtensionRegistry().addListener(this);
}

Expand Down Expand Up @@ -196,15 +199,9 @@ public Object executeCommand(ExecuteCommandParams params, IProgressMonitor monit
Collection<DelegateCommandHandlerDescriptor> candidates = handlers.stream().filter(desc -> desc.getAllCommands().contains(params.getCommand())).collect(Collectors.toSet()); //no cancellation here but it's super fast so it's ok.

if (candidates.isEmpty()) {
// fetch from the extension registry again in case that the local cache is out-of-sync.
IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_POINT_ID);
candidates = Stream.of(elements).filter(element -> {
IConfigurationElement[] commands = element.getChildren(COMMAND);
return Arrays.stream(commands).anyMatch(child -> {
String commandId = child.getAttribute(ID);
return Objects.equal(commandId, params.getCommand());
});
}).map(DelegateCommandHandlerDescriptor::new).collect(Collectors.toSet());
// re-fetch from the extension registry again in case that the local cache is out-of-sync.
handlers = getDelegateCommandHandlerDescriptors(true);
candidates = handlers.stream().filter(desc -> desc.getAllCommands().contains(params.getCommand())).collect(Collectors.toSet());
}

if (monitor.isCanceled()) {
Expand Down

0 comments on commit 652639b

Please sign in to comment.