Skip to content

Commit 2838860

Browse files
committed
Mock Symbol Search documentation and definition
1 parent 3b24b6e commit 2838860

31 files changed

+247
-572
lines changed

presentation-compiler/src/main/dotty/tools/pc/MetalsInteractive.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import scala.annotation.tailrec
55
import dotty.tools.dotc.ast.tpd
66
import dotty.tools.dotc.ast.tpd.*
77
import dotty.tools.dotc.ast.untpd
8-
import dotty.tools.dotc.core.ContextOps.*
98
import dotty.tools.dotc.core.Contexts.*
10-
import dotty.tools.dotc.core.CyclicReference
119
import dotty.tools.dotc.core.Flags.*
1210
import dotty.tools.dotc.core.Names.Name
1311
import dotty.tools.dotc.core.StdNames

presentation-compiler/src/main/dotty/tools/pc/SelectionRangeProvider.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ import java.util as ju
66
import scala.jdk.CollectionConverters._
77
import scala.meta.pc.OffsetParams
88

9-
import dotty.tools.dotc.core.Comments.Comment
109
import dotty.tools.dotc.core.Contexts.Context
1110
import dotty.tools.dotc.interactive.Interactive
1211
import dotty.tools.dotc.interactive.InteractiveDriver
13-
import dotty.tools.dotc.semanticdb.Scala3
1412
import dotty.tools.dotc.util.SourceFile
15-
import dotty.tools.dotc.util.SourcePosition
1613
import dotty.tools.pc.utils.MtagsEnrichments.*
1714

1815
import org.eclipse.lsp4j

presentation-compiler/src/main/dotty/tools/pc/SignatureHelpProvider.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package dotty.tools.pc
22

33
import scala.jdk.CollectionConverters._
4-
import scala.meta.internal.semver.SemVer
54
import scala.meta.pc.OffsetParams
65
import scala.meta.pc.SymbolDocumentation
76
import scala.meta.pc.SymbolSearch

presentation-compiler/src/main/dotty/tools/pc/utils/MtagsEnrichments.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package dotty.tools.pc.utils
22

33
import scala.annotation.tailrec
44
import scala.meta.internal.jdk.CollectionConverters.*
5-
import scala.meta.internal.metals.WorkspaceSymbolQuery
65
import scala.meta.internal.mtags.CommonMtagsEnrichments
76
import scala.meta.internal.mtags.KeywordWrapper
87
import scala.meta.pc.OffsetParams
@@ -24,8 +23,6 @@ import dotty.tools.dotc.core.Types.AppliedType
2423
import dotty.tools.dotc.core.Types.Type
2524
import dotty.tools.dotc.interactive.Interactive
2625
import dotty.tools.dotc.interactive.InteractiveDriver
27-
import dotty.tools.dotc.semanticdb.SymbolInformation
28-
import dotty.tools.dotc.semanticdb.SymbolInformation.Kind
2926
import dotty.tools.dotc.util.SourcePosition
3027
import dotty.tools.dotc.util.Spans
3128
import dotty.tools.dotc.util.Spans.Span

presentation-compiler/test/dotty/tools/pc/base/BaseCompletionSuite.scala

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
11
package dotty.tools.pc.base
22

3-
import java.awt.image.PackedColorModel
43
import java.nio.file.Paths
54
import java.util.Collections
65

76
import scala.jdk.CollectionConverters.*
8-
import scala.meta.internal.jdk.CollectionConverters.*
97
import scala.meta.internal.metals.{CompilerOffsetParams, EmptyCancelToken}
108
import scala.meta.pc.CancelToken
119

12-
import dotty.tools.dotc.util.DiffUtil
1310
import dotty.tools.pc.utils.MtagsEnrichments.*
1411
import dotty.tools.pc.utils.{TestCompletions, TextEdits}
1512

1613
import org.eclipse.lsp4j.{CompletionItem, CompletionList}
17-
import org.hamcrest
18-
import org.hamcrest.CoreMatchers.*
19-
import org.hamcrest.{Matcher, MatcherAssert, StringDescription, TypeSafeMatcher}
20-
import org.jline.utils.DiffHelper
21-
import org.junit.*
22-
import org.junit.rules.{ExpectedException, RuleChain, TestRule, TestWatcher}
23-
import org.junit.runner.Description
2414

2515
abstract class BaseCompletionSuite extends BasePCSuite:
2616

@@ -272,12 +262,6 @@ abstract class BaseCompletionSuite extends BasePCSuite:
272262
}
273263
}
274264

