diff --git a/spellchecker/src/com/intellij/spellchecker/SpellCheckerManager.kt b/spellchecker/src/com/intellij/spellchecker/SpellCheckerManager.kt index 1ad7a437e4f6..8524f8da63a3 100644 --- a/spellchecker/src/com/intellij/spellchecker/SpellCheckerManager.kt +++ b/spellchecker/src/com/intellij/spellchecker/SpellCheckerManager.kt @@ -24,6 +24,8 @@ import com.intellij.openapi.ui.Messages import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.io.FileUtilRt +import com.intellij.openapi.util.io.FileUtilRt.extensionEquals +import com.intellij.openapi.util.io.FileUtilRt.getExtension import com.intellij.openapi.util.registry.Registry import com.intellij.openapi.vfs.* import com.intellij.project.stateStore @@ -420,8 +422,10 @@ private class CustomDictFileListener(private val project: Project, private val m } } -private fun isDic(path: String): Boolean { - return FileUtilRt.extensionEquals(path, "dic") +fun isDic(path: String): Boolean { + return extensionEquals(path, "dic") || + extensionEquals(path, "txt") || + getExtension(path, null) == null } private fun affectCustomDictionaries(path: String, project: Project): Boolean { diff --git a/spellchecker/src/com/intellij/spellchecker/settings/CustomDictionariesPanel.java b/spellchecker/src/com/intellij/spellchecker/settings/CustomDictionariesPanel.java index 272cceb3a87b..108ea3dc48d5 100644 --- a/spellchecker/src/com/intellij/spellchecker/settings/CustomDictionariesPanel.java +++ b/spellchecker/src/com/intellij/spellchecker/settings/CustomDictionariesPanel.java @@ -22,10 +22,10 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.table.TableCellRenderer; import java.awt.*; -import java.util.List; import java.util.*; +import java.util.List; -import static com.intellij.openapi.util.io.FileUtilRt.extensionEquals; +import static com.intellij.spellchecker.SpellCheckerManagerKt.isDic; import static com.intellij.ui.SimpleTextAttributes.GRAY_ATTRIBUTES; import static java.util.Arrays.asList; @@ -105,7 +105,7 @@ public final class CustomDictionariesPanel extends JPanel { final FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(true, false, false, false, false, true) { @Override public boolean isFileSelectable(@Nullable VirtualFile file) { - return file != null && extensionEquals(file.getPath(), "dic"); + return file != null && isDic(file.getName()); } }; diff --git a/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettings.java b/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettings.java index e852e0ac5db9..7b7c4085c240 100644 --- a/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettings.java +++ b/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettings.java @@ -4,7 +4,6 @@ package com.intellij.spellchecker.settings; import com.intellij.openapi.components.*; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.NlsSafe; -import com.intellij.openapi.util.io.FileUtilRt; import com.intellij.openapi.util.text.StringUtil; import com.intellij.spellchecker.ProjectDictionaryLayer; import com.intellij.spellchecker.util.SPFileUtil; @@ -14,6 +13,8 @@ import org.jetbrains.annotations.NotNull; import java.util.*; +import static com.intellij.spellchecker.SpellCheckerManagerKt.isDic; + @State(name = "SpellCheckerSettings", storages = @Storage(StoragePathMacros.WORKSPACE_FILE)) @Service(Service.Level.PROJECT) public final class SpellCheckerSettings implements PersistentStateComponent { @@ -146,7 +147,7 @@ public final class SpellCheckerSettings implements PersistentStateComponent SPFileUtil.processFilesRecursively(folder, file -> { - if (FileUtilRt.extensionEquals(file, "dic")) { + if (isDic(file)) { myCustomDictionariesPaths.add(file); } })); diff --git a/spellchecker/testData/inspection/dictionary/addExtensionlessToCustomDic/test b/spellchecker/testData/inspection/dictionary/addExtensionlessToCustomDic/test new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/spellchecker/testData/inspection/dictionary/addExtensionlessToCustomDic/test.after.php b/spellchecker/testData/inspection/dictionary/addExtensionlessToCustomDic/test.after.php new file mode 100644 index 000000000000..15df5adfcaf3 --- /dev/null +++ b/spellchecker/testData/inspection/dictionary/addExtensionlessToCustomDic/test.after.php @@ -0,0 +1,2 @@ +newword"; \ No newline at end of file diff --git a/spellchecker/testData/inspection/dictionary/addExtensionlessToCustomDic/test.dic.after b/spellchecker/testData/inspection/dictionary/addExtensionlessToCustomDic/test.dic.after new file mode 100644 index 000000000000..be652306a932 --- /dev/null +++ b/spellchecker/testData/inspection/dictionary/addExtensionlessToCustomDic/test.dic.after @@ -0,0 +1 @@ +newword \ No newline at end of file diff --git a/spellchecker/testData/inspection/dictionary/addTxtToCustomDic/test.after.php b/spellchecker/testData/inspection/dictionary/addTxtToCustomDic/test.after.php new file mode 100644 index 000000000000..15df5adfcaf3 --- /dev/null +++ b/spellchecker/testData/inspection/dictionary/addTxtToCustomDic/test.after.php @@ -0,0 +1,2 @@ +newword"; \ No newline at end of file diff --git a/spellchecker/testData/inspection/dictionary/addTxtToCustomDic/test.dic.after b/spellchecker/testData/inspection/dictionary/addTxtToCustomDic/test.dic.after new file mode 100644 index 000000000000..be652306a932 --- /dev/null +++ b/spellchecker/testData/inspection/dictionary/addTxtToCustomDic/test.dic.after @@ -0,0 +1 @@ +newword \ No newline at end of file diff --git a/spellchecker/testData/inspection/dictionary/addTxtToCustomDic/test.txt b/spellchecker/testData/inspection/dictionary/addTxtToCustomDic/test.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/spellchecker/testData/inspection/dictionary/renameToExtensionless/test.after.php b/spellchecker/testData/inspection/dictionary/renameToExtensionless/test.after.php new file mode 100644 index 000000000000..15df5adfcaf3 --- /dev/null +++ b/spellchecker/testData/inspection/dictionary/renameToExtensionless/test.after.php @@ -0,0 +1,2 @@ +newword"; +echo "newword"; \ No newline at end of file diff --git a/spellchecker/testSrc/com/intellij/spellchecker/dictionary/CustomDictionaryTest.java b/spellchecker/testSrc/com/intellij/spellchecker/dictionary/CustomDictionaryTest.java index e96bcb6583f0..5006a4bacae6 100644 --- a/spellchecker/testSrc/com/intellij/spellchecker/dictionary/CustomDictionaryTest.java +++ b/spellchecker/testSrc/com/intellij/spellchecker/dictionary/CustomDictionaryTest.java @@ -4,7 +4,6 @@ package com.intellij.spellchecker.dictionary; import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.util.io.FileUtilRt; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; @@ -21,9 +20,14 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; +import static com.intellij.openapi.util.io.FileUtilRt.extensionEquals; +import static com.intellij.spellchecker.SpellCheckerManagerKt.isDic; + public class CustomDictionaryTest extends SpellcheckerInspectionTestCase { private static final String TEST_DIC = "test.dic"; private static final String NEW_TEST_DIC = "new_" + TEST_DIC; + private static final String TEST_TXT = "test.txt"; + private static final String TEST_EXTENSIONLESS = "test"; private static final String TEST_DIC_AFTER = TEST_DIC + ".after"; public static final String TEMP = "temp"; private SpellCheckerSettings settings; @@ -45,7 +49,7 @@ public class CustomDictionaryTest extends SpellcheckerInspectionTestCase { List testDictionaries = new ArrayList<>(); VfsUtilCore.processFilesRecursively(dictDir, file -> { - if (FileUtilRt.extensionEquals(file.getPath(), "dic")) { + if (isDic(file.getName())) { testDictionaries.add(PathUtil.toSystemDependentName(file.getPath())); } return true; @@ -88,8 +92,8 @@ public class CustomDictionaryTest extends SpellcheckerInspectionTestCase { return dictDir.findChild(TEST_DIC_AFTER); } - private void modifyDictContent(String newContent) throws IOException { - WriteAction.run(() -> VfsUtil.saveText(dictDir.findChild(TEST_DIC), newContent)); + private void modifyDictContent(String dictName, String newContent) throws IOException { + WriteAction.run(() -> VfsUtil.saveText(dictDir.findChild(dictName), newContent)); } private void doBeforeCheck() { @@ -100,9 +104,13 @@ public class CustomDictionaryTest extends SpellcheckerInspectionTestCase { doTest(Paths.get(getTestName(true), "test.after.php").toString()); } - private void doTest() throws IOException { + private void doDictTest() throws IOException { + doDictTest(TEST_DIC); + } + + private void doDictTest(String dictName) throws IOException { doBeforeCheck(); - modifyDictContent(VfsUtilCore.loadText(getTestDictionaryAfter())); + modifyDictContent(dictName, VfsUtilCore.loadText(getTestDictionaryAfter())); doAfterCheck(); } @@ -153,23 +161,31 @@ public class CustomDictionaryTest extends SpellcheckerInspectionTestCase { } public void testAddToCustomDic() throws IOException { - doTest(); + doDictTest(); + } + + public void testAddTxtToCustomDic() throws IOException { + doDictTest(TEST_TXT); + } + + public void testAddExtensionlessToCustomDic() throws IOException { + doDictTest(TEST_EXTENSIONLESS); } public void testAddAnotherToCustomDic() throws IOException { - doTest(); + doDictTest(); } public void testRemoveFromCustomDic() throws IOException { - doTest(); + doDictTest(); } public void testAddSeveralWords() throws IOException { - doTest(); + doDictTest(); } public void testModifyDict() throws IOException { - doTest(); + doDictTest(); } public void testUtf8Dict() throws IOException { @@ -216,6 +232,12 @@ public class CustomDictionaryTest extends SpellcheckerInspectionTestCase { doAfterCheck(); } + public void testRenameToExtensionless() throws IOException { + doBeforeCheck(); + WriteAction.run(() -> getTestDictionaryFile().rename(this, "test")); + doAfterCheck(); + } + public void testRenameStillDicExtension() throws IOException { doBeforeCheck(); WriteAction.run(() -> getTestDictionaryFile().rename(this, "still.dic"));