Skip to content

Commit

Permalink
Log user friendly error if client does not support _java.reloadBundle…
Browse files Browse the repository at this point in the history
…s.command

The result of `executeClientCommand` could be a map in the LSP
`ResponseError` format.
Previously this resulted in a ClassCastException which got logged:

	class com.google.gson.internal.LinkedTreeMap cannot be cast to class java.util.ArrayList (com.google.gson.internal.LinkedTreeMap

This gave users the impression that there's a bug.
This changes the logic to instead log the message returned by the
client.

In neovim for example it results in:

	Command _java.reloadBundles.command not supported on client
  • Loading branch information
mfussenegger authored and rgrunber committed Dec 9, 2022
1 parent 438e619 commit 5630738
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,19 @@ private void syncCapabilitiesToSettings() {
*/
private void synchronizeBundles() {
try {
List<String> bundlesToRefresh = (ArrayList<String>) JavaLanguageServerPlugin.getInstance()
Object commandResult = JavaLanguageServerPlugin.getInstance()
.getClientConnection().executeClientCommand("_java.reloadBundles.command");
if (bundlesToRefresh.size() > 0) {
BundleUtils.loadBundles(bundlesToRefresh);
if (commandResult instanceof List<?> list) {
List<String> bundlesToRefresh = (List<String>) commandResult;
if (bundlesToRefresh.size() > 0) {
BundleUtils.loadBundles(bundlesToRefresh);
}
} else if (commandResult instanceof Map<?, ?> m) {
String message = (String) m.get("message");
JavaLanguageServerPlugin.logError(message);
} else {
JavaLanguageServerPlugin.logError(
"Unexpected result from executeClientCommand: " + commandResult);
}
} catch (Exception e) {
JavaLanguageServerPlugin.logException(e);
Expand Down

0 comments on commit 5630738

Please sign in to comment.