Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle project updated notifications from jdt.ls #9983

Merged
merged 3 commits into from
Jun 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,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