Skip to content

Commit 54656b9

Browse files
committed
Exclude local symbols in workspace/symbol
1 parent cd2f983 commit 54656b9

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,6 @@ object Interactive {
317317
else
318318
namedTrees(trees, include, matchSymbol(_, sym, include))
319319

320-
/** Find named trees with a non-empty position whose name contains `nameSubstring` in `trees`.
321-
*/
322-
def namedTrees(trees: List[SourceTree], nameSubstring: String)
323-
(implicit ctx: Context): List[SourceTree] = {
324-
val predicate: NameTree => Boolean = _.name.toString.contains(nameSubstring)
325-
namedTrees(trees, Include.empty, predicate)
326-
}
327-
328320
/** Find named trees with a non-empty position satisfying `treePredicate` in `trees`.
329321
*
330322
* @param includeReferences If true, include references and not just definitions

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import core._, core.Decorators.{sourcePos => _, _}
2222
import Comments._, Constants._, Contexts._, Flags._, Names._, NameOps._, Symbols._, SymDenotations._, Trees._, Types._
2323
import classpath.ClassPathEntries
2424
import reporting._, reporting.diagnostic.{Message, MessageContainer, messages}
25+
import transform.SymUtils.decorateSymbol
2526
import typer.Typer
2627
import util.{Set => _, _}
2728
import interactive._, interactive.InteractiveDriver._
@@ -466,12 +467,14 @@ class DottyLanguageServer extends LanguageServer
466467

467468
override def symbol(params: WorkspaceSymbolParams) = computeAsync { cancelToken =>
468469
val query = params.getQuery
470+
def predicate(implicit ctx: Context): NameTree => Boolean =
471+
tree => tree.symbol.exists && !tree.symbol.isLocal && tree.name.toString.contains(query)
469472

470473
drivers.values.toList.flatMap { driver =>
471474
implicit val ctx = driver.currentCtx
472475

473476
val trees = driver.sourceTreesContaining(query)
474-
val defs = Interactive.namedTrees(trees, nameSubstring = query)
477+
val defs = Interactive.namedTrees(trees, includeReferences = false, predicate)
475478
defs.flatMap(d => symbolInfo(d.tree.symbol, d.namePos, positionMapperFor(d.source)))
476479
}.asJava
477480
}

language-server/test/dotty/tools/languageserver/SymbolTest.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,14 @@ class SymbolTest {
5151

5252
withProjects(p0, p1)
5353
.symbol("Foo", (m1 to m2).symInfo("Foo", SymbolKind.Class))
54+
}
5455

55-
56+
@Test def noLocalSymbols: Unit = {
57+
code"""object O {
58+
def foo = {
59+
val hello = 0
60+
}
61+
}""".withSource
62+
.symbol("hello")
5663
}
5764
}

0 commit comments

Comments
 (0)