Skip to content

Commit d5edcfb

Browse files
committed
check filetype by extension only (performance is key, avoid reading the file itself)
1 parent e5b4206 commit d5edcfb

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2.16.2
2+
Apr 21, 2021
3+
4+
FIX: Editor complaining about crashes on PyCharm 2021.1 #274
5+
16
2.16.1
27
Apr 20, 2021
38

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jacocoTestReport {
2828
}
2929

3030
group 'net.seesharpsoft.intellij.plugins'
31-
version '2.16.1'
31+
version '2.16.2'
3232

3333
apply plugin: 'java'
3434
project.sourceCompatibility = JavaVersion.VERSION_11

src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvHelper.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import com.intellij.lang.*;
44
import com.intellij.lexer.Lexer;
5+
import com.intellij.openapi.fileTypes.FileType;
6+
import com.intellij.openapi.fileTypes.FileTypeManager;
7+
import com.intellij.openapi.fileTypes.FileTypeRegistry;
58
import com.intellij.openapi.project.Project;
69
import com.intellij.openapi.vfs.VirtualFile;
710
import com.intellij.psi.PsiElement;
@@ -20,6 +23,8 @@
2023
import net.seesharpsoft.intellij.plugins.csv.psi.CsvRecord;
2124
import net.seesharpsoft.intellij.plugins.csv.psi.CsvTypes;
2225
import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettings;
26+
import net.seesharpsoft.intellij.plugins.psv.PsvFileType;
27+
import net.seesharpsoft.intellij.plugins.tsv.TsvFileType;
2328
import org.jetbrains.annotations.NotNull;
2429

2530
import java.util.HashMap;
@@ -45,6 +50,20 @@ public static PsiElement createEmptyCsvField(PsiFile psiFile) {
4550
return node.getPsi();
4651
}
4752

53+
public static boolean isCsvFile(String extension) {
54+
switch(extension.toLowerCase()) {
55+
case "csv":
56+
case "tsv":
57+
case "tab":
58+
case "psv":
59+
return true;
60+
}
61+
FileType fileType = FileTypeRegistry.getInstance().getFileTypeByExtension(extension);
62+
return fileType == CsvFileType.INSTANCE ||
63+
fileType == TsvFileType.INSTANCE ||
64+
fileType == PsvFileType.INSTANCE;
65+
}
66+
4867
public static boolean isCsvFile(Project project, VirtualFile file) {
4968
if (project == null || file == null) {
5069
return false;

src/main/java/net/seesharpsoft/intellij/plugins/csv/components/CsvFileAttributes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void cleanupAttributeMap(@NotNull Project project) {
6363
if (virtualFile == null) {
6464
LOG.debug(fileName + " not found");
6565
faultyFiles.add(fileName);
66-
} else if (!CsvHelper.isCsvFile(project, virtualFile)) {
66+
} else if (!CsvHelper.isCsvFile(virtualFile.getExtension())) {
6767
LOG.debug(fileName + " is not a csv file");
6868
faultyFiles.add(fileName);
6969
}

src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ NEW: "General" settings group
5555
FIX: Lower annotator severity to not appear as problem
5656
FIX: Prevent non CSV entries in CSV attributes map #268
5757
FIX: keep existing & correct entries in CSV attributes map
58+
HOTFIX: Editor complaining about crashes on PyCharm 2021.1 #274
5859
</pre>
5960
]]>
6061
</change-notes>

0 commit comments

Comments
 (0)