Skip to content

Commit 00171ae

Browse files
committed
Exclude local symbols in workspace/symbol
1 parent 14518a3 commit 00171ae

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
@@ -308,14 +308,6 @@ object Interactive {
308308
else
309309
namedTrees(trees, (include & Include.references) != 0, matchSymbol(_, sym, include))
310310

311-
/** Find named trees with a non-empty position whose name contains `nameSubstring` in `trees`.
312-
*/
313-
def namedTrees(trees: List[SourceTree], nameSubstring: String)
314-
(implicit ctx: Context): List[SourceTree] = {
315-
val predicate: NameTree => Boolean = _.name.toString.contains(nameSubstring)
316-
namedTrees(trees, includeReferences = false, predicate)
317-
}
318-
319311
/** Find named trees with a non-empty position satisfying `treePredicate` in `trees`.
320312
*
321313
* @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._
@@ -421,12 +422,14 @@ class DottyLanguageServer extends LanguageServer
421422

422423
override def symbol(params: WorkspaceSymbolParams) = computeAsync { cancelToken =>
423424
val query = params.getQuery
425+
def predicate(implicit ctx: Context): NameTree => Boolean =
426+
tree => tree.symbol.exists && !tree.symbol.isLocal && tree.name.toString.contains(query)
424427

425428
drivers.values.toList.flatMap { driver =>
426429
implicit val ctx = driver.currentCtx
427430

428431
val trees = driver.sourceTreesContaining(query)
429-
val defs = Interactive.namedTrees(trees, nameSubstring = query)
432+
val defs = Interactive.namedTrees(trees, includeReferences = false, predicate)
430433
defs.flatMap(d => symbolInfo(d.tree.symbol, d.namePos, positionMapperFor(d.source)))
431434
}.asJava
432435
}

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)