275-
private def computeDiffMessageEditLines(
276-
expected: String,
277-
actual: String
278-
): String =
279-
"\n\n" + DiffUtil.mkColoredCodeDiff(actual, expected, true) + "\n"
280-
281265
private def trimTrailingSpace(string: String): String =
282266
string.linesIterator
283267
.map(_.replaceFirst("\\s++$", ""))

presentation-compiler/test/dotty/tools/pc/base/BasePCSuite.scala

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,10 @@ import dotty.tools.pc.utils._
1818

1919
import org.eclipse.lsp4j.MarkupContent
2020
import org.eclipse.lsp4j.jsonrpc.messages.Either as JEither
21-
import org.junit.Assert.*
22-
import org.junit.Test
2321
import org.junit.runner.RunWith
24-
import org.junit.runners.BlockJUnit4ClassRunner
25-
import org.junit.runners.model.{FrameworkMethod, Statement}
2622

2723
object TestResources:
2824
val scalaLibrary = BuildInfo.ideTestsDependencyClasspath.map(_.toPath).toSeq
29-
30-
val index = TestingIndex(scalaLibrary.map(_.toString))
3125
val classpathSearch =
3226
ClasspathSearch.fromClasspath(scalaLibrary, ExcludedPackagesHandler.default)
3327

