Skip to content

Backport "Fix BuildInfo scope in scala3-presentation-compiler, improve debugging support" to LTS #19145

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

Merged
merged 1 commit into from
Dec 8, 2023
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 21 additions & 8 deletions docs/_docs/contributing/debugging/ide-debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -123,19 +136,19 @@ 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.

For instance you can add `-Xprint:all` to print all the generated trees after each mega phase.

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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) ++
Expand Down