-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1794 implement 'ShowMessageRequest'
Signed-off-by: Yevhen Vydolob <evidolob@codenvy.com>
- Loading branch information
Yevhen Vydolob
committed
Jul 20, 2017
1 parent
3c2aa13
commit a8d3206
Showing
20 changed files
with
778 additions
and
65 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
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
81 changes: 81 additions & 0 deletions
81
...java/org/eclipse/che/api/core/jsonrpc/commons/reception/PromiseConfigurationOneToOne.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,81 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2017 Codenvy, S.A. | ||
* 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: | ||
* Codenvy, S.A. - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.che.api.core.jsonrpc.commons.reception; | ||
|
||
import org.eclipse.che.api.core.jsonrpc.commons.JsonRpcPromise; | ||
import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerManager; | ||
import org.slf4j.Logger; | ||
|
||
import java.util.function.BiFunction; | ||
import java.util.function.Function; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
/** | ||
* Function configurator to define a function to be applied when we | ||
* handle incoming JSON RPC request with params object that is | ||
* represented by a single object while the result of a function is | ||
* also a single object. | ||
* | ||
* @param <P> | ||
* type of params object | ||
* @param <R> | ||
* type of result object | ||
*/ | ||
public class PromiseConfigurationOneToOne<P, R> { | ||
private final static Logger LOGGER = getLogger(PromiseConfigurationOneToOne.class); | ||
|
||
private final RequestHandlerManager handlerManager; | ||
|
||
private final String method; | ||
private final Class<P> pClass; | ||
private final Class<R> rClass; | ||
|
||
PromiseConfigurationOneToOne(RequestHandlerManager handlerManager, String method, Class<P> pClass, Class<R> rClass) { | ||
this.handlerManager = handlerManager; | ||
|
||
this.method = method; | ||
this.pClass = pClass; | ||
this.rClass = rClass; | ||
} | ||
|
||
/** | ||
* Define a binary function to be applied | ||
* | ||
* @param function | ||
* function | ||
*/ | ||
public void withPromiseBiFunction(BiFunction<String, P, JsonRpcPromise<R>> function) { | ||
checkNotNull(function, "Request promise must not be null"); | ||
|
||
LOGGER.debug("Configuring incoming request binary: " + | ||
"function for method: " + method + ", " + | ||
"params object class: " + pClass + ", " + | ||
"result object class: " + rClass); | ||
|
||
handlerManager.registerOneToPromiseOne(method, pClass, rClass, function); | ||
|
||
|
||
} | ||
|
||
|
||
/** | ||
* Define a function to be applied | ||
* | ||
* @param function | ||
* function | ||
*/ | ||
public void withPromise(Function<P, JsonRpcPromise<R>> function) { | ||
withPromiseBiFunction((s, p) -> function.apply(p)); | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
...in/java/org/eclipse/che/plugin/languageserver/ide/window/ShowMessageRequestProcessor.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,47 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2017 Codenvy, S.A. | ||
* 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: | ||
* Codenvy, S.A. - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.che.plugin.languageserver.ide.window; | ||
|
||
import org.eclipse.che.api.core.jsonrpc.commons.JsonRpcPromise; | ||
import org.eclipse.che.plugin.languageserver.ide.window.dialog.MessageDialogPresenter; | ||
import org.eclipse.lsp4j.MessageActionItem; | ||
import org.eclipse.lsp4j.ShowMessageRequestParams; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Provider; | ||
import javax.inject.Singleton; | ||
|
||
/** | ||
** A processor for incoming <code>window/showMessageRequest</code> requests sent | ||
* by a language server. | ||
*/ | ||
@Singleton | ||
public class ShowMessageRequestProcessor { | ||
|
||
private final Provider<MessageDialogPresenter> provider; | ||
|
||
@Inject | ||
public ShowMessageRequestProcessor(Provider<MessageDialogPresenter> provider) { | ||
this.provider = provider; | ||
} | ||
|
||
public JsonRpcPromise<MessageActionItem> processNotificationRequest(ShowMessageRequestParams params) { | ||
JsonRpcPromise<MessageActionItem> result = new JsonRpcPromise<>(); | ||
|
||
MessageDialogPresenter dialogPresenter = provider.get(); | ||
dialogPresenter.show(params.getMessage(), params.getType().toString(), params.getActions(), actionItem -> { | ||
result.getSuccessConsumer().ifPresent(consumer -> consumer.accept("ws-agent", actionItem)); | ||
}); | ||
|
||
return result; | ||
} | ||
} |
Oops, something went wrong.