Skip to content

Commit e842623

Browse files
authored
Fix ambiguous Either type when parsing unresolved code action (#485)
Fixes #484 Signed-off-by: Vladimir Piskarev <[email protected]>
1 parent 7f38e97 commit e842623

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/adapters/CodeActionResponseAdapter.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import com.google.gson.Gson;
2525
import com.google.gson.JsonElement;
26-
import com.google.gson.JsonObject;
2726
import com.google.gson.JsonPrimitive;
2827
import com.google.gson.TypeAdapter;
2928
import com.google.gson.TypeAdapterFactory;
@@ -38,7 +37,7 @@ public class CodeActionResponseAdapter implements TypeAdapterFactory {
3837
@Override
3938
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
4039
Predicate<JsonElement> leftChecker = new PropertyChecker("command", JsonPrimitive.class);
41-
Predicate<JsonElement> rightChecker = new PropertyChecker("edit").or(new PropertyChecker("command", JsonObject.class));
40+
Predicate<JsonElement> rightChecker = new PropertyChecker("title");
4241
TypeAdapter<Either<Command, CodeAction>> elementTypeAdapter = new EitherTypeAdapter<>(gson,
4342
ELEMENT_TYPE, leftChecker, rightChecker);
4443
return (TypeAdapter<T>) new CollectionTypeAdapter<>(gson, ELEMENT_TYPE.getType(), elementTypeAdapter, ArrayList::new);

org.eclipse.lsp4j/src/test/java/org/eclipse/lsp4j/test/services/JsonParseTest.xtend

+28
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,34 @@ class JsonParseTest {
488488
])
489489
}
490490

491+
@Test
492+
def void testCodeActionResponse3() {
493+
jsonHandler.methodProvider = [ id |
494+
switch id {
495+
case '12': MessageMethods.DOC_CODE_ACTION
496+
}
497+
]
498+
'''
499+
{
500+
"jsonrpc": "2.0",
501+
"id": "12",
502+
"result": [
503+
{
504+
"title": "fixme"
505+
}
506+
]
507+
}
508+
'''.assertParse(new ResponseMessage => [
509+
jsonrpc = "2.0"
510+
id = "12"
511+
result = newArrayList(Either.forRight(
512+
new CodeAction => [
513+
title = "fixme"
514+
]
515+
))
516+
])
517+
}
518+
491519
@Test
492520
def void testPrepareRenameResponse1() {
493521
jsonHandler.methodProvider = [ id |

0 commit comments

Comments
 (0)