Skip to content

IDE: Support jump to definition in imports #4199

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

Merged
merged 21 commits into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address review comments
  • Loading branch information
Duhemm committed Nov 13, 2018
commit cf3c247fc637f1ab738c5f0a39338af43229a797
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/interactive/Interactive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ object Interactive {
object Include {
case class Set private (val bits: Int) extends AnyVal {
def | (that: Set): Set = Set(bits | that.bits)
def except(that: Set): Set = Set(bits & ~that.bits)

def isEmpty: Boolean = bits == 0
def isOverridden: Boolean = (bits & overridden.bits) != 0
Expand Down Expand Up @@ -57,6 +58,9 @@ object Interactive {

/** Include imports in the results */
val imports: Set = Set(1 << 5)

/** All the flags */
val all: Set = Set(~0)
}

/** Does this tree define a symbol ? */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,26 +356,25 @@ class DottyLanguageServer extends LanguageServer
val syms = Interactive.enclosingSourceSymbols(path, pos)
val newName = params.getNewName

def findRenamedReferences(trees: List[SourceTree], syms: List[Symbol], withName: Name): List[SourceTree] = {
val includes = Include.all
syms.flatMap { sym =>
Interactive.findTreesMatching(trees, Include.all, sym, t => Interactive.sameName(t.name, withName))
}
}

val refs =
path match {
// Selected a renaming in an import node
case Thicket(_ :: (rename: Ident) :: Nil) :: (_: Import) :: rest if rename.pos.contains(pos.pos) =>
val includes = Include.references | Include.linkedClass | Include.imports
syms.flatMap { sym =>
Interactive.findTreesMatching(uriTrees, includes, sym, t => Interactive.sameName(t.name, rename.name))
}
findRenamedReferences(uriTrees, syms, rename.name)

// Selected a reference that has been renamed
case (nameTree: NameTree) :: rest if Interactive.isRenamed(nameTree) =>
val includes = Include.references | Include.linkedClass | Include.imports
syms.flatMap { sym =>
Interactive.findTreesMatching(uriTrees, includes, sym, t => Interactive.sameName(t.name, nameTree.name))
}
findRenamedReferences(uriTrees, syms, nameTree.name)

case _ =>
val includes =
Include.references | Include.definitions | Include.linkedClass | Include.overriding | Include.imports

val includes = Include.all.except(Include.overridden)
syms.flatMap { sym =>
val trees = driver.allTreesContaining(sym.name.sourceModuleName.toString)
Interactive.findTreesMatching(trees, includes, sym, t => Interactive.sameName(t.name, sym.name))
Expand Down