Skip to content

Commit 8b31c02

Browse files
authored
Upgrade to Smithy 1.31.0 (#104)
1 parent d20c5c2 commit 8b31c02

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ publishing {
157157

158158
dependencies {
159159
implementation "org.eclipse.lsp4j:org.eclipse.lsp4j:0.14.0"
160-
implementation "software.amazon.smithy:smithy-model:[1.30.0, 2.0["
160+
implementation "software.amazon.smithy:smithy-model:[1.31.0, 2.0["
161161
implementation 'io.get-coursier:interface:1.0.4'
162162
implementation 'com.disneystreaming.smithy:smithytranslate-formatter-jvm-java-api:0.3.4'
163163

src/main/java/software/amazon/smithy/lsp/SmithyTextDocumentService.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -551,21 +551,21 @@ private Optional<Shape> getTargetShape(Shape initialShape, String token, Model m
551551
}
552552

553553
private String getHoverContentsForShape(Shape shape, Model model) {
554-
try {
555-
String serializedShape = serializeShape(shape, model);
554+
List<ValidationEvent> validationEvents = getValidationEventsForShape(shape);
555+
String serializedShape = serializeShape(shape, model);
556+
if (validationEvents.isEmpty()) {
556557
return "```smithy\n" + serializedShape + "\n```";
557-
} catch (Exception e) {
558-
List<ValidationEvent> validationEvents = getValidationEventsForShape(shape);
559-
StringBuilder contents = new StringBuilder();
560-
contents.append("Can't display shape ").append("`").append(shape.getId().toString()).append("`:");
561-
for (ValidationEvent event : validationEvents) {
562-
contents.append(System.lineSeparator()).append(event.getMessage());
563-
}
564-
if (validationEvents.isEmpty()) {
565-
contents.append(System.lineSeparator()).append(e);
566-
}
567-
return contents.toString();
568558
}
559+
StringBuilder contents = new StringBuilder();
560+
contents.append("```smithy\n");
561+
contents.append(serializedShape);
562+
contents.append("\n");
563+
contents.append("---\n");
564+
for (ValidationEvent event : validationEvents) {
565+
contents.append(event.getSeverity() + ": " + event.getMessage() + "\n");
566+
}
567+
contents.append("```");
568+
return contents.toString();
569569
}
570570

571571
private String serializeShape(Shape shape, Model model) {

src/test/java/software/amazon/smithy/lsp/SmithyTextDocumentServiceTest.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public void allowsHoverWhenThereAreUnknownTraits() throws Exception {
214214
}
215215

216216
@Test
217-
public void hoverOnBrokenShapeShowsErrorMessage() throws Exception {
217+
public void hoverOnBrokenShapeAppendsValidations() throws Exception {
218218
Path baseDir = Paths.get(getClass().getResource("ext/models").toURI());
219219
String modelFilename = "unknown-trait.smithy";
220220
Path modelFilePath = baseDir.resolve(modelFilename);
@@ -227,7 +227,10 @@ public void hoverOnBrokenShapeShowsErrorMessage() throws Exception {
227227
TextDocumentIdentifier tdi = new TextDocumentIdentifier(hs.file(modelFilename).toString());
228228
Hover hover = tds.hover(hoverParams(tdi, 10, 13)).get();
229229
MarkupContent hoverContent = hover.getContents().getRight();
230-
assertTrue(hoverContent.getValue().startsWith("Can't display shape"));
230+
assertEquals(hoverContent.getKind(),"markdown");
231+
assertTrue(hoverContent.getValue().startsWith("```smithy"));
232+
assertTrue(hoverContent.getValue().contains("structure Foo {}"));
233+
assertTrue(hoverContent.getValue().contains("WARNING: Unable to resolve trait `com.external#unknownTrait`"));
231234
}
232235
}
233236

@@ -553,9 +556,9 @@ public void hoverV1() throws Exception {
553556

554557
// Resolves via resource read.
555558
Hover readHover = tds.hover(hoverParams(mainTdi, 76, 12)).get();
556-
correctHover(mainHoverPrefix, "@http(\n method: \"PUT\"\n uri: \"/bar\"\n code: 200\n)\n@readonly\n"
557-
+ "operation MyOperation {\n input: MyOperationInput\n output: MyOperationOutput\n"
558-
+ " errors: [\n MyError\n ]\n}", readHover);
559+
assertTrue(readHover.getContents().getRight().getValue().contains("@http(\n method: \"PUT\"\n "
560+
+ "uri: \"/bar\"\n code: 200\n)\n@readonly\noperation MyOperation {\n input: "
561+
+ "MyOperationInput\n output: MyOperationOutput\n errors: [\n MyError\n ]\n}"));
559562

560563
// Does not correspond to shape.
561564
Hover noMatchHover = tds.hover(hoverParams(mainTdi, 0, 0)).get();
@@ -666,9 +669,9 @@ public void hoverV2() throws Exception {
666669

667670
// Resolves via resource read.
668671
Hover readHover = tds.hover(hoverParams(mainTdi, 78, 12)).get();
669-
correctHover(mainHoverPrefix, "@http(\n method: \"PUT\"\n uri: \"/bar\"\n code: 200\n)\n@readonly\n"
670-
+ "operation MyOperation {\n input: MyOperationInput\n output: MyOperationOutput\n"
671-
+ " errors: [\n MyError\n ]\n}", readHover);
672+
assertTrue(readHover.getContents().getRight().getValue().contains("@http(\n method: \"PUT\"\n "
673+
+ "uri: \"/bar\"\n code: 200\n)\n@readonly\noperation MyOperation {\n input: "
674+
+ "MyOperationInput\n output: MyOperationOutput\n errors: [\n MyError\n ]\n}"));
672675

673676
// Does not correspond to shape.
674677
Hover noMatchHover = tds.hover(hoverParams(mainTdi, 0, 0)).get();

0 commit comments

Comments
 (0)