-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improvement: add timeout to worksheet evaluation
- Loading branch information
1 parent
0f9d773
commit 12da73a
Showing
5 changed files
with
113 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
tests/unit/src/test/scala/tests/worksheets/WorksheetInfiniteLoopSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package tests.worksheets | ||
|
||
import scala.meta.internal.metals.InitializationOptions | ||
import scala.meta.internal.metals.Messages | ||
import scala.meta.internal.metals.UserConfiguration | ||
import scala.meta.internal.metals.{BuildInfo => V} | ||
|
||
import tests.BaseLspSuite | ||
|
||
class WorksheetInfiniteLoopSuite | ||
extends BaseLspSuite("worksheet-infinite-loop") { | ||
|
||
override protected def initializationOptions: Option[InitializationOptions] = | ||
Some( | ||
InitializationOptions.Default.copy( | ||
decorationProvider = Some(true) | ||
) | ||
) | ||
|
||
override def userConfig: UserConfiguration = | ||
super.userConfig.copy( | ||
worksheetScreenWidth = 40, | ||
worksheetCancelTimeout = 1, | ||
worksheetTimeout = 4, | ||
) | ||
|
||
test("infinite-loop") { | ||
for { | ||
_ <- initialize( | ||
s""" | ||
|/metals.json | ||
|{"a": {"scalaVersion": "${V.scala3}"}} | ||
|/a/src/main/scala/foo/Main.worksheet.sc | ||
|class Animal(age: Int) | ||
| | ||
|class Rabbit(age: Int) extends Animal(age): | ||
| val id = Rabbit.tag | ||
| Rabbit.tag += 1 | ||
| def getId = id | ||
| | ||
|object Rabbit: | ||
| val basic = Rabbit(0) | ||
| var tag: Int = 0 | ||
| | ||
|val peter = Rabbit(2) | ||
|""".stripMargin | ||
) | ||
_ <- server.didOpen("a/src/main/scala/foo/Main.worksheet.sc") | ||
_ = assertNoDiff( | ||
client.workspaceShowMessages, | ||
Messages.worksheetTimeout, | ||
) | ||
_ <- server.didChange("a/src/main/scala/foo/Main.worksheet.sc")(_ => | ||
"val a = 1" | ||
) | ||
_ <- server.didSave("a/src/main/scala/foo/Main.worksheet.sc")(identity) | ||
_ = assertNoDiff( | ||
client.syntheticDecorations, | ||
"val a = 1 // : Int = 1", | ||
) | ||
} yield () | ||
} | ||
} |