-
Notifications
You must be signed in to change notification settings - Fork 10
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
create Call Hierarchy View. #111
Open
andrey-ilinykh
wants to merge
2
commits into
scala-ide:master
Choose a base branch
from
andrey-ilinykh:issue/add-call-hierarchy-1000872
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -16,8 +16,10 @@ object SearchPlugin extends HasLogger { | |
|
||
// Only expose the Finder API. | ||
@volatile var finder: Finder = _ | ||
@volatile private var plugin: SearchPlugin = _ | ||
|
||
final val PLUGIN_ID = "org.scala.tools.eclipse.search" | ||
def apply() = plugin | ||
} | ||
|
||
class SearchPlugin extends AbstractUIPlugin with HasLogger { | ||
|
@@ -28,7 +30,7 @@ class SearchPlugin extends AbstractUIPlugin with HasLogger { | |
|
||
override def start(context: BundleContext) { | ||
super.start(context) | ||
|
||
SearchPlugin.plugin = this | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should also set |
||
val reporter = new DialogErrorReporter | ||
val index = new Index { | ||
override val base = getStateLocation().append(INDEX_DIR_NAME) | ||
|
@@ -56,6 +58,7 @@ class SearchPlugin extends AbstractUIPlugin with HasLogger { | |
indexManager.shutdown() | ||
indexManager = null | ||
SearchPlugin.finder = null | ||
SearchPlugin.plugin = null | ||
} | ||
|
||
} |
90 changes: 90 additions & 0 deletions
90
....tools.eclipse.search/src/org/scala/tools/eclipse/search/handlers/OpenCallHierarchy.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,90 @@ | ||
package org.scala.tools.eclipse.search | ||
package handlers | ||
|
||
import org.scalaide.logging.HasLogger | ||
import org.eclipse.core.commands.AbstractHandler | ||
import org.eclipse.core.commands.ExecutionEvent | ||
import org.eclipse.ui.PlatformUI | ||
import org.scala.tools.eclipse.search.ErrorReporter | ||
import org.scala.tools.eclipse.search.SearchPlugin | ||
import org.scala.tools.eclipse.search.searching.Finder | ||
import org.scala.tools.eclipse.search.ui.DialogErrorReporter | ||
import org.scala.tools.eclipse.search.ui.TypeHierarchyView | ||
import org.scalaide.util.Utils.WithAsInstanceOfOpt | ||
import org.eclipse.ui.handlers.HandlerUtil | ||
import org.scala.tools.eclipse.search.searching.Location | ||
import org.eclipse.core.runtime.jobs.Job | ||
import org.eclipse.core.runtime.IProgressMonitor | ||
import org.eclipse.core.runtime.IStatus | ||
import org.eclipse.core.runtime.Status | ||
import org.eclipse.swt.widgets.Display | ||
import org.scala.tools.eclipse.search.searching.ProjectFinder | ||
import org.scalaide.core.IScalaPlugin | ||
import org.scala.tools.eclipse.search.searching.Scope | ||
import org.scalaide.ui.editor.InteractiveCompilationUnitEditor | ||
import org.scala.tools.eclipse.search.ui.CallHierarchyView | ||
import org.scala.tools.eclipse.search.ui.Node | ||
import org.eclipse.jface.operation.IRunnableWithProgress | ||
import org.eclipse.jface.dialogs.ProgressMonitorDialog | ||
import scala.tools.nsc.interactive.Response | ||
import scala.reflect.internal.util.OffsetPosition | ||
import org.scala.tools.eclipse.search.ui.CallerNode | ||
|
||
class OpenCallHierarchy extends AbstractHandler with HasLogger { | ||
private val finder: Finder = SearchPlugin.finder | ||
private val reporter: ErrorReporter = new DialogErrorReporter | ||
|
||
override def execute(event: ExecutionEvent): Object = { | ||
|
||
def scheduleJob(e: Entity, scope: Scope, in: Node) = { | ||
val job = new Job("Searching for callers...") { | ||
def run(monitor: IProgressMonitor): IStatus = { | ||
|
||
finder.findCallers(e, scope, (offset, ee, label, owner, project) => in.list = CallerNode(offset, ee, scope, label, owner, project) :: in.list, monitor) | ||
Status.OK_STATUS | ||
} | ||
} | ||
job.schedule() | ||
|
||
} | ||
|
||
def view = PlatformUI.getWorkbench() | ||
.getActiveWorkbenchWindow() | ||
.getActivePage() | ||
.showView(CallHierarchyView.VIEW_ID) | ||
|
||
for { | ||
// For the selection | ||
editor <- Option(HandlerUtil.getActiveEditor(event)) onEmpty reporter.reportError("An editor has to be active") | ||
scalaEditor <- editor.asInstanceOfOpt[InteractiveCompilationUnitEditor] onEmpty reporter.reportError("Active editor wasn't a Scala editor") | ||
selection <- UIUtil.getSelection(scalaEditor) onEmpty reporter.reportError("You need to have a selection") | ||
thview <- view.asInstanceOfOpt[CallHierarchyView] onEmpty logger.debug("Wasn't an instance of CallHierarchyView") | ||
} { | ||
// Get the relevant scope to search for sub-types in. | ||
val projects = ProjectFinder.projectClosure(scalaEditor.getInteractiveCompilationUnit.scalaProject.underlying) | ||
val scope = Scope(projects.map(IScalaPlugin().asScalaProject(_)).flatten) | ||
val loc = Location(scalaEditor.getInteractiveCompilationUnit, selection.getOffset()) | ||
|
||
val root = thview.input | ||
root.list = List() | ||
finder.entityAt(loc) match { | ||
case Right(Some(entity: Method)) => | ||
scheduleJob(entity, scope, root) | ||
case Right(Some(entity: Val)) => | ||
scheduleJob(entity, scope, root) | ||
case Right(Some(entity: Var)) => | ||
scheduleJob(entity, scope, root) | ||
case Right(Some(entity)) => reporter.reportError(s"Sorry, can't use selected '${entity.name}' to build a call-hierarchy.") | ||
case Right(None) => // No-op | ||
case Left(_) => | ||
reporter.reportError("""Couldn't get the symbol of the given entity. | ||
|This is very likely a bug, so please submit a bug report that contains | ||
|a minimal example to https://www.assembla.com/spaces/scala-ide/tickets | ||
|Thank you! - IDE Team""".stripMargin) | ||
} | ||
} | ||
|
||
null | ||
} | ||
|
||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you introduced
apply
, I would makefinder
private.