Skip to content

Commit 7112e29

Browse files
authored
Fix off by one issue (#101)
* Fix off by one issue * Check location and add issue link * Inline file into test * Clear blank line * Avoid all-star import
1 parent e467548 commit 7112e29

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/main/java/software/amazon/smithy/lsp/ext/FileCachingCollector.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,9 @@ private Boolean shapeWasDefinedInline(OperationShape operation, Shape shape, Mod
274274
}
275275
int boundary = Math.max(priorShapeLine, operation.getSourceLocation().getLine());
276276
while (shapeStartLine >= boundary) {
277-
String line = modelFile.lines.get(shapeStartLine);
277+
String line = modelFile.lines.get(shapeStartLine - 1);
278+
279+
// note: this doesn't take code inside comments into account
278280
if (line.contains(":=")) {
279281
return true;
280282
}

src/test/java/software/amazon/smithy/lsp/ext/SmithyProjectTest.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515

1616
package software.amazon.smithy.lsp.ext;
1717

18-
import static org.junit.Assert.assertEquals;
19-
import static org.junit.Assert.assertFalse;
20-
2118
import java.io.File;
2219
import java.nio.file.Files;
2320
import java.nio.file.Path;
@@ -43,6 +40,10 @@
4340
import software.amazon.smithy.utils.ListUtils;
4441
import software.amazon.smithy.utils.MapUtils;
4542

43+
import static org.junit.Assert.assertEquals;
44+
import static org.junit.Assert.assertFalse;
45+
import static org.junit.Assert.assertNotNull;
46+
4647
public class SmithyProjectTest {
4748

4849
@Test
@@ -124,6 +125,30 @@ public void ignoresUnmodeledApplyStatements() throws Exception {
124125
}
125126
}
126127

128+
// https://github.com/awslabs/smithy-language-server/issues/100
129+
@Test
130+
public void allowsEmptyStructsWithMixins() throws Exception {
131+
String fileText = "$version: \"2\"\n" +
132+
"\n" +
133+
"namespace demo\n" +
134+
"\n" +
135+
"operation MyOp {\n" +
136+
" output: MyOpOutput\n" +
137+
"}\n" +
138+
"\n" +
139+
"@output\n" +
140+
"structure MyOpOutput {}\n";
141+
142+
Map<String, String> files = MapUtils.of("main.smithy", fileText);
143+
144+
try (Harness hs = Harness.create(SmithyBuildExtensions.builder().build(), files)) {
145+
assertNotNull(hs.getProject());
146+
Map<ShapeId, Location> locationMap = hs.getProject().getLocations();
147+
148+
correctLocation(locationMap, "demo#MyOpOutput", 9, 0, 9, 23);
149+
}
150+
}
151+
127152
@Test
128153
public void definitionLocationsV1() throws Exception {
129154
Path baseDir = Paths.get(SmithyProjectTest.class.getResource("models/v1").toURI());

0 commit comments

Comments
 (0)