Skip to content

Commit 21b3149

Browse files
authored
Merge pull request #2744 from dotty-staging/fix-hover
Fix #2743: Fix hover problem
2 parents b0f6d04 + bda0318 commit 21b3149

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ object Types {
125125
def isRef(sym: Symbol)(implicit ctx: Context): Boolean = stripAnnots.stripTypeVar match {
126126
case this1: TypeRef =>
127127
this1.info match { // see comment in Namer#typeDefSig
128-
case TypeAlias(tp) => tp.isRef(sym)
128+
case TypeAlias(tp) =>
129+
assert((tp ne this) && (tp ne this1), s"$tp / $this")
130+
tp.isRef(sym)
129131
case _ => this1.symbol eq sym
130132
}
131133
case this1: RefinedOrRecType => this1.parent.isRef(sym)

compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@ class InteractiveDriver(settings: List[String]) extends Driver {
4444

4545
def currentCtx: Context = myCtx
4646

47-
private val myOpenedFiles = new mutable.LinkedHashMap[URI, SourceFile]
48-
private val myOpenedTrees = new mutable.LinkedHashMap[URI, List[SourceTree]]
47+
private val myOpenedFiles = new mutable.LinkedHashMap[URI, SourceFile] {
48+
override def default(key: URI) = NoSource
49+
}
50+
51+
private val myOpenedTrees = new mutable.LinkedHashMap[URI, List[SourceTree]] {
52+
override def default(key: URI) = Nil
53+
}
4954

5055
def openedFiles: Map[URI, SourceFile] = myOpenedFiles
5156
def openedTrees: Map[URI, List[SourceTree]] = myOpenedTrees

language-server/src/dotty/tools/languageserver/DottyLanguageServer.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,12 @@ object DottyLanguageServer {
351351

352352
/** Convert an lsp4j.Position to a SourcePosition */
353353
def sourcePosition(driver: InteractiveDriver, uri: URI, pos: lsp4j.Position): SourcePosition = {
354-
val source = driver.openedFiles(uri) // might throw exception
355-
val p = Positions.Position(source.lineToOffset(pos.getLine) + pos.getCharacter)
356-
new SourcePosition(source, p)
354+
val source = driver.openedFiles(uri)
355+
if (source.exists) {
356+
val p = Positions.Position(source.lineToOffset(pos.getLine) + pos.getCharacter)
357+
new SourcePosition(source, p)
358+
}
359+
else NoSourcePosition
357360
}
358361

359362
/** Convert a SourcePosition to an lsp4j.Range */

0 commit comments

Comments
 (0)