From c698d9a756bbd6ad2aac8756015f0fcc8434ae20 Mon Sep 17 00:00:00 2001 From: Akash Yadav Date: Wed, 29 May 2024 21:36:52 +0530 Subject: [PATCH] fix(lsp): invalid inferred file extensions in FileProvider --- .../itsaky/androidide/lsp/java/JavaLSPTest.kt | 2 +- .../itsaky/androidide/lsp/testing/LSPTest.kt | 6 ++++-- .../itsaky/androidide/utils/FileProvider.kt | 2 +- .../androidide/utils/FileProviderTest.kt | 18 ++---------------- .../itsaky/androidide/lsp/xml/XMLLSPTest.kt | 2 +- 5 files changed, 9 insertions(+), 21 deletions(-) diff --git a/java/lsp/src/test/java/com/itsaky/androidide/lsp/java/JavaLSPTest.kt b/java/lsp/src/test/java/com/itsaky/androidide/lsp/java/JavaLSPTest.kt index a0d81735be..3e905be1ad 100644 --- a/java/lsp/src/test/java/com/itsaky/androidide/lsp/java/JavaLSPTest.kt +++ b/java/lsp/src/test/java/com/itsaky/androidide/lsp/java/JavaLSPTest.kt @@ -26,7 +26,7 @@ import org.junit.Ignore /** @author Akash Yadav */ @Ignore("Base singleton class") -object JavaLSPTest : LSPTest() { +object JavaLSPTest : LSPTest("java") { val server by lazy { ILanguageServerRegistry.getDefault().getServer(JavaLanguageServer.SERVER_ID) diff --git a/testing/lspTest/src/main/java/com/itsaky/androidide/lsp/testing/LSPTest.kt b/testing/lspTest/src/main/java/com/itsaky/androidide/lsp/testing/LSPTest.kt index 31bf17e2ce..d3de68c686 100644 --- a/testing/lspTest/src/main/java/com/itsaky/androidide/lsp/testing/LSPTest.kt +++ b/testing/lspTest/src/main/java/com/itsaky/androidide/lsp/testing/LSPTest.kt @@ -63,7 +63,9 @@ import java.nio.file.Path */ @RunWith(RobolectricTestRunner::class) @Config(manifest = Config.DEFAULT_VALUE_STRING) -abstract class LSPTest { +abstract class LSPTest( + private val sourceFileExt: String, +) { protected lateinit var toolingServer: IToolingApiServer protected lateinit var toolingProject: IProject @@ -162,7 +164,7 @@ abstract class LSPTest { } open fun openFile(fileName: String) { - file = FileProvider.sourceFile(fileName).normalize() + file = FileProvider.sourceFile(fileName, sourceFileExt).normalize() contents = FileProvider.contents(file!!) dispatchEvent(DocumentOpenEvent(file!!, contents.toString(), 0)) diff --git a/utilities/shared/src/main/java/com/itsaky/androidide/utils/FileProvider.kt b/utilities/shared/src/main/java/com/itsaky/androidide/utils/FileProvider.kt index 81b67eea30..05e6e6bf89 100644 --- a/utilities/shared/src/main/java/com/itsaky/androidide/utils/FileProvider.kt +++ b/utilities/shared/src/main/java/com/itsaky/androidide/utils/FileProvider.kt @@ -93,7 +93,7 @@ class FileProvider { * @return The path to the file. */ @JvmStatic - fun sourceFile(name: String): Path { + fun sourceFile(name: String, extension: String = ""): Path { return resources().resolve("${name}_template.$extension").normalize() } diff --git a/utilities/shared/src/test/java/com/itsaky/androidide/utils/FileProviderTest.kt b/utilities/shared/src/test/java/com/itsaky/androidide/utils/FileProviderTest.kt index 650ced6d80..306cd4335a 100644 --- a/utilities/shared/src/test/java/com/itsaky/androidide/utils/FileProviderTest.kt +++ b/utilities/shared/src/test/java/com/itsaky/androidide/utils/FileProviderTest.kt @@ -26,29 +26,15 @@ class FileProviderTest { @Test fun testPath() { - val path = FileProvider.sourceFile("SourceFileTest") + val path = FileProvider.sourceFile("SourceFileTest", "java") assertThat(Files.exists(path)).isTrue() assertThat(path.fileName.toString()).isEqualTo("SourceFileTest_template.java") } @Test fun testNested() { - val path = FileProvider.sourceFile("package/SourceFileTest") + val path = FileProvider.sourceFile("package/SourceFileTest", "java") assertThat(Files.exists(path)).isTrue() assertThat(path.fileName.toString()).isEqualTo("SourceFileTest_template.java") } - - @Test - fun testExtension() { - val folder = File(".").canonicalFile - - assertThat(FileProvider.extension).isNotEmpty() - assertThat(FileProvider.extension) - .isEqualTo( - when (folder.name) { - "xml" -> "xml" - else -> "java" - } - ) - } } \ No newline at end of file diff --git a/xml/lsp/src/test/java/com/itsaky/androidide/lsp/xml/XMLLSPTest.kt b/xml/lsp/src/test/java/com/itsaky/androidide/lsp/xml/XMLLSPTest.kt index 6466186fe0..2eb3848a44 100644 --- a/xml/lsp/src/test/java/com/itsaky/androidide/lsp/xml/XMLLSPTest.kt +++ b/xml/lsp/src/test/java/com/itsaky/androidide/lsp/xml/XMLLSPTest.kt @@ -29,7 +29,7 @@ import org.junit.Ignore /** @author Akash Yadav */ @Ignore("Base class for XML tests") -object XMLLSPTest : LSPTest() { +object XMLLSPTest : LSPTest("xml") { @Before override fun initProjectIfNeeded() {