IDE integration capabilities providing incremental compilation, context preservation, and interactive features for development tools and language servers.
Specialized driver designed for IDE integration with support for incremental compilation and context preservation.
/**
* Driver subclass designed for IDE integration
* Provides incremental compilation and context preservation for interactive development
*/
class InteractiveDriver extends Driver {
/**
* Get the current compilation context
* Maintains context state across multiple compilation requests
* @return Current compilation context with preserved state
*/
def currentCtx: Context
/**
* Compile source files incrementally
* Only recompiles changed files and their dependencies
* @param sources List of source files to compile
* @return Compilation result with incremental information
*/
def compileIncremental(sources: List[SourceFile]): CompilerResult
/**
* Get completion suggestions at a specific position
* @param source Source file for completion
* @param position Cursor position for completion
* @return List of completion candidates
*/
def completionAt(source: SourceFile, position: Position): List[Completion]
/**
* Get type information at a specific position
* @param source Source file to query
* @param position Position to get type information for
* @return Optional type information at the position
*/
def typeAt(source: SourceFile, position: Position): Option[Type]
/**
* Get symbol definition location
* @param source Source file containing the symbol reference
* @param position Position of the symbol reference
* @return Optional source position of the symbol definition
*/
def definitionAt(source: SourceFile, position: Position): Option[SourcePosition]
/**
* Find all references to a symbol
* @param symbol Symbol to find references for
* @return List of source positions where the symbol is referenced
*/
def referencesTo(symbol: Symbol): List[SourcePosition]
/**
* Get hover information for a position
* @param source Source file to query
* @param position Position to get hover information for
* @return Optional hover information containing type and documentation
*/
def hoverAt(source: SourceFile, position: Position): Option[Hover]
}Usage Examples:
import dotty.tools.dotc.interactive.InteractiveDriver
import dotty.tools.dotc.util.SourceFile
val driver = new InteractiveDriver
// Set up initial compilation
val sources = List(SourceFile.virtual("Test.scala", "class Test { def foo = 42 }"))
driver.compileIncremental(sources)
// Get completions
val position = Position(source = sources.head, line = 1, column = 20)
val completions = driver.completionAt(sources.head, position)
completions.foreach(c => println(s"${c.label}: ${c.detail}"))
// Get type information
val typeInfo = driver.typeAt(sources.head, position)
typeInfo.foreach(t => println(s"Type: ${t.show}"))
// Find definition
val definition = driver.definitionAt(sources.head, position)
definition.foreach(pos => println(s"Defined at: ${pos.source.path}:${pos.line}"))Specialized compiler optimized for interactive usage with caching and incremental processing capabilities.
/**
* Compiler variant optimized for interactive usage
* Provides caching, incremental processing, and IDE-specific optimizations
*/
class InteractiveCompiler extends Compiler {
/**
* Compile with caching support
* Caches compilation results for improved performance on subsequent runs
* @param sources Source files to compile
* @param ctx Compilation context
* @return Cached compilation result
*/
def compileWithCaching(sources: List[SourceFile])(using Context): CachedResult
/**
* Invalidate cached results for changed files
* @param changedFiles List of files that have been modified
*/
def invalidateCache(changedFiles: List[SourceFile]): Unit
/**
* Get cached symbols for IDE features
* @return Map of file paths to their cached symbols
*/
def getCachedSymbols: Map[String, List[Symbol]]
/**
* Check if incremental compilation is possible
* @param sources Source files to check
* @return True if incremental compilation can be performed
*/
def canCompileIncrementally(sources: List[SourceFile]): Boolean
}Integration support for Language Server Protocol (LSP) implementations.
/**
* LSP support utilities for interactive features
*/
object LanguageServerUtils {
/**
* Convert compiler diagnostics to LSP diagnostics
* @param diagnostics Compiler diagnostics
* @return LSP-compatible diagnostic messages
*/
def toLspDiagnostics(diagnostics: List[Diagnostic]): List[LspDiagnostic]
/**
* Convert completion results to LSP completion items
* @param completions Compiler completion results
* @return LSP-compatible completion items
*/
def toLspCompletions(completions: List[Completion]): List[LspCompletionItem]
/**
* Convert hover information to LSP hover response
* @param hover Compiler hover information
* @return LSP-compatible hover response
*/
def toLspHover(hover: Hover): LspHover
}High-level presentation compiler interface for IDE features and tooling.
/**
* Presentation compiler providing high-level IDE features
* Wraps interactive compilation with convenience methods for common IDE operations
*/
class PresentationCompiler {
/**
* Initialize presentation compiler with project configuration
* @param projectRoot Root directory of the project
* @param classpath Compilation classpath
* @param scalaVersion Scala version for compilation
*/
def initialize(projectRoot: String, classpath: List[String], scalaVersion: String): Unit
/**
* Update source file content
* @param path File path to update
* @param content New file content
*/
def updateSource(path: String, content: String): Unit
/**
* Get semantic tokens for syntax highlighting
* @param path File path to tokenize
* @return List of semantic tokens with position and type information
*/
def semanticTokens(path: String): List[SemanticToken]
/**
* Get document symbols for outline view
* @param path File path to analyze
* @return Hierarchical list of document symbols
*/
def documentSymbols(path: String): List[DocumentSymbol]
/**
* Perform code formatting
* @param path File path to format
* @param options Formatting options
* @return List of text edits for formatting
*/
def format(path: String, options: FormatOptions): List[TextEdit]
/**
* Get code actions for a range
* @param path File path
* @param range Text range for code actions
* @return List of available code actions
*/
def codeActions(path: String, range: Range): List[CodeAction]
}Usage Examples:
import dotty.tools.dotc.interactive.PresentationCompiler
val pc = new PresentationCompiler
pc.initialize(
projectRoot = "/path/to/project",
classpath = List("lib/scala-library.jar"),
scalaVersion = "3.7.0"
)
// Update source content
pc.updateSource("src/Main.scala", """
object Main {
def main(args: Array[String]): Unit = {
println("Hello, World!")
}
}
""")
// Get document symbols
val symbols = pc.documentSymbols("src/Main.scala")
symbols.foreach(s => println(s"${s.name}: ${s.kind}"))
// Get semantic tokens for syntax highlighting
val tokens = pc.semanticTokens("src/Main.scala")
tokens.foreach(t => println(s"${t.range}: ${t.tokenType}"))/**
* Completion candidate for IDE code completion
*/
case class Completion(
label: String, // Display text for completion
detail: String, // Additional detail information
kind: CompletionKind, // Type of completion (method, class, etc.)
insertText: String, // Text to insert when selected
documentation: Option[String] // Optional documentation
)
enum CompletionKind {
case Method, Class, Object, Trait, Value, Variable, Type
}/**
* Hover information for IDE hover tooltips
*/
case class Hover(
content: String, // Main hover content
range: Range, // Text range for hover
documentation: Option[String] // Optional additional documentation
)/**
* Position in source code
*/
case class Position(
source: SourceFile, // Source file
line: Int, // Line number (0-based)
column: Int // Column number (0-based)
)/**
* Source position with file information
*/
case class SourcePosition(
source: SourceFile, // Source file
start: Int, // Start offset
end: Int // End offset
) {
def line: Int // Line number
def column: Int // Column number
}/**
* Text range in source code
*/
case class Range(
start: Position, // Start position
end: Position // End position
)/**
* Result of compilation operation
*/
case class CompilerResult(
success: Boolean, // Whether compilation succeeded
diagnostics: List[Diagnostic], // Compilation diagnostics
generatedFiles: List[String] // List of generated file paths
)