forked from eclipse-che/che
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 8721 - Update Libraries, etc. based on JDT notifications eclips…
…e-che#8721 Draft - DO NOT MERGE Signed-off-by: Victor Rubezhny <vrubezhny@redhat.com>
- Loading branch information
Showing
10 changed files
with
329 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...va/org/eclipse/che/plugin/java/languageserver/ExecuteClientCommandJsonRpcTransmitter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright (c) 2012-2018 Red Hat, Inc. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.plugin.java.languageserver; | ||
|
||
import static org.eclipse.che.ide.ext.java.shared.Constants.EXECUTE_CLIENT_COMMAND; | ||
|
||
import java.util.Set; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.CopyOnWriteArraySet; | ||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerConfigurator; | ||
import org.eclipse.che.api.core.jsonrpc.commons.RequestTransmitter; | ||
import org.eclipse.che.api.core.notification.EventService; | ||
import org.eclipse.che.api.languageserver.server.dto.DtoServerImpls; | ||
import org.eclipse.che.api.languageserver.server.dto.DtoServerImpls.ExecuteCommandParamsDto; | ||
import org.eclipse.lsp4j.ExecuteCommandParams; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** Transmits 'workspace/executeClientCommand' over the JSON-RPC */ | ||
@Singleton | ||
public class ExecuteClientCommandJsonRpcTransmitter { | ||
private final Set<String> endpointIds = new CopyOnWriteArraySet<>(); | ||
|
||
private final RequestTransmitter requestTransmitter; | ||
|
||
private static final Logger LOG = | ||
LoggerFactory.getLogger(ExecuteClientCommandJsonRpcTransmitter.class); | ||
|
||
@Inject | ||
public ExecuteClientCommandJsonRpcTransmitter(RequestTransmitter requestTransmitter) { | ||
this.requestTransmitter = requestTransmitter; | ||
} | ||
|
||
@Inject | ||
private void subscribe(EventService eventService, RequestTransmitter requestTransmitter) { | ||
LOG.info("subscribe() is invoked"); | ||
eventService.subscribe( | ||
event -> | ||
endpointIds.forEach( | ||
endpointId -> { | ||
LOG.info("subscribe() is invoked for endpointID " + endpointId); | ||
requestTransmitter | ||
.newRequest() | ||
.endpointId(endpointId) | ||
.methodName(EXECUTE_CLIENT_COMMAND) | ||
.paramsAsDto(new ExecuteCommandParamsDto(event)) | ||
.sendAndSkipResult(); | ||
}), | ||
ExecuteCommandParams.class); | ||
} | ||
|
||
@Inject | ||
private void configureSubscribeHandler(RequestHandlerConfigurator requestHandler) { | ||
LOG.info("configureSubscribeHandler() is invoked"); | ||
requestHandler | ||
.newConfiguration() | ||
.methodName("workspace/executeClientCommand/subscribe") | ||
.noParams() | ||
.noResult() | ||
.withConsumer(endpointIds::add); | ||
} | ||
|
||
@Inject | ||
private void configureUnSubscribeHandler(RequestHandlerConfigurator requestHandler) { | ||
LOG.info("configureUnSubscribeHandler() is invoked"); | ||
requestHandler | ||
.newConfiguration() | ||
.methodName("workspace/executeClientCommand/unsubscribe") | ||
.noParams() | ||
.noResult() | ||
.withConsumer(endpointIds::remove); | ||
} | ||
|
||
public CompletableFuture<Object> executeClientCommand(ExecuteCommandParams requestParams) { | ||
LOG.info("executeClientCommand() is invoked"); | ||
|
||
ExecuteCommandParamsDto paramsDto = | ||
(ExecuteCommandParamsDto) DtoServerImpls.makeDto(requestParams); | ||
|
||
CompletableFuture<Object> result = new CompletableFuture<>(); | ||
for (String endpointId : endpointIds) { | ||
requestTransmitter | ||
.newRequest() | ||
.endpointId(endpointId) | ||
.methodName("workspace/executeClientCommand") | ||
.paramsAsDto(paramsDto) | ||
.sendAndSkipResult(); | ||
} | ||
result.complete(null); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...pse/che/plugin/languageserver/ide/navigation/workspace/UpdateProjectClasspathHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (c) 2012-2018 Red Hat, Inc. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.plugin.languageserver.ide.navigation.workspace; | ||
|
||
import static java.util.stream.Collectors.toSet; | ||
|
||
import com.google.inject.Inject; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import javax.inject.Singleton; | ||
import org.eclipse.che.api.languageserver.shared.model.ExtendedExecuteCommandParams; | ||
import org.eclipse.che.ide.api.app.AppContext; | ||
import org.eclipse.che.ide.util.loging.Log; | ||
|
||
@Singleton | ||
public class UpdateProjectClasspathHandler { | ||
|
||
private final AppContext appContext; | ||
|
||
@Inject | ||
public UpdateProjectClasspathHandler(AppContext appContext) { | ||
this.appContext = appContext; | ||
} | ||
|
||
/** | ||
* Updates the tree of projects which were modified. | ||
* | ||
* @param dto describes a projects which were modified | ||
*/ | ||
public void handleUpdate(ExtendedExecuteCommandParams params) { | ||
List<Object> updatedProjects = params.getArguments(); | ||
Set<String> projectToRefresh = computeUniqueHiLevelProjects(updatedProjects); | ||
Log.info( | ||
getClass(), | ||
"Updating projects..." | ||
+ (projectToRefresh == null ? " null " : "" + projectToRefresh.size()) | ||
+ " from " | ||
+ (updatedProjects == null ? " null " : "" + updatedProjects.size())); | ||
|
||
for (final String path : projectToRefresh) { | ||
Log.info(getClass(), "Updating project: " + path); | ||
|
||
appContext | ||
.getWorkspaceRoot() | ||
.getContainer(path) | ||
.then( | ||
container -> { | ||
Log.info(UpdateProjectClasspathHandler.class, "Updating project: " + path); | ||
if (container.isPresent()) { | ||
container.get().synchronize(); | ||
} | ||
}) | ||
.catchError( | ||
error -> { | ||
Log.error(UpdateProjectClasspathHandler.class, error.getCause()); | ||
}); | ||
} | ||
Log.info(getClass(), "Updating projects finished"); | ||
} | ||
|
||
private Set<String> computeUniqueHiLevelProjects(List<Object> updatedProjects) { | ||
return updatedProjects | ||
.stream() | ||
.filter(Objects::nonNull) | ||
.map(each -> each.toString()) | ||
// .filter(each -> shouldBeUpdated(updatedProjects, each)) | ||
.collect(toSet()); | ||
} | ||
|
||
private boolean shouldBeUpdated(List<Object> updatedProjects, String project) { | ||
for (Object each : updatedProjects) { | ||
if (!project.equals(each) && project.startsWith(String.valueOf(each))) { | ||
Log.info(getClass(), "shouldBeUpdated(" + project + ") == " + false); | ||
return false; | ||
} | ||
} | ||
Log.info(getClass(), "shouldBeUpdated(" + project + ") == " + true); | ||
return true; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...java/org/eclipse/che/plugin/languageserver/ide/service/ExecuteClientCommandProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (c) 2012-2018 Red Hat, Inc. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.plugin.languageserver.ide.service; | ||
|
||
import static org.eclipse.che.jdt.ls.extension.api.Commands.CLIENT_UPDATE_PROJECTS_CLASSPATH; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.Singleton; | ||
import org.eclipse.che.api.languageserver.shared.model.ExtendedExecuteCommandParams; | ||
import org.eclipse.che.ide.util.loging.Log; | ||
import org.eclipse.che.plugin.languageserver.ide.navigation.workspace.UpdateProjectClasspathHandler; | ||
|
||
/** | ||
* A processor for incoming <code>workspace/ClasspathChanged</code> notifications sent by a language | ||
* server. | ||
* | ||
* @author V. Rubezhny | ||
*/ | ||
@Singleton | ||
public class ExecuteClientCommandProcessor { | ||
|
||
private UpdateProjectClasspathHandler updateClasspathHandler; | ||
|
||
@Inject | ||
public ExecuteClientCommandProcessor(UpdateProjectClasspathHandler updateClasspathHandler) { | ||
this.updateClasspathHandler = updateClasspathHandler; | ||
} | ||
|
||
public void execute(ExtendedExecuteCommandParams params) { | ||
Log.info( | ||
getClass(), | ||
"workspace/executeClientCommand " + (params == null ? "-empty-" : params.getCommand())); | ||
if (CLIENT_UPDATE_PROJECTS_CLASSPATH.equals(params.getCommand())) { | ||
updateClasspathHandler.handleUpdate(params); | ||
} | ||
} | ||
} |
Oops, something went wrong.