Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More abstract dealings with Scala compilation units.
We need a way to treat uniformly different kinds of Scala-based sources. Until now we routed everything through `ScalaCompilationUnit`, that extends the JDT `CompilationUnit` class. This tight connection is counter-productive, and in most cases, unnecessary. This commit is a step towards extracting a set of interfaces for other Scala-based sources to benefit of reconciliation ('errors-as-you-type'), hyperlinking and completion engine that already exists. * extracted `InteractiveCompilationUnit` as a super type of `ScalaCompilationUnit` * switched from `ScalaCompilationUnit` to `InteractiveCompilationUnit` wherever possible, to allow hyperlinking to work in the scala-worksheet project * added a utility method to retrieve the compilation unit associated with an open editor that uses the platform adapter protocol to allow other plugins to participate.
- Loading branch information
Showing
19 changed files
with
194 additions
and
79 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
72 changes: 72 additions & 0 deletions
72
org.scala-ide.sdt.core/src/scala/tools/eclipse/InteractiveCompilationUnit.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,72 @@ | ||
package scala.tools.eclipse | ||
|
||
import org.eclipse.core.resources.IFile | ||
import org.eclipse.jdt.core.compiler.IProblem | ||
|
||
import scala.tools.nsc.util.BatchSourceFile | ||
import scala.tools.nsc.util.SourceFile | ||
import scala.tools.nsc.interactive.Response | ||
import scala.tools.nsc.io.AbstractFile | ||
|
||
/** A Scala compilation unit. It can be backed up by a `ScalaCompilationUnit` in usual | ||
* Scala projects, or any other implementation (such as a specialized Scala DSL, a | ||
* Script file, an Sbt build file, etc.). | ||
* | ||
*/ | ||
trait InteractiveCompilationUnit { | ||
|
||
/** The `AbstractFile` that the Scala compiler uses to read this compilation unit. */ | ||
def file: AbstractFile | ||
|
||
/** The workspace file corresponding to this compilation unit. */ | ||
def workspaceFile: IFile | ||
|
||
/** Does this unit exist in the workspace? */ | ||
def exists(): Boolean | ||
|
||
/** The Scala project to which this compilation unit belongs. */ | ||
def scalaProject: ScalaProject | ||
|
||
/** Return a compiler `SourceFile` implementation with the given contents. The implementation decides | ||
* if this is a batch file or a script/other kind of source file. | ||
*/ | ||
def sourceFile(contents: Array[Char] = getContents): SourceFile | ||
|
||
/** Return a compiler batch source file (that needs a top-level definition). */ | ||
def batchSourceFile(contents: Array[Char] = getContents): BatchSourceFile | ||
|
||
/** Reconcile the unit. Return all compilation errors. | ||
* | ||
* Blocks until the unit is type-checked. | ||
*/ | ||
def reconcile(newContents: String): List[IProblem] | ||
|
||
/** Return all compilation errors from this unit. Waits until the unit is type-checked. | ||
* It may be long running, but it won't force retype-checking. If the unit was already typed, | ||
* the answer is fast. | ||
*/ | ||
def currentProblems(): List[IProblem] | ||
|
||
/** Return the current contents of this compilation unit. */ | ||
def getContents: Array[Char] | ||
|
||
/** Perform a side-effecting operation on the source file, with the current presentation compiler. */ | ||
def doWithSourceFile(op: (SourceFile, ScalaPresentationCompiler) => Unit) { | ||
scalaProject.withSourceFile(this)(op)(()) | ||
} | ||
|
||
/** Perform an operation on the source file, with the current presentation compiler. | ||
* | ||
* @param op The operation to be performed | ||
* @param orElse A recovery option in case the presentation compiler is not available (for instance, if it cannot be | ||
* started because of classpath issues) | ||
*/ | ||
def withSourceFile[T](op: (SourceFile, ScalaPresentationCompiler) => T)(orElse: => T = scalaProject.defaultOrElse): T = { | ||
scalaProject.withSourceFile(this)(op)(orElse) | ||
} | ||
|
||
/** Schedule the unit for reconciliation. Not blocking. Used by the usual Scala editor to signal a need for `askReload`, | ||
* ensuring faster response when calling `getProblems`. | ||
*/ | ||
def scheduleReconcile(): Response[Unit] | ||
} |
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
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
6 changes: 3 additions & 3 deletions
6
...ala-ide.sdt.core/src/scala/tools/eclipse/hyperlink/text/detector/HyperlinksDetector.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
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
Oops, something went wrong.