Skip to content

Commit cc1e969

Browse files
committed
Make "goto-definition" more useful.
When invoking "goto-definition" on a definition node itself, we now return all overriding or overridden definitions, in all sources. Previously, we returned only overriding definitions in the same source. But it's arguably more useful to know about overriding definitions in other sources because these are harder to find manually. Performance, is not an issue because it's only invoked if one is already on a definition, which should be relatively rare.
1 parent c56f126 commit cc1e969

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,10 @@ class DottyLanguageServer extends LanguageServer
211211
/*isIncomplete = */ false, items.map(completionItem).asJava))
212212
}
213213

214-
/** If cursor is on a reference, show its definition and all overriding definitions.
214+
/** If cursor is on a reference, show its definition and all overriding definitions in
215+
* the same source as the primary definition.
215216
* If cursor is on a definition, show this definition together with all overridden
216-
* and overriding definitions.
217-
* For performance reasons we currently look for overrides only in the file
218-
* where `sym` is defined.
217+
* and overriding definitions (in all sources).
219218
*/
220219
override def definition(params: TextDocumentPositionParams) = computeAsync { cancelToken =>
221220
val uri = new URI(params.getTextDocument.getUri)
@@ -228,9 +227,13 @@ class DottyLanguageServer extends LanguageServer
228227

229228
if (sym == NoSymbol) Nil.asJava
230229
else {
231-
val trees = SourceTree.fromSymbol(sym.topLevelClass.asClass).toList
232-
var include = Include.overriding
233-
if (enclTree.isInstanceOf[MemberDef]) include |= Include.overridden
230+
val (trees, include) =
231+
if (enclTree.isInstanceOf[MemberDef])
232+
(driver.allTreesContaining(sym.name.sourceModuleName.toString),
233+
Include.overriding | Include.overridden)
234+
else
235+
(SourceTree.fromSymbol(sym.topLevelClass.asClass).toList,
236+
Include.overriding)
234237
val defs = Interactive.namedTrees(trees, include, sym)
235238
defs.map(d => location(d.namePos)).asJava
236239
}

0 commit comments

Comments
 (0)