fix(lsp): invalid inferred file extensions in FileProvider

This commit is contained in:
Akash Yadav
2024-05-29 21:36:52 +05:30
parent a9f7c354f5
commit 0e8bf40e53
5 changed files with 9 additions and 21 deletions
@@ -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)
@@ -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))
@@ -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()
}
@@ -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"
}
)
}
}
@@ -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() {