diff --git a/src/nl/hannahsten/texifyidea/completion/pathcompletion/LatexPathProviderBase.kt b/src/nl/hannahsten/texifyidea/completion/pathcompletion/LatexPathProviderBase.kt index a49d6c565..e0df119bc 100644 --- a/src/nl/hannahsten/texifyidea/completion/pathcompletion/LatexPathProviderBase.kt +++ b/src/nl/hannahsten/texifyidea/completion/pathcompletion/LatexPathProviderBase.kt @@ -123,7 +123,7 @@ abstract class LatexPathProviderBase : CompletionProvider( */ private fun addAbsolutePathCompletion(baseDir: String) { if (baseDir.isBlank()) return - LocalFileSystem.getInstance().findFileByPath(baseDir)?.let { dirFile -> + LocalFileSystem.getInstance().refreshAndFindFileByPath(baseDir)?.let { dirFile -> if (searchFolders()) { addFolderNavigations(baseDir) getContents(dirFile, true).forEach { @@ -273,18 +273,6 @@ abstract class LatexPathProviderBase : CompletionProvider( * search in given path for subfiles or directories */ private fun getContents(base: VirtualFile?, directory: Boolean): List { - val contents = java.util.ArrayList() - - if (base == null) { - return contents - } - - for (file in base.children) { - if (file.isDirectory == directory) { - contents.add(file) - } - } - - return contents + return base?.children?.filter { it.isDirectory == directory } ?: mutableListOf() } } \ No newline at end of file diff --git a/src/nl/hannahsten/texifyidea/lang/commands/RequiredFileArgument.kt b/src/nl/hannahsten/texifyidea/lang/commands/RequiredFileArgument.kt index c5d9deee0..c58875993 100644 --- a/src/nl/hannahsten/texifyidea/lang/commands/RequiredFileArgument.kt +++ b/src/nl/hannahsten/texifyidea/lang/commands/RequiredFileArgument.kt @@ -52,9 +52,8 @@ open class RequiredFileArgument(name: String?, open val isAbsolutePathSupported: regex.append("(") for (extension in extensions) { regex.append("\\.") - val extensionLower = extension.lowercase(Locale.getDefault()) - regex.append(extensionLower) - supportedExtensions.add(extensionLower) + regex.append(extension) + supportedExtensions.add(extension) if (extension != extensions[extensions.size - 1]) { regex.append("|") } diff --git a/src/nl/hannahsten/texifyidea/util/Strings.kt b/src/nl/hannahsten/texifyidea/util/Strings.kt index 92f0e06e9..ac5703393 100644 --- a/src/nl/hannahsten/texifyidea/util/Strings.kt +++ b/src/nl/hannahsten/texifyidea/util/Strings.kt @@ -82,11 +82,10 @@ fun String.getIndent(): String { fun String.appendExtension(extensionWithoutDot: String): String { if (extensionWithoutDot == "") return this - val dottedExtension = ".${extensionWithoutDot.lowercase(Locale.getDefault())}" - val thisLower = lowercase(Locale.getDefault()) + val dottedExtension = ".$extensionWithoutDot" return when { - thisLower.endsWith(dottedExtension) -> this + this.endsWith(dottedExtension) -> this endsWith('.') -> this + extensionWithoutDot else -> this + dottedExtension } diff --git a/src/nl/hannahsten/texifyidea/util/files/VirtualFile.kt b/src/nl/hannahsten/texifyidea/util/files/VirtualFile.kt index 26e57e95e..7fc5f572c 100644 --- a/src/nl/hannahsten/texifyidea/util/files/VirtualFile.kt +++ b/src/nl/hannahsten/texifyidea/util/files/VirtualFile.kt @@ -76,7 +76,7 @@ fun VirtualFile.findFile(filePath: String, extensions: List = emptyList( else { LocalFileSystem.getInstance().findFileByPath(filePath) } - if (file != null && !file.isDirectory) return file + if (file != null && !file.isDirectory && (extensions.isEmpty() || file.extension in extensions)) return file extensions.forEach { extension -> val lookFor = filePath.appendExtension(extension) diff --git a/test/nl/hannahsten/texifyidea/completion/LatexAbsolutePathCompletionTest.kt b/test/nl/hannahsten/texifyidea/completion/LatexAbsolutePathCompletionTest.kt index e645ed8e7..a8bfc582a 100644 --- a/test/nl/hannahsten/texifyidea/completion/LatexAbsolutePathCompletionTest.kt +++ b/test/nl/hannahsten/texifyidea/completion/LatexAbsolutePathCompletionTest.kt @@ -4,7 +4,6 @@ import com.intellij.codeInsight.completion.CompletionType import com.intellij.codeInsight.lookup.LookupElement import com.intellij.testFramework.fixtures.BasePlatformTestCase import nl.hannahsten.texifyidea.file.LatexFileType -import org.junit.Test import java.io.File import java.nio.file.Path import java.nio.file.Paths @@ -21,7 +20,6 @@ class LatexAbsolutePathCompletionTest : BasePlatformTestCase() { absoluteWorkingPath = currentRelativePath.toAbsolutePath().toString().replace(File.separatorChar, '/') } - @Test fun testAbsoluteFolderCompletion() { myFixture.configureByText(LatexFileType, """"\graphicspath{{$absoluteWorkingPath/test/resources/completion/path/}}""") @@ -31,7 +29,6 @@ class LatexAbsolutePathCompletionTest : BasePlatformTestCase() { assert(result.removeFolderEntries().isEmpty()) } - @Test fun testAbsoluteFileCompletion() { myFixture.configureByText(LatexFileType, """\input{$absoluteWorkingPath/test/resources/completion/path/}""") @@ -40,17 +37,15 @@ class LatexAbsolutePathCompletionTest : BasePlatformTestCase() { assert(result.isNotEmpty()) } - @Test fun testSupportedPictureExtensions() { myFixture.configureByText(LatexFileType, """\includegraphics{$absoluteWorkingPath/test/resources/completion/path/}""") val result = myFixture.complete(CompletionType.BASIC) // is only allowed to show folders and the png file - assert(result.removeFolderEntries().size == 1) + assertEquals(1, result.removeFolderEntries().size) } - @Test fun testSupportedInputExtensions() { myFixture.configureByText(LatexFileType, """\input{$absoluteWorkingPath/test/resources/completion/path/}""") @@ -60,7 +55,6 @@ class LatexAbsolutePathCompletionTest : BasePlatformTestCase() { assert(result.removeFolderEntries().size == 1) } - @Test fun testNonAbsolutePathSupport() { myFixture.configureByText(LatexFileType, """\include{$absoluteWorkingPath/test/resources/completion/cite/}""") diff --git a/test/nl/hannahsten/texifyidea/inspections/latex/probablebugs/LatexFileNotFoundInspectionTest.kt b/test/nl/hannahsten/texifyidea/inspections/latex/probablebugs/LatexFileNotFoundInspectionTest.kt index 655f55535..13128e202 100644 --- a/test/nl/hannahsten/texifyidea/inspections/latex/probablebugs/LatexFileNotFoundInspectionTest.kt +++ b/test/nl/hannahsten/texifyidea/inspections/latex/probablebugs/LatexFileNotFoundInspectionTest.kt @@ -5,11 +5,9 @@ import io.mockk.mockkStatic import nl.hannahsten.texifyidea.file.LatexFileType import nl.hannahsten.texifyidea.inspections.TexifyInspectionTestBase import nl.hannahsten.texifyidea.util.runCommandWithExitCode -import org.junit.Test import java.io.File import java.nio.file.Path import java.nio.file.Paths -import kotlin.test.assertFails class LatexFileNotFoundInspectionTest : TexifyInspectionTestBase(LatexFileNotFoundInspection()) { @@ -30,40 +28,32 @@ class LatexFileNotFoundInspectionTest : TexifyInspectionTestBase(LatexFileNotFou return "test/resources/inspections/latex/filenotfound" } - @Test - fun testInvalidAbsolutePath() { + fun testMissingAbsolutePath() { myFixture.configureByText(LatexFileType, """\includegraphics{$absoluteWorkingPath/test/resources/completion/path/myPicture.myinvalidextension}""") myFixture.checkHighlighting() } - @Test fun testValidAbsolutePath() { - myFixture.configureByText(LatexFileType, """\includegraphics{$absoluteWorkingPath/test/resources/completion/path/myPicture.png}""") + myFixture.configureByText(LatexFileType, """\includegraphics{$absoluteWorkingPath/test/resources/completion/path/myPicture.png}""") - assertFails { - myFixture.checkHighlighting() - } + myFixture.checkHighlighting() } - @Test - fun testBackActionAbsolute() { - myFixture.configureByText(LatexFileType, """\includegraphics{$absoluteWorkingPath/test/resources/completion/path/../path/../path/myPicture.png}""") + fun testValidAbsolutePathCaps() { + myFixture.configureByText(LatexFileType, """\includegraphics{$absoluteWorkingPath/test/resources/inspections/latex/filenotfound/myOtherPicture.PNG}""") + myFixture.checkHighlighting() + } - assertFails { - myFixture.checkHighlighting() - } + fun testBackActionAbsolute() { + myFixture.configureByText(LatexFileType, """\includegraphics{$absoluteWorkingPath/test/resources/completion/path/../path/../path/myPicture.png}""") + myFixture.checkHighlighting() } - @Test fun testCurrDirActionAbsolute() { - myFixture.configureByText(LatexFileType, """\includegraphics{$absoluteWorkingPath/test/./resources/./././completion/path/././myPicture.png}""") - - assertFails { - myFixture.checkHighlighting() - } + myFixture.configureByText(LatexFileType, """\includegraphics{$absoluteWorkingPath/test/./resources/./././completion/path/././myPicture.png}""") + myFixture.checkHighlighting() } - @Test fun testAbsoluteGraphicsDirWithInclude() { myFixture.copyFileToProject("myPicture.png") myFixture.configureByText( @@ -77,16 +67,35 @@ class LatexFileNotFoundInspectionTest : TexifyInspectionTestBase(LatexFileNotFou myFixture.checkHighlighting() } - @Test + fun testUpperCaseAbsoluteGraphicsDirWithInclude() { + myFixture.copyFileToProject("myOtherPicture.PNG") + myFixture.configureByText( + LatexFileType, + """ + \graphicspath{{$absoluteWorkingPath/test/resources/completion/path/}} + \includegraphics{myOtherPicture} + """.trimIndent() + ) + + myFixture.checkHighlighting() + } + fun testDefaultExtensionCompletion() { - myFixture.configureByText(LatexFileType, """\includegraphics{$absoluteWorkingPath/test/resources/completion/path/myPicture}""") + myFixture.configureByText(LatexFileType, """\includegraphics{$absoluteWorkingPath/test/resources/completion/path/myPicture}""") + myFixture.checkHighlighting() + } + + fun testDefaultUpperCaseExtensionCompletion() { + myFixture.configureByText(LatexFileType, """\includegraphics{$absoluteWorkingPath/test/resources/inspections/latex/filenotfound/myOtherPicture}""") + myFixture.checkHighlighting() + } + + fun testDefaultMixedCaseExtensionCompletion() { + myFixture.configureByText(LatexFileType, """\includegraphics{$absoluteWorkingPath/test/resources/completion/path/myBadPicture}""") - assertFails { - myFixture.checkHighlighting() - } + myFixture.checkHighlighting() } - @Test fun testNoWarningInDefinition() { myFixture.configureByText(LatexFileType, """\newcommand*{\gridelement}[1]{\subbottom[#1]{\includegraphics[width=2cm]{media/#1}}}""") @@ -101,14 +110,12 @@ class LatexFileNotFoundInspectionTest : TexifyInspectionTestBase(LatexFileNotFou // myFixture.checkHighlighting() // } - @Test fun testInvalidImportAbsolutePath() { myFixture.copyFileToProject("chapters/included.tex") myFixture.configureByText(LatexFileType, """\import{/does/not/exist}{included}""") myFixture.checkHighlighting() } - @Test fun testImportAbsolutePathIncludedFile() { val files = myFixture.configureByFiles("ImportPackageAbsolutePath.tex", "chapters/included.tex", "chapters/included2.tex") myFixture.type("$absoluteWorkingPath/chapters/") @@ -116,25 +123,21 @@ class LatexFileNotFoundInspectionTest : TexifyInspectionTestBase(LatexFileNotFou myFixture.checkHighlighting() } - @Test fun testImportRelativePathIncludedFile() { myFixture.configureByFiles("chapters/included.tex", "ImportPackageRelativePath.tex", "chapters/included2.tex") myFixture.checkHighlighting() } - @Test fun testInvalidImportRelativePathIncludedFile() { myFixture.configureByFiles("chapters/notincluded.tex", "ImportPackageRelativePathInvalid.tex", "chapters/included2.tex") myFixture.checkHighlighting() } - @Test fun `test command expansion in root file`() { myFixture.configureByFiles("commandexpansion/main.tex", "commandexpansion/main.bib", "commandexpansion/nest/sub.tex") myFixture.checkHighlighting() } - @Test fun `test command expansion in subfile`() { myFixture.configureByFiles("commandexpansion/nest/sub.tex", "commandexpansion/main.tex", "commandexpansion/nest/sub2.tex") myFixture.checkHighlighting() diff --git a/test/nl/hannahsten/texifyidea/util/TexifyUtilTest.kt b/test/nl/hannahsten/texifyidea/util/TexifyUtilTest.kt index bac48df13..6713446a1 100644 --- a/test/nl/hannahsten/texifyidea/util/TexifyUtilTest.kt +++ b/test/nl/hannahsten/texifyidea/util/TexifyUtilTest.kt @@ -43,13 +43,4 @@ class TexifyUtilTest { val expectedResult = "SomePath.tex.tex" Assert.assertEquals("SomePath.tex.tex + tex", expectedResult, actualResult) } - - @Test - fun appendExtensionCrazyCapitals() { - val path = "SoMEPaTH.TEx" - val extension = "tEX" - val actualResult = path.appendExtension(extension) - val expectedResult = "SomePath.tex" - Assert.assertTrue("SoMEPaTH.TEx + tEX", actualResult.equals(expectedResult, ignoreCase = true)) - } } \ No newline at end of file diff --git a/test/resources/inspections/latex/filenotfound/myOtherPicture.PNG b/test/resources/inspections/latex/filenotfound/myOtherPicture.PNG new file mode 100644 index 000000000..e69de29bb