From 147e654335c8ae721ec6802cedf16bdabf5a7106 Mon Sep 17 00:00:00 2001 From: David Francoeur Date: Fri, 24 Nov 2023 16:57:00 -0500 Subject: [PATCH] Avoid substring if not suffixed --- .../software/amazon/smithy/lsp/ext/FileCachingCollector.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/software/amazon/smithy/lsp/ext/FileCachingCollector.java b/src/main/java/software/amazon/smithy/lsp/ext/FileCachingCollector.java index ec9c8ef5..334bcd28 100644 --- a/src/main/java/software/amazon/smithy/lsp/ext/FileCachingCollector.java +++ b/src/main/java/software/amazon/smithy/lsp/ext/FileCachingCollector.java @@ -240,7 +240,10 @@ private Optional getOperationForInlinedInputOrOutput(Shape shape String suffix = getOperationInputOrOutputSuffix(shape, preamble); String shapeName = shape.getId().getName(); - String matchingOperationName = shapeName.substring(0, shapeName.length() - suffix.length()); + String matchingOperationName = + shapeName.endsWith(suffix) + ? shapeName.substring(0, shapeName.length() - suffix.length()) + : shapeName; ShapeId matchingOperationId = ShapeId.fromParts(shape.getId().getNamespace(), matchingOperationName); return model.shapes(OperationShape.class)