Skip to content

Commit 78db538

Browse files
committed
Fixes IDE ticket #1000692.
1 parent 36adada commit 78db538

File tree

1 file changed

+42
-28
lines changed

1 file changed

+42
-28
lines changed

src/compiler/scala/tools/nsc/interactive/Global.scala

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -708,46 +708,60 @@ class Global(settings: Settings, reporter: Reporter, projectName: String = "")
708708

709709
/** Implements CompilerControl.askLinkPos */
710710
private[interactive] def getLinkPos(sym: Symbol, source: SourceFile, response: Response[Position]) {
711-
informIDE("getLinkPos "+sym+" "+source)
712-
respond(response) {
713-
val preExisting = unitOfFile isDefinedAt source.file
714-
val originalTypeParams = sym.owner.typeParams
715-
reloadSources(List(source))
716-
parseAndEnter(getUnit(source).get)
717-
val owner = sym.owner
718-
if (owner.isClass) {
719-
val pre = adaptToNewRunMap(ThisType(owner))
720-
val newsym = pre.decl(sym.name) filter { alt =>
711+
def doGetLinkPos(sym: Symbol, source: SourceFile, response: Response[Position]) {
712+
informIDE("getLinkPos "+sym+" "+source)
713+
respond(response) {
714+
val preExisting = unitOfFile isDefinedAt source.file
715+
val originalTypeParams = sym.owner.typeParams
716+
reloadSources(List(source))
717+
parseAndEnter(getUnit(source).get)
718+
val owner = sym.owner
719+
if (owner.isClass) {
720+
val pre = adaptToNewRunMap(ThisType(owner))
721+
val newsym = pre.decl(sym.name) filter { alt =>
721722
sym.isType || {
722723
try {
723724
val tp1 = pre.memberType(alt) onTypeError NoType
724725
val tp2 = adaptToNewRunMap(sym.tpe) substSym (originalTypeParams, owner.typeParams)
725726
matchesType(tp1, tp2, false)
726727
} catch {
727-
case ex: Throwable =>
728-
println("error in hyperlinking: "+ex)
729-
ex.printStackTrace()
730-
false
728+
case ex: Throwable =>
729+
println("error in hyperlinking: "+ex)
730+
ex.printStackTrace()
731+
false
731732
}
732733
}
733-
}
734-
if (!preExisting) removeUnitOf(source)
735-
if (newsym == NoSymbol) {
736-
debugLog("link not found "+sym+" "+source+" "+pre)
737-
NoPosition
738-
} else if (newsym.isOverloaded) {
739-
settings.uniqid.value = true
740-
debugLog("link ambiguous "+sym+" "+source+" "+pre+" "+newsym.alternatives)
741-
NoPosition
734+
}
735+
if (!preExisting) removeUnitOf(source)
736+
if (newsym == NoSymbol) {
737+
debugLog("link not found "+sym+" "+source+" "+pre)
738+
NoPosition
739+
} else if (newsym.isOverloaded) {
740+
settings.uniqid.value = true
741+
debugLog("link ambiguous "+sym+" "+source+" "+pre+" "+newsym.alternatives)
742+
NoPosition
743+
} else {
744+
debugLog("link found for "+newsym+": "+newsym.pos)
745+
newsym.pos
746+
}
742747
} else {
743-
debugLog("link found for "+newsym+": "+newsym.pos)
744-
newsym.pos
748+
debugLog("link not in class "+sym+" "+source+" "+owner)
749+
NoPosition
745750
}
746-
} else {
747-
debugLog("link not in class "+sym+" "+source+" "+owner)
748-
NoPosition
749751
}
750752
}
753+
754+
try {
755+
reload(List(source), new Response[Unit])
756+
doGetLinkPos(sym, source, response)
757+
}
758+
finally {
759+
/* Make sure to unload the `source` file that is supposed to contain
760+
* the definition of the symbol referenced by the link (i.e., `sym`).
761+
* The source is unloaded for performance reasons, as the more are the loaded
762+
* units, the slower is the background compiler. */
763+
removeUnitOf(source)
764+
}
751765
}
752766

753767
def stabilizedType(tree: Tree): Type = tree match {

0 commit comments

Comments
 (0)