Skip to content
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

Upgrade to Scalameta v3.7 #275

Closed
wants to merge 25 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0aba1e2
Upgrade build dependency
olafurpg Apr 9, 2018
633bbc2
Fix all compile errors
olafurpg Apr 9, 2018
0ea9e56
Fix compile errors in tests
olafurpg Apr 10, 2018
3431fb7
Fix workspace/symbol by removing protobuf generation.
olafurpg Apr 10, 2018
4ec168f
Add note on package objects for workspace/symbol
olafurpg Apr 10, 2018
17380e8
Compute definition on the fly for local symbols.
olafurpg Apr 10, 2018
5eba30c
Fix indexing for local symbols.
olafurpg Apr 10, 2018
afa835e
Don't index message-only documents.
olafurpg Apr 10, 2018
b37d634
Fix mtags tests
olafurpg Apr 10, 2018
d413039
Fix remaining test cases.
olafurpg Apr 10, 2018
15b667a
Fix remaining deprecation warnings
olafurpg Apr 10, 2018
3f8c0b7
Address comment
olafurpg Apr 10, 2018
63487bf
Fix CI failures
olafurpg Apr 10, 2018
45abbe3
Upgrade scalafix dependency
olafurpg Apr 13, 2018
df272a6
Handle method overloads in Scala mtags.
amarrella Apr 15, 2018
bce8dd9
Handle conflicting method overlaods.
olafurpg Apr 15, 2018
ed9bb9d
Emit method symbols for val/var to be compliant with spec
olafurpg Apr 15, 2018
3fd7262
Emit correct disambiguator for singleton type
olafurpg Apr 15, 2018
7a3e0bf
Use scalafix PrettyType for HoverProvider
olafurpg Apr 20, 2018
525039c
Fix scalafix integration.
olafurpg Apr 20, 2018
1f6ec39
Polish new Hover implementation
olafurpg Apr 20, 2018
b20a6c9
Add more relevant tests for hover
olafurpg Apr 21, 2018
317fd60
Document hover requires metalsSetup
olafurpg Apr 21, 2018
0c9d0fc
Log slightly more helpful error message on failure to parse proto file
olafurpg Apr 21, 2018
42765d7
Address review feedback and polish.
olafurpg Apr 21, 2018
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
Prev Previous commit
Next Next commit
Polish new Hover implementation
- Include JDK classpath
- Document blocking issues
olafurpg committed May 6, 2018
commit 1f6ec3927d551f0cf1fdd9ce109925cebec4cc71
Original file line number Diff line number Diff line change
@@ -26,7 +26,11 @@ class MetacpProvider {
.process(Settings().withScalaLibrarySynthetics(true), reporter)
.get
.shallow
.head
private val jdk = Metacp
.process(settings.withClasspath(ClasspathOps.bootClasspath), reporter)
.getOrElse {
throw new IllegalArgumentException("Failed to process JDK")
}
private val empty = AbsolutePath(Files.createTempDirectory("metals"))
private val processEntry = new function.Function[AbsolutePath, AbsolutePath] {
override def apply(t: AbsolutePath): AbsolutePath = {
@@ -44,61 +48,26 @@ class MetacpProvider {
}

def process(classpath: Classpath): Classpath = {
Classpath(synthetics :: classpath.shallow.map { entry =>
val processed = classpath.shallow.map { entry =>
if (entry.isDirectory) entry
else classpaths.computeIfAbsent(entry, processEntry)
})
}
Classpath(List(synthetics, jdk.shallow, processed).flatten)
}

}

object ClasspathOps {

def bootClasspath: Option[Classpath] = sys.props.collectFirst {
case (k, v) if k.endsWith(".boot.class.path") => Classpath(v)
}

val devNull = new PrintStream(new OutputStream {
override def write(b: Int): Unit = ()
})

/** Process classpath with metacp to build semanticdbs of global symbols. **/
def toMetaClasspath(
sclasspath: Classpath,
cacheDirectory: Option[AbsolutePath] = None,
parallel: Boolean = true,
out: PrintStream = devNull
): Option[Classpath] = {
val (processed, toProcess) = sclasspath.shallow.partition { path =>
path.isDirectory &&
path.resolve("META-INF").resolve("semanticdb.semanticidx").isFile
}
val withJDK = Classpath(
bootClasspath.fold(sclasspath.shallow)(_.shallow ::: toProcess)
)
val default = metacp.Settings()
val settings = default
.withClasspath(withJDK)
.withScalaLibrarySynthetics(true)
.withCacheDir(cacheDirectory.getOrElse(default.cacheDir))
.withPar(parallel)
val reporter = metacp
.Reporter()
.withOut(devNull) // out prints classpath of proccessed classpath, which is not relevant for scalafix.
.withErr(out)
val mclasspath = scala.meta.cli.Metacp.process(settings, reporter)
mclasspath.map(x => Classpath(x.shallow ++ processed))
}

def newSymbolTable(
classpath: Classpath,
cacheDirectory: Option[AbsolutePath] = None,
parallel: Boolean = true,
out: PrintStream = System.out
): Option[SymbolTable] = {
toMetaClasspath(classpath, cacheDirectory, parallel, out)
.map(new LazySymbolTable(_))
}
def bootClasspath: Classpath =
sys.props
.collectFirst {
case (k, v) if k.endsWith(".boot.class.path") =>
Classpath(
Classpath(v).shallow.filter(p => Files.exists(p.toNIO))
)
}
.getOrElse(Classpath(Nil))

def getCurrentClasspath: Classpath = {
Thread.currentThread.getContextClassLoader match {
Original file line number Diff line number Diff line change
@@ -59,10 +59,14 @@ object HoverProvider extends LazyLogging {
info.symbol.stripSuffix(".").parse[Term].get.asInstanceOf[Term.Ref]
Pkg(ref, Nil)
} else if (info.kind.isTrait) {
// TODO: include type parameters
Defn.Trait(mods, Type.Name(info.name), Nil, EmptyCtor, EmptyTemplate)
} else if (info.kind.isClass) {
// TODO: include type parameters and primary constructor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry about TODO vs tickets. Consider creating issues for these and referencing the issue in the TODO comment.

Defn.Class(mods, Type.Name(info.name), Nil, EmptyCtor, EmptyTemplate)
} else if (info.kind.isLocal || info.symbol.startsWith("local")) {
// Workaround for https://github.com/scalameta/scalameta/issues/1503
// In the future we should be able to produce `val x: Int` syntax for local symbols.
PrettyType.toType(info.tpe.get, symtab, QualifyStrategy.Readable).tree
} else {
PrettyType.toTree(info, symtab, QualifyStrategy.Readable).tree
13 changes: 13 additions & 0 deletions metals/src/test/scala/tests/provider/HoverProviderTest.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package tests.provider

import java.util

object HoverProviderTest extends BaseHoverProviderTest {

check(
@@ -307,4 +309,15 @@ object HoverProviderTest extends BaseHoverProviderTest {
""".stripMargin,
"sealed trait W"
)

check(
"jdk",
"""
|object x {
| val <<entry>> =
| new java.util.HashMap[java.lang.Integer, java.lang.String]().entrySet()
|}
""".stripMargin,
"val entry: Set[Map.Entry[Integer, String]]"
)
}