Skip to content

Commit

Permalink
bugfix: Fix extract function not showing up
Browse files Browse the repository at this point in the history
I must have missed the add Template Body
  • Loading branch information
tgodzik committed Nov 8, 2024
1 parent ec0b8ed commit b6a45d5
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ExtractMethodCodeAction(
enclosing.map(_ match {
case Term.Block(stats) =>
stats.filter((s: Tree) => range.encloses(s.pos.toLsp))
case Template(_, _, _, stats) =>
case Template.Body(_, stats) =>
stats.filter((s: Tree) => range.encloses(s.pos.toLsp))
case ap if returnsValue(ap) => List(ap)
case _ => Nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ object TextEdits {
.collect { case (edit, Some(pos)) =>
edit -> pos
}
.sortBy(_._2.start)
.sortWith { case ((_, pos1), (_, pos2)) =>
if (pos1.start == pos2.start) pos1.end < pos2.end
else pos1.start < pos2.start

}
var curr = 0
val out = new java.lang.StringBuilder()
positions.foreach { case (edit, pos) =>
Expand Down
43 changes: 43 additions & 0 deletions tests/cross/src/test/scala/tests/pc/ExtractMethodSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,49 @@ class ExtractMethodSuite extends BaseExtractMethodSuite {
|}""".stripMargin)
)

checkEdit(
"val-trait",
"""|
|trait Simple{
| def well(str: String) = ""
|}
|
|object A{
| @@
| <<val s: Simple = ???
| s.well("")>>
|}""".stripMargin,
"""|trait Simple{
| def well(str: String) = ""
|}
|
|object A{
|
| def newMethod(): String = {
| val s: Simple = ???
| s.well("")
| }
| newMethod()
|}
|""".stripMargin,
Map(
"3" ->
"""|trait Simple{
| def well(str: String) = ""
|}
|
|object A{
|
| def newMethod(): String =
| val s: Simple = ???
| s.well("")
|
| newMethod()
|}
|""".stripMargin
)
)

checkEdit(
"single-param",
s"""|object A{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,35 @@ class ExtractMethodLspSuite
selectedActionIndex = 1,
)

check(
"val-trait",
"""|
|trait Simple{
| def well(str: String) = ""
|}
|
|object A{
|
| <<val s: Simple = ???
| s.well("")>>
|}""".stripMargin,
s"""|${ExtractMethodCodeAction.title("object `A`")}
|""".stripMargin,
"""|trait Simple{
| def well(str: String) = ""
|}
|
|object A{
|
| def newMethod(): String = {
| val s: Simple = ???
| s.well("")
| }
| newMethod()
|}
|""".stripMargin,
)

check(
"single-param",
s"""|object A{
Expand Down

0 comments on commit b6a45d5

Please sign in to comment.