Skip to content

Commit

Permalink
Fix: Language detection in associatedWith for files with empty name
Browse files Browse the repository at this point in the history
  • Loading branch information
dabico committed Dec 1, 2023
1 parent 7f64694 commit 9b8e539
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main/java/ch/usi/si/seart/treesitter/Language.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.Generated;
import lombok.Getter;
import lombok.experimental.FieldDefaults;
import org.apache.commons.io.FilenameUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;

Expand Down Expand Up @@ -459,8 +460,8 @@ public static void validate(@NotNull Language language) {
"Path argument must not be a directory!"
);
String name = path.getFileName().toString();
int i = name.lastIndexOf('.');
return Optional.ofNullable(i > 0 ? name.substring(i + 1) : null)
String extension = FilenameUtils.getExtension(name);
return Optional.of(extension)
.map(EXTENSION_LOOKUP::get)
.orElseGet(Collections::emptyList);
}
Expand Down

0 comments on commit 9b8e539

Please sign in to comment.