Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix matching inline inputs/outputs with operations #111

Merged
merged 3 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,12 @@ private Optional<OperationShape> getOperationForInlinedInputOrOutput(Shape shape
) {
String suffix = getOperationInputOrOutputSuffix(shape, preamble);
String shapeName = shape.getId().getName();

String matchingOperationName = shapeName.substring(0, shapeName.length() - suffix.length());
ShapeId matchingOperationId = ShapeId.fromParts(shape.getId().getNamespace(), matchingOperationName);

return model.shapes(OperationShape.class)
.filter(operationShape -> operationShape.getId().getName().equals(matchingOperationName))
.filter(operationShape -> operationShape.getId().equals(matchingOperationId))
.findFirst()
.filter(operation -> shapeWasDefinedInline(operation, shape, modelFile));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,23 @@ public void allowsEmptyStructsWithMixins() throws Exception {
}
}

// https://github.com/awslabs/smithy-language-server/issues/110
// Note: This test is flaky, it may succeed even if the code being tested is incorrect.
@Test
public void handlesSameOperationNameBetweenNamespaces() throws Exception {
Path baseDir = Paths.get(SmithyProjectTest.class.getResource("models/operation-name-conflict").toURI());
Path modelA = baseDir.resolve("a.smithy");
Path modelB = baseDir.resolve("b.smithy");
List<Path> modelFiles = ListUtils.of(modelA, modelB);

try (Harness hs = Harness.create(SmithyBuildExtensions.builder().build(), modelFiles)) {
Map<ShapeId, Location> locationMap = hs.getProject().getLocations();

correctLocation(locationMap, "a#HelloWorld", 4, 0, 13, 1);
correctLocation(locationMap, "b#HelloWorld", 6, 0, 15, 1);
}
}

@Test
public void definitionLocationsV1() throws Exception {
Path baseDir = Paths.get(SmithyProjectTest.class.getResource("models/v1").toURI());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
$version: "2"

namespace a

operation HelloWorld {
input := {
@required
name: String
}
output := {
@required
name: String
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
$version: "2"

namespace b

string Ignored
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: this technically can be anything that makes this file longer than the other - which is what ultimately caused the IIOBE (line lookup hitting a different file than intended, which would go over the bounds).


operation HelloWorld {
input := {
@required
name: String
}
output := {
@required
name: String
}
}