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
@@ -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"
}
)
}
}