Skip to content

Commit

Permalink
Fix Windows uri comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
Chase Coalwell committed Apr 28, 2022
1 parent aefd638 commit a8405e4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ private List<String> textBufferContents(String path) throws IOException {
LspLog.println("Path " + path + " was found in temporary buffer");
contents = Arrays.stream(tempContents.split("\n")).collect(Collectors.toList());
} else {
contents = readAll(new File(URI.create(path)));
try {
contents = readAll(new File(URI.create(path)));
} catch (IllegalArgumentException e) {
contents = readAll(new File(path));
}
}

}
Expand Down Expand Up @@ -356,7 +360,11 @@ private File fileUri(TextDocumentItem tdi) {
}

private File fileFromUri(String uri) {
return new File(URI.create(uri));
try {
return new File(URI.create(uri));
} catch (IllegalArgumentException e) {
return new File(uri);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public Optional<ShapeId> getShapeIdFromLocation(String uri, Position position) {
entry.getValue().getRange().getEnd().getLine() - entry.getValue().getRange().getStart().getLine());

List<Map.Entry<ShapeId, Location>> matchingShapes = locations.entrySet().stream()
.filter(entry -> Paths.get(entry.getValue().getUri()).equals(Paths.get(uri)))
.filter(entry -> entry.getValue().getUri().endsWith(Paths.get(uri).toString()))
.filter(filterByLocation(position))
// Since the position is in each of the overlapping shapes, return the smallest range.
.sorted(rangeSize)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ public void shapeIdFromLocation() throws Exception {

try (Harness hs = Harness.create(SmithyBuildExtensions.builder().build(), modelFiles)) {
SmithyProject project = hs.getProject();
String uri = "file:" + hs.file("main.smithy");
String testUri = "file:" + hs.file("test.smithy");
String uri = hs.file("main.smithy").toString();
String testUri = hs.file("test.smithy").toString();

assertFalse(project.getShapeIdFromLocation("empty.smithy", new Position(0, 0)).isPresent());
assertFalse(project.getShapeIdFromLocation(uri, new Position(0, 0)).isPresent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void definitions() throws Exception {
StubClient client = new StubClient();
tds.createProject(hs.getConfig(), hs.getRoot());
tds.setClient(client);
TextDocumentIdentifier mainTdi = new TextDocumentIdentifier("file:" + hs.file(modelFilename));
TextDocumentIdentifier mainTdi = new TextDocumentIdentifier(hs.file(modelFilename).toString());

// Resolves via token => shape name.
DefinitionParams commentParams = definitionParams(mainTdi, 43, 37);
Expand Down

0 comments on commit a8405e4

Please sign in to comment.