@@ -43,11 +37,10 @@ abstract class BasePCSuite extends PcAssertions:
4337
lazy val presentationCompiler: PresentationCompiler =
4438
val myclasspath: Seq[Path] = TestResources.scalaLibrary
4539
val scalacOpts = scalacOptions(myclasspath)
46-
47-
val search = new TestingSymbolSearch(
40+
val search = new MockSymbolSearch(
4841
testingWorkspaceSearch,
49-
if requiresJdkSources then Some(TestResources.index) else None,
50-
TestResources.classpathSearch
42+
TestResources.classpathSearch,
43+
mockEntries
5144
)
5245

5346
new ScalaPresentationCompiler()
@@ -79,8 +72,7 @@ abstract class BasePCSuite extends PcAssertions:
7972

8073
protected def scalacOptions(classpath: Seq[Path]): Seq[String] =
8174
immutable.Seq.empty
82-
protected def requiresJdkSources: Boolean = false
83-
protected def requiresScalaLibrarySources: Boolean = false
75+
protected def mockEntries: MockEntries = new MockEntries {}
8476

8577
def params(code: String, filename: String = "test.scala"): (String, Int) =
8678
val code2 = code.replace("@@", "")

presentation-compiler/test/dotty/tools/pc/tests/NoIndentSuite.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import java.nio.file.Path
55
import dotty.tools.pc.base.{BaseCompletionSuite, BaseExtractMethodSuite}
66

77
import org.junit.Test
8+
import dotty.tools.pc.utils.MockEntries
89

910
class ExtractMethodNoIndentSuite extends BaseExtractMethodSuite:
1011
override protected def scalacOptions(classpath: Seq[Path]): Seq[String] =
@@ -82,8 +83,8 @@ class CompletionMatchNoIndentSuite extends BaseCompletionSuite:
8283
s"""
8384
|object A {
8485
| Option(1) match {
85-
|\tcase Some(value) => $$0
86-
|\tcase None =>
86+
|\tcase None => $$0
87+
|\tcase Some(value) =>
8788
|}
8889
|}""".stripMargin,
8990
filter = _.contains("exhaustive")

presentation-compiler/test/dotty/tools/pc/tests/PcSemanticdbSuite.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ import org.junit.Test
99

1010
class PcSemanticdbSuite extends BasePCSuite:
1111

12-
override def requiresJdkSources: Boolean = true
13-
14-
override def requiresScalaLibrarySources: Boolean = true
15-
1612
@Test def `simple` =
1713
check(
1814
"""|package a

presentation-compiler/test/dotty/tools/pc/tests/SelectionRangeCommentSuite.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package dotty.tools.pc.tests
22

33
import dotty.tools.pc.base.BaseSelectionRangeSuite
44

5-
import org.junit.Ignore
65
import org.junit.Test
76

87
class SelectionRangeCommentSuite extends BaseSelectionRangeSuite:

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionDocSuite.scala

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import org.junit.{Ignore, Test}
66

77
@Ignore
88
class CompletionDocSuite extends BaseCompletionSuite:
9-
override def requiresJdkSources: Boolean = true
10-
override def requiresScalaLibrarySources: Boolean = true
119

1210
@Test def `java` =
1311
check(
@@ -58,70 +56,6 @@ class CompletionDocSuite extends BaseCompletionSuite:
5856
|""".stripMargin
5957
)
6058

61-
// @Test def `java5` =
62-
// check(
63-
// """
64-
// |object A {
65-
// | java.util.OptionalInt@@
66-
// |}
67-
// """.stripMargin,
68-
// if (isJava8)
69-
// """|> A container object which may or may not contain a `int` value.
70-
// |If a value is present, `isPresent()` will return `true` and
71-
// |`getAsInt()` will return the value.
72-
// |
73-
// |Additional methods that depend on the presence or absence of a contained
74-
// |value are provided, such as [orElse()](#orElse(int))
75-
// |(return a default value if value not present) and
76-
// |[ifPresent()](#ifPresent(java.util.function.IntConsumer)) (execute a block
77-
// |of code if the value is present).
78-
// |
79-
// |This is a [value-based]()
80-
// |class; use of identity-sensitive operations (including reference equality
81-
// |(`==`), identity hash code, or synchronization) on instances of
82-
// |`OptionalInt` may have unpredictable results and should be avoided.
83-
// |OptionalInt java.util
84-
// |""".stripMargin
85-
// else if (isJava17)
86-
// """|> A container object which may or may not contain an `int` value.
87-
// |If a value is present, `isPresent()` returns `true`. If no
88-
// |value is present, the object is considered *empty* and
89-
// |`isPresent()` returns `false`.
90-
// |
91-
// |Additional methods that depend on the presence or absence of a contained
92-
// |value are provided, such as [orElse()](#orElse(int))
93-
// |(returns a default value if no value is present) and
94-
// |[ifPresent()](#ifPresent(IntConsumer)) (performs an
95-
// |action if a value is present).
96-
// |
97-
// |This is a [value-based]()
98-
// |class; programmers should treat instances that are
99-
// |[equal](#equals(Object)) as interchangeable and should not
100-
// |use instances for synchronization, or unpredictable behavior may
101-
// |occur. For example, in a future release, synchronization may fail.
102-
// |OptionalInt java.util
103-
// |""".stripMargin
104-
// else
105-
// """|> A container object which may or may not contain an `int` value.
106-
// |If a value is present, `isPresent()` returns `true`. If no
107-
// |value is present, the object is considered *empty* and
108-
// |`isPresent()` returns `false`.
109-
// |
110-
// |Additional methods that depend on the presence or absence of a contained
111-
// |value are provided, such as [orElse()](#orElse(int))
112-
// |(returns a default value if no value is present) and
113-
// |[ifPresent()](#ifPresent(IntConsumer)) (performs an
114-
// |action if a value is present).
115-
// |
116-
// |This is a [value-based]()
117-
// |class; use of identity-sensitive operations (including reference equality
118-
// |(`==`), identity hash code, or synchronization) on instances of
119-
// |`OptionalInt` may have unpredictable results and should be avoided.
120-
// |OptionalInt java.util
121-
// |""".stripMargin,
122-
// includeDocs = true,
123-
// )
124-
12559
@Test def `scala` =
12660
check(
12761
"""

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionMatchSuite.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ package dotty.tools.pc.tests.completion
33
import dotty.tools.pc.base.BaseCompletionSuite
44

55
import org.junit.Test
6+
import dotty.tools.pc.utils.MockEntries
67

78
class CompletionMatchSuite extends BaseCompletionSuite:
8-
override def requiresScalaLibrarySources: Boolean = true
9+
10+
override protected def mockEntries = new MockEntries:
11+
override def definitionSourceTopLevels = Map[String, List[String]](
12+
"scala/Option#" -> List("scala/Some.", "scala/None."),
13+
)
914

1015
@Test def `match` =
1116
check(

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionOverrideSuite.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package dotty.tools.pc.tests.completion
22

3+
import scala.meta.pc.SymbolDocumentation
4+
35
import dotty.tools.pc.base.BaseCompletionSuite
6+
import dotty.tools.pc.utils.MockEntries
47

58
import org.junit.Test
69

710
class CompletionOverrideSuite extends BaseCompletionSuite:
811

9-
override def requiresJdkSources: Boolean = true
10-
11-
override def requiresScalaLibrarySources: Boolean = true
12+
override protected def mockEntries: MockEntries = new MockEntries:
13+
override def documentations: Set[SymbolDocumentation] = Set(
14+
MockDocumentation("java/nio/file/SimpleFileVisitor#visitFile().", "visitFile", Seq(), Seq("file", "attrs"))
15+
)
1216

1317
@Test def `basic` =
1418
checkEdit(

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSuite.scala

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
package dotty.tools.pc.tests.completion
22

3+
import scala.meta.pc.SymbolDocumentation
4+
35
import dotty.tools.pc.base.BaseCompletionSuite
6+
import dotty.tools.pc.utils.MockEntries
47

5-
import org.junit.rules.{RuleChain, TestRule, TestWatcher}
6-
import org.junit.runner.Description
7-
import org.junit.{Ignore, Test}
8+
import org.junit.Test
89

910
class CompletionSuite extends BaseCompletionSuite:
1011

11-
override def requiresJdkSources: Boolean = true
12+
override protected def mockEntries: MockEntries = new MockEntries:
13+
override def documentations: Set[SymbolDocumentation] = Set(
14+
MockDocumentation("java/lang/String#substring().", "substring", Seq(), Seq("beginIndex")),
15+
MockDocumentation("java/lang/String#substring(+1).", "substring", Seq(), Seq("beginIndex", "endIndex")),
16+
MockDocumentation("java/nio/file/Files#readAttributes().", "readAttributes", Seq("A"), Seq("path", "type", "options")),
17+
MockDocumentation("java/nio/file/Files#readAttributes(+1).", "readAttributes", Seq(), Seq("path", "attributes", "options"))
18+
)
1219

1320
@Test def scope =
1421
check(
@@ -17,7 +24,7 @@ class CompletionSuite extends BaseCompletionSuite:
1724
| Lis@@
1825
|}""".stripMargin,
1926
"""
20-
|List: scala.collection.immutable
27+
|List scala.collection.immutable
2128
|List - java.awt
2229
|List - java.util
2330
|List - scala.collection.immutable
@@ -84,7 +91,6 @@ class CompletionSuite extends BaseCompletionSuite:
8491
"""|empty[A]: List[A]
8592
|from[B](coll: IterableOnce[B]): List[B]
8693
|newBuilder[A]: Builder[A, List[A]]
87-
|ordinal(x$0: MirroredMonoType): Int
8894
|apply[A](elems: A*): List[A]
8995
|concat[A](xss: Iterable[A]*): List[A]
9096
|fill[A](n1: Int, n2: Int)(elem: => A): List[List[A] @uncheckedVariance]
@@ -650,7 +656,7 @@ class CompletionSuite extends BaseCompletionSuite:
650656
|}
651657
|""".stripMargin,
652658
"""|None scala
653-
|NoManifest: scala.reflect
659+
|NoManifest scala.reflect
654660
|""".stripMargin,
655661
topLines = Some(2)
656662
)
@@ -663,8 +669,8 @@ class CompletionSuite extends BaseCompletionSuite:
663669
|}
664670
|""".stripMargin,
665671
"""|Some(value) scala
666-
|Seq: scala.collection.immutable
667-
|Set: scala.collection.immutable
672+
|Seq scala.collection.immutable
673+
|Set scala.collection.immutable
668674
|""".stripMargin,
669675
topLines = Some(3)
670676
)
@@ -677,8 +683,8 @@ class CompletionSuite extends BaseCompletionSuite:
677683
|}
678684
|""".stripMargin,
679685
"""|Some[?] scala
680-
|Seq: scala.collection.immutable
681-
|Set: scala.collection.immutable
686+
|Seq scala.collection.immutable
687+
|Set scala.collection.immutable
682688
|""".stripMargin,
683689
topLines = Some(3)
684690
)
@@ -699,7 +705,7 @@ class CompletionSuite extends BaseCompletionSuite:
699705
|""".stripMargin,
700706
"""|NotString: Int
701707
|Number: Regex
702-
|Nil: scala.collection.immutable
708+
|Nil scala.collection.immutable
703709
|""".stripMargin,
704710
topLines = Option(3)
705711
)
@@ -713,8 +719,8 @@ class CompletionSuite extends BaseCompletionSuite:
713719
|}
714720
|""".stripMargin,
715721
"""|Number: Regex
716-
|Nil: scala.collection.immutable
717-
|NoManifest: scala.reflect
722+
|Nil scala.collection.immutable
723+
|NoManifest scala.reflect
718724
|""".stripMargin,
719725
topLines = Option(3)
720726
)
@@ -728,8 +734,8 @@ class CompletionSuite extends BaseCompletionSuite:
728734
|}
729735
|""".stripMargin,
730736
"""|Number: Regex
731-
|Nil: scala.collection.immutable
732-
|NoManifest: scala.reflect
737+
|Nil scala.collection.immutable
738+
|NoManifest scala.reflect
733739
|""".stripMargin,
734740
topLines = Option(3)
735741
)

0 commit comments

Comments
 (0)