diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeRegistry.java b/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeRegistry.java index c7c45b6fa3fd..2bea0d48c3a7 100644 --- a/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeRegistry.java +++ b/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeRegistry.java @@ -32,6 +32,13 @@ public abstract class FileTypeRegistry { public abstract boolean isFileIgnored(@NotNull VirtualFile file); + /** + * Checks if the given file has the given file type. This is faster than getting the file type + * and comparing it, because for file types that are identified by virtual file, it will only + * check if the given file type matches, and will not run other detectors. However, this can + * lead to inconsistent results if two file types report the same file as matching (which should + * generally be avoided). + */ public abstract boolean isFileOfType(@NotNull VirtualFile file, @NotNull FileType type); @Nullable diff --git a/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java index bc201cc834cc..70d6666ec3c5 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java @@ -996,9 +996,12 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent @Override public boolean isFileOfType(@NotNull VirtualFile file, @NotNull FileType type) { - if (type instanceof UnknownFileType) { + if (type.equals(PlainTextFileType.INSTANCE) || type.equals(UnknownFileType.INSTANCE)) { // a file has unknown file type if none of file type detectors matched it - return file.getFileType() instanceof UnknownFileType; + // for plain text file type, we run file type detection based on content + + //noinspection SSBasedInspection + return file.getFileType().equals(type); } if (file instanceof LightVirtualFile) {