Skip to content

Commit

Permalink
Handle project updated notifications from jdt.ls (#9983)
Browse files Browse the repository at this point in the history
Signed-off-by: Valeriy Svydenko <[email protected]>
  • Loading branch information
svor authored and tsmaeder committed Oct 17, 2018
1 parent a84266b commit f11a8a3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,6 @@ public void actionPerformed(ActionEvent e) {

javaLanguageExtensionServiceClient
.reImportMavenProjects(paramsDto)
.then(
updatedProjects -> {
for (final String path : updatedProjects) {
appContext
.getWorkspaceRoot()
.getContainer(path)
.then(
container -> {
if (container.isPresent()) {
container.get().synchronize();
}
});
}
// TODO update error markers in poms if needed
})
.catchError(
error -> {
notificationManager.notify(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
*/
package org.eclipse.che.plugin.java.languageserver;

import static java.util.Collections.singletonList;
import static org.eclipse.che.api.languageserver.LanguageServiceUtils.removePrefixUri;
import static org.eclipse.che.api.languageserver.util.JsonUtil.convertToJson;
import static org.eclipse.che.jdt.ls.extension.api.Commands.CLIENT_UPDATE_PROJECT;
import static org.eclipse.che.jdt.ls.extension.api.Commands.CLIENT_UPDATE_PROJECTS_CLASSPATH;

import com.google.inject.Inject;
Expand Down Expand Up @@ -122,12 +124,22 @@ public CompletableFuture<Object> executeClientCommand(ExecuteCommandParams param
}

private ExecuteCommandParams convertParams(ExecuteCommandParams params) {
if (CLIENT_UPDATE_PROJECTS_CLASSPATH.equals(params.getCommand())) {
List<Object> fixedPathList = new ArrayList<>();
for (Object uri : params.getArguments()) {
fixedPathList.add(removePrefixUri(convertToJson(uri).getAsString()));
}
params.setArguments(fixedPathList);
String command = params.getCommand();
switch (command) {
case CLIENT_UPDATE_PROJECTS_CLASSPATH:
List<Object> fixedPathList = new ArrayList<>(params.getArguments().size());
for (Object uri : params.getArguments()) {
fixedPathList.add(removePrefixUri(convertToJson(uri).getAsString()));
}
params.setArguments(fixedPathList);
break;
case CLIENT_UPDATE_PROJECT:
Object projectUri = params.getArguments().get(0);
params.setArguments(
singletonList(removePrefixUri(convertToJson(projectUri).getAsString())));
break;
default:
break;
}
return params;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
*/
package org.eclipse.che.plugin.languageserver.ide.service;

import static org.eclipse.che.jdt.ls.extension.api.Commands.CLIENT_UPDATE_PROJECT;
import static org.eclipse.che.jdt.ls.extension.api.Commands.CLIENT_UPDATE_PROJECTS_CLASSPATH;

import com.google.gwt.json.client.JSONString;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.web.bindery.event.shared.EventBus;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.project.node.ProjectClasspathChangedEvent;
import org.eclipse.lsp4j.ExecuteCommandParams;

Expand All @@ -25,24 +29,42 @@
*/
@Singleton
public class ExecuteClientCommandProcessor {
private static final String CLIENT_UPDATE_PROJECTS_CLASSPATH =
"che.jdt.ls.extension.workspace.clientUpdateProjectsClasspath";

private EventBus eventBus;
private AppContext appContext;

@Inject
public ExecuteClientCommandProcessor(EventBus eventBus) {
public ExecuteClientCommandProcessor(EventBus eventBus, AppContext appContext) {
this.eventBus = eventBus;
this.appContext = appContext;
}

public void execute(ExecuteCommandParams params) {
if (CLIENT_UPDATE_PROJECTS_CLASSPATH.equals(params.getCommand())) {
for (Object project : params.getArguments()) {
eventBus.fireEvent(new ProjectClasspathChangedEvent(stringValue(project)));
}
switch (params.getCommand()) {
case CLIENT_UPDATE_PROJECTS_CLASSPATH:
for (Object project : params.getArguments()) {
eventBus.fireEvent(new ProjectClasspathChangedEvent(stringValue(project)));
}
break;
case CLIENT_UPDATE_PROJECT:
updateProject(stringValue(params.getArguments()));
break;
default:
break;
}
}

private void updateProject(String project) {
appContext
.getWorkspaceRoot()
.getContainer(project)
.then(
container -> {
if (container.isPresent()) {
container.get().synchronize();
}
});
}

private String stringValue(Object value) {
return value instanceof JSONString ? ((JSONString) value).stringValue() : String.valueOf(value);
}
Expand Down

0 comments on commit f11a8a3

Please sign in to comment.