Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: Fix extract function not showing up #6920

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading