-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created extension point for SourceFileProvider so that the Hyperlinki…
…ng logic can be easily used by other plugins (e.g., worksheet) The extension mechanism is such that other plugins will be able to register new source file provider and benefit of the existing declaration hyperlink detection logic. The fix was motivated by https://github.com/dragos/scala-worksheet/issues/23, and hopefully it will be useful for others. Fix #1001208
- Loading branch information
Showing
10 changed files
with
227 additions
and
36 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<!-- Schema file written by PDE --> | ||
<schema targetNamespace="org.scala-ide.sdt.core" xmlns="http://www.w3.org/2001/XMLSchema"> | ||
<annotation> | ||
<appInfo> | ||
<meta.schema plugin="org.scala-ide.sdt.core" id="sourcefileprovider" name="SourceFile Provider"/> | ||
</appInfo> | ||
<documentation> | ||
A provider for obtaining a compilation unit from a path. | ||
</documentation> | ||
</annotation> | ||
|
||
<element name="extension"> | ||
<annotation> | ||
<appInfo> | ||
<meta.element /> | ||
</appInfo> | ||
</annotation> | ||
<complexType> | ||
<sequence minOccurs="1" maxOccurs="unbounded"> | ||
<element ref="provider"/> | ||
</sequence> | ||
<attribute name="point" type="string" use="required"> | ||
<annotation> | ||
<documentation> | ||
|
||
</documentation> | ||
</annotation> | ||
</attribute> | ||
<attribute name="id" type="string"> | ||
<annotation> | ||
<documentation> | ||
|
||
</documentation> | ||
</annotation> | ||
</attribute> | ||
<attribute name="name" type="string"> | ||
<annotation> | ||
<documentation> | ||
|
||
</documentation> | ||
<appInfo> | ||
<meta.attribute translatable="true"/> | ||
</appInfo> | ||
</annotation> | ||
</attribute> | ||
</complexType> | ||
</element> | ||
|
||
<element name="provider"> | ||
<complexType> | ||
<attribute name="class" type="string" use="required"> | ||
<annotation> | ||
<documentation> | ||
|
||
</documentation> | ||
</annotation> | ||
</attribute> | ||
<attribute name="file_extension" type="string" use="required"> | ||
<annotation> | ||
<documentation> | ||
|
||
</documentation> | ||
</annotation> | ||
</attribute> | ||
</complexType> | ||
</element> | ||
|
||
<annotation> | ||
<appInfo> | ||
<meta.section type="since"/> | ||
</appInfo> | ||
<documentation> | ||
2.1 | ||
</documentation> | ||
</annotation> | ||
|
||
<annotation> | ||
<appInfo> | ||
<meta.section type="examples"/> | ||
</appInfo> | ||
<documentation> | ||
[Enter extension point usage example here.] | ||
</documentation> | ||
</annotation> | ||
|
||
<annotation> | ||
<appInfo> | ||
<meta.section type="apiinfo"/> | ||
</appInfo> | ||
<documentation> | ||
[Enter API information here.] | ||
</documentation> | ||
</annotation> | ||
|
||
<annotation> | ||
<appInfo> | ||
<meta.section type="implementation"/> | ||
</appInfo> | ||
<documentation> | ||
[Enter information about supplied implementation of this extension point.] | ||
</documentation> | ||
</annotation> | ||
|
||
|
||
</schema> |
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
9 changes: 9 additions & 0 deletions
9
org.scala-ide.sdt.core/src/scala/tools/eclipse/sourcefileprovider/SourceFileProvider.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,9 @@ | ||
package scala.tools.eclipse.sourcefileprovider | ||
|
||
import org.eclipse.core.runtime.IPath | ||
import scala.tools.eclipse.InteractiveCompilationUnit | ||
|
||
trait SourceFileProvider { | ||
/** Create a compilation unit for the passed workspace `path`.*/ | ||
def createFrom(path: IPath): Option[InteractiveCompilationUnit] | ||
} |
56 changes: 56 additions & 0 deletions
56
...-ide.sdt.core/src/scala/tools/eclipse/sourcefileprovider/SourceFileProviderRegistry.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,56 @@ | ||
package scala.tools.eclipse.sourcefileprovider | ||
|
||
import java.util.concurrent.{ConcurrentMap, ConcurrentHashMap} | ||
import org.eclipse.core.runtime.CoreException | ||
import org.eclipse.core.runtime.IConfigurationElement | ||
import org.eclipse.core.runtime.IExtension | ||
import org.eclipse.core.runtime.IExtensionPoint | ||
import org.eclipse.core.runtime.Platform | ||
import scala.tools.eclipse.logging.HasLogger | ||
import org.eclipse.core.runtime.IPath | ||
|
||
object SourceFileProviderRegistry extends HasLogger { | ||
private val EXTENSION_POINT = "org.scala-ide.sdt.core.sourcefileprovider" | ||
|
||
private object FileExtension { | ||
def apply(path: IPath): FileExtension = new FileExtension(path.getFileExtension()) | ||
} | ||
|
||
private case class FileExtension(extension: String) | ||
|
||
// Note: The map has to be thread-safe, since it can potentially be accessed by different threads at the same time | ||
private val registry: ConcurrentMap[FileExtension, SourceFileProvider] = new ConcurrentHashMap | ||
|
||
registerProviders() | ||
|
||
def getProvider(path: IPath): SourceFileProvider = getProvider(FileExtension(path)) | ||
|
||
private def getProvider(extension: FileExtension): SourceFileProvider = registry get extension | ||
|
||
private def registerProviders() { | ||
val extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(EXTENSION_POINT) | ||
if (extensionPoint != null) { | ||
val extensions = extensionPoint.getExtensions() | ||
for { | ||
extension <- extensions | ||
config <- extension.getConfigurationElements | ||
if config.isValid | ||
} try { | ||
val provider = config.createExecutableExtension("class").asInstanceOf[SourceFileProvider] | ||
registerProvider(config.getAttribute("file_extension"), provider) | ||
} catch { | ||
case e: CoreException => | ||
eclipseLog.error("Failed to register source file provider for extension point: " + extension, e) | ||
} | ||
} | ||
} | ||
|
||
private def registerProvider(fileExtension: String, provider: SourceFileProvider): Unit = { | ||
val extension = FileExtension(fileExtension) | ||
if(registry containsKey extension) eclipseLog.warn("Source file provider for file extension `%s` already exists. Registration of `%s` will hence be ignored.".format(fileExtension, provider)) | ||
else registry put (extension, provider) | ||
} | ||
|
||
// Note: we may need to implement the `IRegistryEventListener` if we want to support plugins that are started on the fly. This can be easily done | ||
// via `Platform.getExtensionRegistry().addListener(...)` | ||
} |