| 
2 | 2 | 
 
  | 
3 | 3 | import com.intellij.lang.*;  | 
4 | 4 | import com.intellij.lexer.Lexer;  | 
5 |  | -import com.intellij.openapi.fileTypes.FileType;  | 
6 | 5 | import com.intellij.openapi.fileTypes.FileTypeRegistry;  | 
7 | 6 | import com.intellij.openapi.project.Project;  | 
8 | 7 | import com.intellij.openapi.vfs.VirtualFile;  | 
 | 
22 | 21 | import net.seesharpsoft.intellij.plugins.csv.psi.CsvRecord;  | 
23 | 22 | import net.seesharpsoft.intellij.plugins.csv.psi.CsvTypes;  | 
24 | 23 | import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettings;  | 
25 |  | -import net.seesharpsoft.intellij.plugins.psv.PsvFileType;  | 
26 |  | -import net.seesharpsoft.intellij.plugins.tsv.TsvFileType;  | 
27 | 24 | import net.seesharpsoft.intellij.psi.PsiHelper;  | 
28 | 25 | import org.jetbrains.annotations.NotNull;  | 
29 | 26 | 
 
  | 
@@ -58,26 +55,19 @@ public static boolean isCsvFile(String extension) {  | 
58 | 55 |         if (extension == null) {  | 
59 | 56 |             return false;  | 
60 | 57 |         }  | 
61 |  | -        // simple check to always in include the defaults even if association was removed  | 
62 |  | -        switch (extension.toLowerCase()) {  | 
63 |  | -            case "csv":  | 
64 |  | -            case "tsv":  | 
65 |  | -            case "tab":  | 
66 |  | -            case "psv":  | 
67 |  | -                return true;  | 
68 |  | -            default:  | 
69 |  | -                // but also consider other extensions that are associated manually  | 
70 |  | -                FileType fileType = FileTypeRegistry.getInstance().getFileTypeByExtension(extension);  | 
71 |  | -                return fileType == CsvFileType.INSTANCE ||  | 
72 |  | -                        fileType == TsvFileType.INSTANCE ||  | 
73 |  | -                        fileType == PsvFileType.INSTANCE;  | 
74 |  | -        }  | 
 | 58 | +        Language language = LanguageUtil.getFileTypeLanguage(  | 
 | 59 | +                FileTypeRegistry.getInstance().getFileTypeByExtension(extension)  | 
 | 60 | +        );  | 
 | 61 | +        return language != null && language.isKindOf(CsvLanguage.INSTANCE);  | 
75 | 62 |     }  | 
76 | 63 | 
 
  | 
77 | 64 |     public static boolean isCsvFile(Project project, VirtualFile file) {  | 
78 |  | -        if (project == null || file == null || !isCsvFile(file.getExtension())) {  | 
 | 65 | +        if (file == null) {  | 
79 | 66 |             return false;  | 
80 | 67 |         }  | 
 | 68 | +        if (project == null) {  | 
 | 69 | +            return isCsvFile(file.getExtension());  | 
 | 70 | +        }  | 
81 | 71 |         final Language language = LanguageUtil.getLanguageForPsi(project, file);  | 
82 | 72 |         return language != null && language.isKindOf(CsvLanguage.INSTANCE);  | 
83 | 73 |     }  | 
 | 
0 commit comments