MetalsDriver

dotty.tools.pc.MetalsDriver
class MetalsDriver(val settings: List[String]) extends InteractiveDriver

MetalsDriver is a wrapper class that provides a compilation cache for InteractiveDriver. MetalsDriver skips running compilation if

  • the target URI of run is the same as the previous target URI
  • the content didn't change since the last compilation.

This compilation cache enables Metals to skip compilation and re-use the typed tree under the situation like developers sequentially hover on the symbols in the same file without any changes.

Note: we decided to cache only if the target URI is the same as in the previous run because of InteractiveDriver.currentCtx that should return the context that refers to the last compiled source file. It would be ideal if we could update currentCtx even when we skip the compilation, but we struggled to do that. See the discussion https://github.com/scalameta/metals/pull/4225#discussion_r941138403 To avoid the complexity related to currentCtx, we decided to cache only when the target URI only if the same as the previous run.

Attributes

Graph
Supertypes
class InteractiveDriver
class Driver
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

override def run(uri: URI, source: SourceFile): List[Diagnostic]

Attributes

Definition Classes
InteractiveDriver
override def run(uri: URI, sourceCode: String): List[Diagnostic]

Attributes

Definition Classes
InteractiveDriver

Inherited methods

def allTrees(using Context): List[SourceTree]

All the trees for this project.

All the trees for this project.

This includes the trees of the sources of this project, along with the trees that are found on this project's classpath.

Attributes

Inherited from:
InteractiveDriver
def allTreesContaining(id: String)(using Context): List[SourceTree]

All the trees for this project that contain id.

All the trees for this project that contain id.

This includes the trees of the sources of this project, along with the trees that are found on this project's classpath.

Attributes

Inherited from:
InteractiveDriver
def close(uri: URI): Unit

Attributes

Inherited from:
InteractiveDriver
def compilationUnits: Map[URI, CompilationUnit]

Attributes

Inherited from:
InteractiveDriver
def currentCtx: Context

Attributes

Inherited from:
InteractiveDriver
def main(args: Array[String]): Unit

Attributes

Inherited from:
Driver
def openedFiles: Map[URI, SourceFile]

Attributes

Inherited from:
InteractiveDriver
def openedTrees: Map[URI, List[SourceTree]]

Attributes

Inherited from:
InteractiveDriver
def process(args: Array[String], rootCtx: Context): Reporter

Entry point to the compiler using a custom Context.

Entry point to the compiler using a custom Context.

In most cases, you do not need a custom Context and should instead use one of the other overloads of process. However, the other overloads cannot be overridden, instead you should override this one which they call internally.

Usage example: https://github.com/scala/scala3/tree/master/compiler/test/dotty/tools/dotc/EntryPointsTest.scala.disabled in method runCompilerWithContext

Value parameters

args

Arguments to pass to the compiler.

rootCtx

The root Context to use.

Attributes

Returns

The Reporter used. Use Reporter#hasErrors to check if compilation succeeded.

Inherited from:
Driver
def process(args: Array[String]): Reporter

Entry point to the compiler with no optional arguments.

Entry point to the compiler with no optional arguments.

This overload is provided for compatibility reasons: the RawCompiler of sbt expects this method to exist and calls it using reflection. Keeping it means that we can change the other overloads without worrying about breaking compatibility with sbt.

Attributes

Inherited from:
Driver
final def process(args: Array[String], reporter: Reporter | Null, callback: CompilerCallback | Null): Reporter

Principal entry point to the compiler.

Principal entry point to the compiler.

Usage example: https://github.com/scala/scala3/tree/master/compiler/test/dotty/tools/dotc/EntryPointsTest.scala.disabled in method runCompiler

Value parameters

args

Arguments to pass to the compiler.

callback

Used to execute custom code during the compilation process. No callbacks will be executed if this is null.

reporter

Used to log errors, warnings, and info messages. The default reporter is used if this is null.

Attributes

Returns

The Reporter used. Use Reporter#hasErrors to check if compilation succeeded.

Inherited from:
Driver
final def process(args: Array[String], simple: SimpleReporter | Null, callback: CompilerCallback | Null): ReporterResult

Entry point to the compiler that can be conveniently used with Java reflection.

Entry point to the compiler that can be conveniently used with Java reflection.

This entry point can easily be used without depending on the dotty package, you only need to depend on dotty-interfaces and call this method using reflection. This allows you to write code that will work against multiple versions of dotty without recompilation.

The trade-off is that you can only pass a SimpleReporter to this method and not a normal Reporter which is more powerful.

Usage example: https://github.com/scala/scala3/tree/master/compiler/test/dotty/tools/dotc/InterfaceEntryPointTest.scala

Value parameters

args

Arguments to pass to the compiler.

callback

Used to execute custom code during the compilation process. No callbacks will be executed if this is null.

simple

Used to log errors, warnings, and info messages. The default reporter is used if this is null.

Attributes

Inherited from:
Driver
def setup(args: Array[String], rootCtx: Context): Option[(List[AbstractFile], Context)]

Setup context with initialized settings from CLI arguments, then check if there are any settings that would change the default behaviour of the compiler.

Setup context with initialized settings from CLI arguments, then check if there are any settings that would change the default behaviour of the compiler.

Attributes

Returns

If there is no setting like -help preventing us from continuing compilation, this method returns a list of files to compile and an updated Context. If compilation should be interrupted, this method returns None.

Inherited from:
Driver
def sourceTrees(using Context): List[SourceTree]

The trees for all the source files in this project.

The trees for all the source files in this project.

This includes the trees for the buffers that are presently open in the IDE, and the trees from the target directory.

Attributes

Inherited from:
InteractiveDriver
def sourceTreesContaining(id: String)(using Context): List[SourceTree]

The trees for all the source files in this project that contain id.

The trees for all the source files in this project that contain id.

This includes the trees for the buffers that are presently open in the IDE, and the trees from the target directory.

Attributes

Inherited from:
InteractiveDriver
override def sourcesRequired: Boolean

Attributes

Definition Classes
InteractiveDriver -> Driver
Inherited from:
InteractiveDriver

Concrete fields

override val settings: List[String]