plugin fixes: incorrect reformatting on }, incorrect parsing of class minidocs

This commit is contained in:
sergeych committed 2026-01-04 11:58:55 +01:00
1 parent 1d9befe101
commit 9e138367ef
4 files changed
+73 -6

No files matched your search

@@ -115,6 +115,23 @@ class MiniAstTest {
assertNotNull(vd.initRange)
}
@Test
fun miniAst_captures_class_doc_with_members() = runTest {
val code = """
/** Class C docs */
class C {
fun foo() {}
}
"""
val (_, sink) = compileWithMini(code)
val mini = sink.build()
assertNotNull(mini)
val cd = mini!!.declarations.filterIsInstance<MiniClassDecl>().firstOrNull { it.name == "C" }
assertNotNull(cd)
assertNotNull(cd.doc, "Class doc should be preserved even with members")
assertTrue(cd.doc!!.raw.contains("Class C docs"))
}
@Test
fun miniAst_captures_class_bases_and_doc() = runTest {
val code = """
@@ -434,4 +434,37 @@ class BlockReindentTest {
kotlin.test.assertTrue(lines.getOrNull(innerStart + 1)?.trimStart()?.startsWith("1") == true)
kotlin.test.assertEquals("}", lines.getOrNull(innerStart + 2)?.trim())
}
@Test
fun reindentRange_doubledIndentationFix() {
val src = """
class X {
fun funA(): String {
"a"
}
fun runB() {
}
}
""".trimIndent()
// The range for runB should be from the start of 'fun runB' line to the end of '}' line.
val startOfRunB = src.indexOf(" fun runB")
val endOfRunB = src.indexOf(" }") + " }".length
val range = startOfRunB until endOfRunB
val cfg = LyngFormatConfig(indentSize = 4)
val updated = LyngFormatter.reindentRange(src, range, cfg, preserveBaseIndent = true)
val expected = """
class X {
fun funA(): String {
"a"
}
fun runB() {
}
}
""".trimIndent()
assertEquals(expected, updated)
}
}