Skip to content

Small improvements to workspace/symbol #5443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions compiler/src/dotty/tools/dotc/interactive/Interactive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,6 @@ object Interactive {
else
namedTrees(trees, include, matchSymbol(_, sym, include))

/** Find named trees with a non-empty position whose name contains `nameSubstring` in `trees`.
*/
def namedTrees(trees: List[SourceTree], nameSubstring: String)
(implicit ctx: Context): List[SourceTree] = {
val predicate: NameTree => Boolean = _.name.toString.contains(nameSubstring)
namedTrees(trees, Include.empty, predicate)
}

/** Find named trees with a non-empty position satisfying `treePredicate` in `trees`.
*
* @param includeReferences If true, include references and not just definitions
Expand All @@ -346,6 +338,7 @@ object Interactive {
val tree = utree.asInstanceOf[tpd.NameTree]
if (tree.symbol.exists
&& !tree.symbol.is(Synthetic)
&& !tree.symbol.isPrimaryConstructor
&& tree.pos.exists
&& !tree.pos.isZeroExtent
&& (include.isReferences || isDefinition(tree))
Expand Down Expand Up @@ -381,8 +374,7 @@ object Interactive {
)(implicit ctx: Context): List[SourceTree] = {
val linkedSym = symbol.linkedClass
val fullPredicate: NameTree => Boolean = tree =>
( !tree.symbol.isPrimaryConstructor
&& (includes.isDefinitions || !Interactive.isDefinition(tree))
( (includes.isDefinitions || !Interactive.isDefinition(tree))
&& ( Interactive.matchSymbol(tree, symbol, includes)
|| ( includes.isLinkedClass
&& linkedSym.exists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import core._, core.Decorators.{sourcePos => _, _}
import Comments._, Constants._, Contexts._, Flags._, Names._, NameOps._, Symbols._, SymDenotations._, Trees._, Types._
import classpath.ClassPathEntries
import reporting._, reporting.diagnostic.{Message, MessageContainer, messages}
import transform.SymUtils.decorateSymbol
import typer.Typer
import util.{Set => _, _}
import interactive._, interactive.InteractiveDriver._
Expand Down Expand Up @@ -456,8 +457,9 @@ class DottyLanguageServer extends LanguageServer
implicit val ctx = driver.currentCtx

val uriTrees = driver.openedTrees(uri)
val predicate = (tree: NameTree) => !tree.symbol.isLocal

val defs = Interactive.namedTrees(uriTrees, Include.empty, _ => true)
val defs = Interactive.namedTrees(uriTrees, Include.empty, predicate)
(for {
d <- defs if !isWorksheetWrapper(d)
info <- symbolInfo(d.tree.symbol, d.namePos, positionMapperFor(d.source))
Expand All @@ -466,12 +468,16 @@ class DottyLanguageServer extends LanguageServer

override def symbol(params: WorkspaceSymbolParams) = computeAsync { cancelToken =>
val query = params.getQuery
def predicate(implicit ctx: Context): NameTree => Boolean = { tree =>
val sym = tree.symbol
!sym.isLocal && tree.name.toString.contains(query)
}

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

val trees = driver.allTrees
val defs = Interactive.namedTrees(trees, nameSubstring = query)
val trees = driver.sourceTreesContaining(query)
val defs = Interactive.namedTrees(trees, Include.empty, predicate)
defs.flatMap(d => symbolInfo(d.tree.symbol, d.namePos, positionMapperFor(d.source)))
}.asJava
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,10 @@ class DocumentSymbolTest {
.documentSymbol(m1, (m1 to m2).symInfo("Foo", SymbolKind.Module),
(m3 to m4).symInfo("Foo", SymbolKind.Class))
}

@Test def documentSymbolSynthetic: Unit = {
code"""case class ${m1}Foo${m2}(${m3}x${m4}: Int)""".withSource
.documentSymbol(m1, (m1 to m2).symInfo("Foo", SymbolKind.Class),
(m3 to m4).symInfo("x", SymbolKind.Field, "Foo"))
}
}
22 changes: 22 additions & 0 deletions language-server/test/dotty/tools/languageserver/SymbolTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,26 @@ class SymbolTest {
.symbol("Foo", (m1 to m2).symInfo("Foo", SymbolKind.Module),
(m3 to m4).symInfo("Foo", SymbolKind.Class))
}

@Test def multipleProjects0: Unit = {
val p0 = Project.withSources(
code"""class ${m1}Foo${m2}"""
)

val p1 = Project.dependingOn(p0).withSources(
code"""class ${m3}Bar${m4} extends Foo"""
)

withProjects(p0, p1)
.symbol("Foo", (m1 to m2).symInfo("Foo", SymbolKind.Class))
}

@Test def noLocalSymbols: Unit = {
code"""object O {
def foo = {
val hello = 0
}
}""".withSource
.symbol("hello")
}
}