diff --git a/docs/_assets/images/contribution/debug-test-code-lens.jpg b/docs/_assets/images/contribution/debug-test-code-lens.jpg new file mode 100644 index 000000000000..3a9622b95f51 Binary files /dev/null and b/docs/_assets/images/contribution/debug-test-code-lens.jpg differ diff --git a/docs/_assets/images/contribution/debug-test-explorer.jpg b/docs/_assets/images/contribution/debug-test-explorer.jpg new file mode 100644 index 000000000000..b59c7ab64f44 Binary files /dev/null and b/docs/_assets/images/contribution/debug-test-explorer.jpg differ diff --git a/docs/_docs/contributing/debugging/ide-debugging.md b/docs/_docs/contributing/debugging/ide-debugging.md index 8eaef0594736..af817826565a 100644 --- a/docs/_docs/contributing/debugging/ide-debugging.md +++ b/docs/_docs/contributing/debugging/ide-debugging.md @@ -20,9 +20,22 @@ It may take a few minutes to import, compile and index the full project. If you have any trouble with importing, you can try to switch the build server from Bloop to sbt, by running the `Metals: Switch build server` command from VSCode command palette. -## Configuring the debugger +## Debugging the unit tests -To configure the debugger in VSCode, you can go to the `Run and Debug` view and click `create a launch.json file`. +If the module you're working on contains unit tests, you can debug a specific one without any additional work. +It can be accomplished by running `Debug Test` code lens on an exact test case. + +![Debug test via code lens](/images/contribution/debug-test-code-lens.jpg) + +The second way to run a unit test is to use the test explorer tab, which lists all available test cases. +The debugger is started either by pressing a debug button or by selecting `Debug Test` option from the menu. + +![Debug test via code lens](/images/contribution/debug-test-explorer.jpg) + +## Debugging the compilation + +Debugging of the compilation requires additional configuration in order to work. +In VSCode, you can go to the `Run and Debug` view and click `create a launch.json file`. It creates the `launch.json` file in the `.vscode` folder, in which we will define the debug configurations. ![Create launch.json file](/images/contribution/launch-config-file.jpg) @@ -89,9 +102,9 @@ Here is the final configuration: } ``` -## Customizing the debug configurations +### Customizing the debug configurations -### Compiling several files at once +#### Compiling several files at once You can compile more than one Scala file, by adding them in the `args`: ```json @@ -103,7 +116,7 @@ You can compile more than one Scala file, by adding them in the `args`: ] ``` -### Depending on a library +#### Depending on a library To add a dependency to an external library you need to download it and all its transitive dependencies, and to add them in the classpath. The Coursier CLI can help you to do that. @@ -123,7 +136,7 @@ And concatenate the output into the classpath argument, which should already con ] ``` -### Add more compiler options +#### Add more compiler options In the `args` you can add any additional compiler option you want. @@ -131,11 +144,11 @@ For instance you can add `-Xprint:all` to print all the generated trees after ea Run `scalac -help` to get an overview of the available compiler options. -### Defining more than one launch configuration +#### Defining more than one launch configuration You can create as many debug configurations as you need: to compile different files, with different compiler options or different classpaths. -## Starting the debugger +### Starting the debugger Before starting the debugger you need to put a breakpoint in the part of the code that you want to debug. If you don't know where to start, you can put a breakpoint in the `main` method of the `dotty.tools.dotc.Driver` trait. diff --git a/presentation-compiler/src/main/dotty/tools/pc/ScalaPresentationCompiler.scala b/presentation-compiler/src/main/dotty/tools/pc/ScalaPresentationCompiler.scala index 170a6418f2dc..3c201cb4634a 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/ScalaPresentationCompiler.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/ScalaPresentationCompiler.scala @@ -28,7 +28,7 @@ import scala.meta.pc.* import dotty.tools.dotc.reporting.StoreReporter import dotty.tools.pc.completions.CompletionProvider import dotty.tools.pc.completions.OverrideCompletions -import dotty.tools.pc.util.BuildInfo +import dotty.tools.pc.buildinfo.BuildInfo import org.eclipse.lsp4j.DocumentHighlight import org.eclipse.lsp4j.TextEdit diff --git a/presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala b/presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala index 6b397fa1a3ad..29fe756d3776 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala @@ -31,7 +31,7 @@ import dotty.tools.dotc.util.Spans.Span import dotty.tools.dotc.util.SrcPos import dotty.tools.pc.AutoImports.AutoImportsGenerator import dotty.tools.pc.completions.OverrideCompletions.OverrideExtractor -import dotty.tools.pc.util.BuildInfo +import dotty.tools.pc.buildinfo.BuildInfo import dotty.tools.pc.utils.MtagsEnrichments.* class Completions( diff --git a/presentation-compiler/test/dotty/tools/pc/base/BasePCSuite.scala b/presentation-compiler/test/dotty/tools/pc/base/BasePCSuite.scala index e45654e83add..8c040d61575c 100644 --- a/presentation-compiler/test/dotty/tools/pc/base/BasePCSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/base/BasePCSuite.scala @@ -4,6 +4,7 @@ import java.nio.charset.StandardCharsets import java.nio.file.{Files, Path} import java.util.Comparator import java.util.concurrent.{Executors, ScheduledExecutorService} +import java.lang.management.ManagementFactory import scala.collection.immutable import scala.meta.internal.jdk.CollectionConverters.* @@ -13,7 +14,7 @@ import scala.meta.pc.{PresentationCompiler, PresentationCompilerConfig} import dotty.tools.pc.* import dotty.tools.pc.ScalaPresentationCompiler -import dotty.tools.pc.util.BuildInfo +import dotty.tools.pc.tests.buildinfo.BuildInfo import dotty.tools.pc.utils._ import org.eclipse.lsp4j.MarkupContent @@ -27,6 +28,8 @@ object TestResources: @RunWith(classOf[ReusableClassRunner]) abstract class BasePCSuite extends PcAssertions: + private val isDebug = ManagementFactory.getRuntimeMXBean.getInputArguments.toString.contains("-agentlib:jdwp") + val tmp = Files.createTempDirectory("stable-pc-tests") val executorService: ScheduledExecutorService = Executors.newSingleThreadScheduledExecutor() @@ -51,7 +54,7 @@ abstract class BasePCSuite extends PcAssertions: .newInstance("", myclasspath.asJava, scalacOpts.asJava) protected def config: PresentationCompilerConfig = - PresentationCompilerConfigImpl().copy(snippetAutoIndent = false) + PresentationCompilerConfigImpl().copy(snippetAutoIndent = false, timeoutDelay = if isDebug then 3600 else 5) private def inspectDialect(filename: String, code: String) = val file = tmp.resolve(filename) diff --git a/project/Build.scala b/project/Build.scala index 107a7ed25eb6..804ca2a6de61 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -1119,8 +1119,9 @@ object Build { dottyLib :: scalaLib // Nil }, - Compile / buildInfoPackage := "dotty.tools.pc.util", + Compile / buildInfoPackage := "dotty.tools.pc.buildinfo", Compile / buildInfoKeys := Seq(scalaVersion), + Test / buildInfoPackage := "dotty.tools.pc.tests.buildinfo", Test / buildInfoKeys := Seq(scalaVersion, ideTestsDependencyClasspath) ) ++ BuildInfoPlugin.buildInfoScopedSettings(Compile) ++ BuildInfoPlugin.buildInfoScopedSettings(Test) ++