Skip to content

Commit f6520a1

Browse files
committed
Fix scala#7673: Fix failing tests
- Fix failing tests in dotty.tools.languageserver.WorksheetTest - Fix failing tests in dotty.tools.languageserver.DocumentSymbolTest - Add tests for top-level decls, enums, type params in DocumentSymbolTest - Remove erroneous trees and empty owner from document symbols
1 parent 985f955 commit f6520a1

File tree

3 files changed

+67
-19
lines changed

3 files changed

+67
-19
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,12 @@ class DottyLanguageServer extends LanguageServer
489489

490490
val uriTrees = driver.openedTrees(uri)
491491

492+
// Excludes locals from synthetic symbols (with the exception of enums members)
493+
// and erroroneous trees.
492494
val excludeLocalsFromSyntheticSymbols = (n: NameTree) => {
493495
val owner = n.symbol.owner
494496
n.symbol.is(Case) || {
497+
n.name != StdNames.nme.ERROR &&
495498
!owner.is(Synthetic) &&
496499
!owner.isPrimaryConstructor
497500
}
@@ -918,11 +921,9 @@ object DottyLanguageServer {
918921
SK.Field
919922
}
920923
def containerName(sym: Symbol): String = {
921-
if (sym.owner.exists && !sym.owner.isEmptyPackage) {
922-
if (sym.owner.isPackageObject && sym.owner.owner.exists) {
923-
sym.owner.owner.name.stripModuleClassSuffix.show
924-
} else
925-
sym.owner.name.stripModuleClassSuffix.show
924+
val owner = if (sym.owner.exists && sym.owner.isPackageObject) sym.owner.owner else sym.owner
925+
if (owner.exists && !owner.isEmptyPackage) {
926+
owner.name.stripModuleClassSuffix.show
926927
} else
927928
null
928929
}

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

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,86 @@ import dotty.tools.languageserver.util.Code._
99
class DocumentSymbolTest {
1010

1111
@Test def withErroneousTree: Unit =
12-
code"class ${m1}Foo$m2 { def }"
12+
code"${m1}class Foo { def }$m2"
1313
.withSource.documentSymbol(m1, (m1 to m2).symInfo("Foo", SymbolKind.Class))
1414

1515
@Test def documentSymbol0: Unit =
16-
code"class ${m1}Foo$m2".withSource.documentSymbol(m1, (m1 to m2).symInfo("Foo", SymbolKind.Class))
16+
code"${m1}class Foo$m2".withSource.documentSymbol(m1, (m1 to m2).symInfo("Foo", SymbolKind.Class))
1717

1818
@Test def documentSymbol1: Unit =
19-
code"class ${m1}Foo$m2; class ${m3}Bar$m4".withSource
19+
code"${m1}class Foo$m2; ${m3}class Bar$m4".withSource
2020
.documentSymbol(m1, (m1 to m2).symInfo("Foo", SymbolKind.Class), (m3 to m4).symInfo("Bar", SymbolKind.Class))
2121

2222
@Test def documentSymbol3: Unit = {
2323
withSources(
24-
code"class ${m1}Foo$m2",
25-
code"class ${m3}Bar$m4"
24+
code"${m1}class Foo$m2",
25+
code"${m3}class Bar$m4"
2626
) .documentSymbol(m1, (m1 to m2).symInfo("Foo", SymbolKind.Class))
2727
.documentSymbol(m3, (m3 to m4).symInfo("Bar", SymbolKind.Class))
2828
}
2929

3030
@Test def documentSymbolShowModule: Unit = {
31-
code"""object ${m1}Foo${m2}""".withSource
31+
code"""${m1}object Foo${m2}""".withSource
3232
.documentSymbol(m1, (m1 to m2).symInfo("Foo", SymbolKind.Module))
3333
}
3434

3535
@Test def documentSymbolShowClassAndCompanion: Unit = {
36-
code"""object ${m1}Foo${m2}
37-
|class ${m3}Foo${m4}""".withSource
36+
code"""${m1}object Foo${m2}
37+
|${m3}class Foo${m4}""".withSource
3838
.documentSymbol(m1, (m1 to m2).symInfo("Foo", SymbolKind.Module),
3939
(m3 to m4).symInfo("Foo", SymbolKind.Class))
4040
}
4141

4242
@Test def documentSymbolSynthetic: Unit = {
43-
code"""case class ${m1}Foo${m2}(${m3}x${m4}: Int)""".withSource
43+
code"""${m1}case class Foo(${m3}x: Int${m4})${m2}""".withSource
4444
.documentSymbol(m1, (m1 to m2).symInfo("Foo", SymbolKind.Class),
4545
(m3 to m4).symInfo("x", SymbolKind.Field, "Foo"))
4646
}
47+
48+
@Test def documentSymbolEnumADT: Unit = {
49+
code"""${m1}enum Option[${m3}+T${m4}] {
50+
${m5}case Some(${m7}x: T${m8})${m6}
51+
${m9}case None${m10}
52+
}${m2}""".withSource
53+
.documentSymbol(m1, (m1 to m2).symInfo("Option", SymbolKind.Enum),
54+
(m3 to m4).symInfo("T", SymbolKind.TypeParameter, "Option"),
55+
(m5 to m6).symInfo("Some", SymbolKind.EnumMember, "Option"),
56+
(m7 to m8).symInfo("x", SymbolKind.Field, "Some"),
57+
(m9 to m10).symInfo("None", SymbolKind.EnumMember, "Option"))
58+
}
59+
60+
@Test def documentSymbolEnum: Unit = {
61+
code"""${m1}enum Color(${m3}val rgb: Int${m4}) {
62+
${m5}case Red extends Color(0xFF0000)${m6}
63+
${m7}case Green extends Color(0x00FF00)${m8}
64+
${m9}case Blue extends Color(0x0000FF)${m10}
65+
}${m2}""".withSource
66+
.documentSymbol(m1, (m1 to m2).symInfo("Color", SymbolKind.Enum),
67+
(m3 to m4).symInfo("rgb", SymbolKind.Field, "Color"),
68+
(m5 to m6).symInfo("Red", SymbolKind.EnumMember, "Color"),
69+
(m7 to m8).symInfo("Green", SymbolKind.EnumMember, "Color"),
70+
(m9 to m10).symInfo("Blue", SymbolKind.EnumMember, "Color"))
71+
}
72+
73+
@Test def documentSymbolTopLevelDef: Unit =
74+
code"${m1}def foo(): Unit = { }${m2}".withSource.documentSymbol(m1, (m1 to m2).symInfo("foo", SymbolKind.Method))
75+
76+
@Test def documentSymbolTrait: Unit =
77+
code"${m1}trait Foo(${m3}val x: Int${m4})${m2}".withSource.documentSymbol(m1, (m1 to m2).symInfo("Foo", SymbolKind.Interface),
78+
(m3 to m4).symInfo("x", SymbolKind.Field, "Foo"))
79+
80+
@Test def documentSymbolLocalDef: Unit =
81+
code"""${m1}def foo(): Unit = {
82+
${m3}def bar(): Unit = { }${m4}
83+
${m5}val x: Int = 0${m6}
84+
}${m2}""".withSource.documentSymbol(m1, (m1 to m2).symInfo("foo", SymbolKind.Method),
85+
(m3 to m4).symInfo("bar", SymbolKind.Method, "foo"),
86+
(m5 to m6).symInfo("x", SymbolKind.Field, "foo") )
87+
88+
@Test def documentSymbolTypeFields: Unit =
89+
code"""${m1}class Foo {
90+
${m3}type T${m4}
91+
}${m2}""".withSource.documentSymbol(m1, (m1 to m2).symInfo("Foo", SymbolKind.Class),
92+
(m3 to m4).symInfo("T", SymbolKind.TypeParameter, "Foo"))
93+
4794
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ class WorksheetTest {
189189
}
190190

191191
@Test def worksheetDocumentSymbol(): Unit = {
192-
ws"""class ${m1}Foo${m2} {
193-
def ${m3}bar${m4} = 123
194-
}""".withSource
195-
.documentSymbol(m1, (m1 to m2).symInfo("Foo", SymbolKind.Class, WorksheetWrapper.moduleClassName.toString),
192+
ws"""${m1}class Foo {
193+
${m3}def bar = 123${m4}
194+
}${m2}""".withSource
195+
.documentSymbol(m1, (m1 to m2).symInfo("Foo", SymbolKind.Class, WorksheetWrapper.moduleClassName.stripModuleClassSuffix.toString),
196196
(m3 to m4).symInfo("bar", SymbolKind.Method, "Foo"))
197197
}
198198

@@ -202,7 +202,7 @@ class WorksheetTest {
202202
def ${m3}bar${m4} = 123
203203
}""",
204204
code"""class ${m5}Baz${m6}"""
205-
).symbol("Foo", (m1 to m2).symInfo("Foo", SymbolKind.Class, WorksheetWrapper.moduleClassName.toString))
205+
).symbol("Foo", (m1 to m2).symInfo("Foo", SymbolKind.Class, WorksheetWrapper.moduleClassName.stripModuleClassSuffix.toString))
206206
.symbol("bar", (m3 to m4).symInfo("bar", SymbolKind.Method, "Foo"))
207207
.symbol("Baz", (m5 to m6).symInfo("Baz", SymbolKind.Class))
208208
}

0 commit comments

Comments
 (0)