mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
fix(lsp): invalid inferred file extensions in FileProvider
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user