-
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.
Issue 1793: Language Server Protocol: ShowMessage Notification feature (
#3124) Added a ShowMessageProcessor and a ShowMessageMessager classes to process incoming `window/showMessage` notification and display a notification in `float` mode in the UI if the message type is `error` or `warning`, in the events panel otherwise. Note that the notification type for `error` messages is incorrectly set to `Log` because of a bug in the typefox dependency: `io.typefox.lsapi.MessageType#Log` has the value `1` instead of `4`. This issue depends on #3113 (Add a 'warning' state for the notifications) To test the pull request, please follow the instructions on #3123 to run the 'test-lang' server. Once in the workspace, create a project, add a `foo.test` file (the Language Server support for the 'test-lang' will be activated), then type the following line > window/showMessage:error: a message and wait for the editor to save the changes. This will trigger a `window/showMessage` notification from the 'test-lang' server in the Che UI. Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
- Loading branch information
Showing
8 changed files
with
187 additions
and
18 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
58 changes: 58 additions & 0 deletions
58
.../src/main/java/org/eclipse/che/plugin/languageserver/ide/editor/ShowMessageProcessor.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,58 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2016 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.editor; | ||
|
||
import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE; | ||
|
||
import org.eclipse.che.ide.api.notification.NotificationManager; | ||
import org.eclipse.che.ide.api.notification.StatusNotification; | ||
import org.eclipse.che.ide.util.loging.Log; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.Singleton; | ||
|
||
import io.typefox.lsapi.MessageParams; | ||
|
||
/** | ||
* A processor for incoming <code>window/showMessage</code> notifications sent | ||
* by a language server. | ||
* | ||
* @author xcoulon | ||
*/ | ||
@Singleton | ||
public class ShowMessageProcessor { | ||
|
||
private final NotificationManager notificationManager; | ||
|
||
@Inject | ||
public ShowMessageProcessor(final NotificationManager notificationManager) { | ||
this.notificationManager = notificationManager; | ||
} | ||
|
||
public void processNotification(final MessageParams messageParams) { | ||
Log.debug(getClass(), "Received a 'ShowMessage' message: " + messageParams.getMessage()); | ||
switch(messageParams.getType()) { | ||
case Error: | ||
this.notificationManager.notify(messageParams.getMessage(), StatusNotification.Status.FAIL, FLOAT_MODE); | ||
break; | ||
case Warning: | ||
this.notificationManager.notify(messageParams.getMessage(), StatusNotification.Status.WARNING, FLOAT_MODE); | ||
break; | ||
case Info: | ||
case Log: | ||
default: | ||
this.notificationManager.notify(messageParams.getMessage(), StatusNotification.Status.SUCCESS, FLOAT_MODE); | ||
break; | ||
} | ||
} | ||
|
||
} |
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
68 changes: 68 additions & 0 deletions
68
...erver/src/main/java/org/eclipse/che/api/languageserver/messager/ShowMessageMessenger.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,68 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2016 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.languageserver.messager; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.annotation.PreDestroy; | ||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
import javax.websocket.EncodeException; | ||
|
||
import org.eclipse.che.api.core.notification.EventService; | ||
import org.eclipse.che.api.core.notification.EventSubscriber; | ||
import org.everrest.websockets.WSConnectionContext; | ||
import org.everrest.websockets.message.ChannelBroadcastMessage; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.google.gson.Gson; | ||
|
||
import io.typefox.lsapi.MessageParams; | ||
|
||
/** | ||
* {@link EventSubscriber} for incoming <code>window/showMessage</code> notifications. | ||
* @author xcoulon | ||
*/ | ||
@Singleton | ||
public class ShowMessageMessenger implements EventSubscriber<MessageParams> { | ||
|
||
private final static Logger LOG = LoggerFactory.getLogger(ShowMessageMessenger.class); | ||
|
||
private final EventService eventService; | ||
|
||
@Inject | ||
public ShowMessageMessenger(EventService eventService) { | ||
this.eventService = eventService; | ||
} | ||
|
||
public void onEvent(final MessageParams event) { | ||
try { | ||
final ChannelBroadcastMessage bm = new ChannelBroadcastMessage(); | ||
bm.setChannel("languageserver/window/showMessage"); | ||
bm.setBody(new Gson().toJson(event)); | ||
WSConnectionContext.sendMessage(bm); | ||
} catch (EncodeException | IOException e) { | ||
LOG.error(e.getMessage(), e); | ||
} | ||
} | ||
|
||
@PostConstruct | ||
public void subscribe() { | ||
eventService.subscribe(this); | ||
} | ||
|
||
@PreDestroy | ||
public void unsubscribe() { | ||
eventService.unsubscribe(this); | ||
} | ||
} |
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