Skip to content
This repository has been archived by the owner. It is now read-only.

[Sponsored] scala 2.12 #1703

Merged
merged 23 commits into from Jan 21, 2017
Merged
Changes from 13 commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -37,5 +37,6 @@ pipeline:

matrix:
SCALA_VERSION:
- 2.12.0
- 2.11.8
- 2.10.6

Large diffs are not rendered by default.

@@ -457,10 +457,20 @@ class SemanticHighlightingSpec extends EnsimeSpec
""",
List(ValFieldSymbol)
)
sds should ===(List(
(ValFieldSymbol, "u"),
(ValFieldSymbol, "v")
))
sds should (
// 2.10 & 2.11 case
equal(List(
(ValFieldSymbol, "u"),
(ValFieldSymbol, "v")
)) or
// 2.12 case
equal(List(
(ValFieldSymbol, "u"),
(ValFieldSymbol, "v"),
(ValFieldSymbol, "u"),
(ValFieldSymbol, "v")
))
)
}

it should "highlight setter operators" in withPresCompiler { (config, cc) =>
@@ -152,9 +152,9 @@ class SearchServiceSpec extends EnsimeSpec
it should "not prioritise noisy inner classes" in withSearchService { implicit service =>
def nonTrailingDollarSigns(fqn: String): Int = fqn.count(_ == '$') - (if (fqn.endsWith("$")) 1 else 0)
def isSorted(hits: Seq[String]): Boolean =
hits.sliding(2).map {
hits.sliding(2).forall {
case List(x, y) => nonTrailingDollarSigns(x) <= nonTrailingDollarSigns(y)
}.forall(identity)
}

val sorted = new BeMatcher[Seq[String]] {
override def apply(left: Seq[String]): MatchResult =
@@ -183,7 +183,7 @@ class SearchServiceSpec extends EnsimeSpec
)
matchersHits should be(sorted)

val regexHits = service.searchClasses("Regex", 10).map(_.fqn)
val regexHits = service.searchClasses("Regex", 8).map(_.fqn)
regexHits.take(2) should contain theSameElementsAs Seq(
"scala.util.matching.Regex",
"scala.util.matching.Regex$"
@@ -209,11 +209,11 @@ class SearchServiceSpec extends EnsimeSpec
}

"lucene index" should "not contain duplicates" in withSearchService { implicit service =>
import scala.collection.JavaConversions._
import scala.collection.JavaConverters._

This comment has been minimized.

Copy link
@fommil

fommil Jan 7, 2017

Contributor

argh, we should not have been using this in the first place

val lucene = service.index.lucene
val terms = List("org", "example", "bar")
val query = new DisjunctionMaxQuery(
terms.map(service.index.buildTermClassMethodQuery), 0f
terms.map(service.index.buildTermClassMethodQuery).asJavaCollection, 0f
)
val fqns = lucene.search(query, 10).map(_.get("fqn"))
fqns.distinct should ===(fqns)

Large diffs are not rendered by default.

@@ -187,7 +187,7 @@ class DebugTest extends EnsimeSpec
withDebugSession(
"variables.ReadVariables",
"variables/ReadVariables.scala",
21
22
) { (threadId, variablesFile) =>
// boolean local
getVariableValue(threadId, "a") should matchPattern {
@@ -238,14 +238,11 @@ class DebugTest extends EnsimeSpec
}

// type local
inside(getVariableValue(threadId, "j")) {
case DebugObjectInstance(summary, debugFields, "scala.collection.immutable.$colon$colon", _) =>
summary should startWith("Instance of scala.collection.immutable.$colon$colon")
inside(getVariableValue(threadId, "m")) {
case DebugObjectInstance(summary, debugFields, "variables.ReadVariables$SimpleTestClass", _) =>
summary should startWith("Instance of variables.ReadVariables$SimpleTestClass")
exactly(1, debugFields) should matchPattern {
case DebugClassField(_, head, "java.lang.Object", summary) if (
(head == "head" || head == "hd") &&
summary.startsWith("Instance of java.lang.Integer")
) =>
case DebugClassField(_, "xs", "scala.collection.immutable.List", summary) if summary.startsWith("Instance of scala.collection.immutable.$colon$colon") =>
}
}

@@ -265,7 +262,7 @@ class DebugTest extends EnsimeSpec
withDebugSession(
"variables.ReadVariables",
"variables/ReadVariables.scala",
21
22
) { (threadId, variablesFile) =>
// boolean local
getVariableAsString(threadId, "a").text should be("true")
@@ -0,0 +1,17 @@
// Copyright: 2010 - 2017 https://github.com/ensime/ensime-server/graphs
// License: http://www.gnu.org/licenses/gpl-3.0.en.html
package org.ensime.core

trait DocResolverBackCompat {
def scalaSigToLocalUri(prefix: String, jarName: String, scalaSig: DocSig): String = {
val anchor = scalaSig.fqn.mkString +
scalaSig.member.map("@" + _).getOrElse("")
s"$prefix/$jarName/index.html#$anchor"
}

def scalaFqnToPath(fqn: DocFqn): String = {
if (fqn.typeName == "package") {
fqn.pack.replace(".", "/") + "/package.html"
} else fqn.pack.replace(".", "/") + "/" + fqn.typeName + ".html"
}
}
@@ -0,0 +1,19 @@
// Copyright: 2010 - 2017 https://github.com/ensime/ensime-server/graphs
// License: http://www.gnu.org/licenses/gpl-3.0.en.html
package org.ensime.core

import scala.tools.refactoring.implementations.OrganizeImports

trait ScalaRefactoringBackCompat {

def organizeImportOptions(refactoring: OrganizeImports) = {
import refactoring._
List(
SortImports,
SimplifyWildcards,
SortImportSelectors,
RemoveDuplicates
)
}

}
@@ -0,0 +1,7 @@
// Copyright: 2010 - 2017 https://github.com/ensime/ensime-server/graphs
// License: http://www.gnu.org/licenses/gpl-3.0.en.html
package org.ensime.database

object SlickBackCompat {
val h2Api = slick.driver.H2Driver.api
}
@@ -0,0 +1,17 @@
// Copyright: 2010 - 2017 https://github.com/ensime/ensime-server/graphs
// License: http://www.gnu.org/licenses/gpl-3.0.en.html
package org.ensime.core

trait DocResolverBackCompat {
def scalaSigToLocalUri(prefix: String, jarName: String, scalaSig: DocSig): String = {
val anchor = scalaSig.fqn.mkString +
scalaSig.member.map("@" + _).getOrElse("")
s"$prefix/$jarName/index.html#$anchor"
}

def scalaFqnToPath(fqn: DocFqn): String = {
if (fqn.typeName == "package") {
fqn.pack.replace(".", "/") + "/package.html"
} else fqn.pack.replace(".", "/") + "/" + fqn.typeName + ".html"
}
}
@@ -0,0 +1,19 @@
// Copyright: 2010 - 2017 https://github.com/ensime/ensime-server/graphs
// License: http://www.gnu.org/licenses/gpl-3.0.en.html
package org.ensime.core

import scala.tools.refactoring.implementations.OrganizeImports

trait ScalaRefactoringBackCompat {

def organizeImportOptions(refactoring: OrganizeImports) = {
import refactoring._
List(
SortImports,
SimplifyWildcards,
SortImportSelectors,
RemoveDuplicates
)
}

}
@@ -0,0 +1,7 @@
// Copyright: 2010 - 2017 https://github.com/ensime/ensime-server/graphs
// License: http://www.gnu.org/licenses/gpl-3.0.en.html
package org.ensime.database

object SlickBackCompat {
val h2Api = slick.jdbc.H2Profile.api
}
@@ -0,0 +1,17 @@
// Copyright: 2010 - 2017 https://github.com/ensime/ensime-server/graphs
// License: http://www.gnu.org/licenses/gpl-3.0.en.html
package org.ensime.core

trait DocResolverBackCompat {
def scalaSigToLocalUri(prefix: String, jarName: String, scalaSig: DocSig): String = {
val anchor = scalaFqnToPath(scalaSig.fqn) +
scalaSig.member.map("#" + _).getOrElse("")
s"$prefix/$jarName/$anchor"
}

def scalaFqnToPath(fqn: DocFqn): String = {
if (fqn.typeName == "package") {
fqn.pack.replace(".", "/") + "/index.html"
} else fqn.pack.replace(".", "/") + "/" + fqn.typeName + ".html"
}
}
@@ -0,0 +1,21 @@
// Copyright: 2010 - 2017 https://github.com/ensime/ensime-server/graphs
// License: http://www.gnu.org/licenses/gpl-3.0.en.html
package org.ensime.core

import Predef.{ any2stringadd => _ }

import scala.reflect.internal.util.Position

/**
* Simulate methods that were added in later versions of the scalac
* API, or to generate fake methods that we can use in both versions.
*/
trait PresentationCompilerBackCompat

trait PositionBackCompat {
implicit class RichPosition(pos: Position) {
// annoyingly, {start, end}OrPoint is deprecated
def startOrCursor: Int = if (pos.isRange) pos.start else pos.point
def endOrCursor: Int = if (pos.isRange) pos.end else pos.point
}
}
@@ -0,0 +1,18 @@
// Copyright: 2010 - 2017 https://github.com/ensime/ensime-server/graphs
// License: http://www.gnu.org/licenses/gpl-3.0.en.html
package org.ensime.core

import scala.tools.refactoring.implementations.OrganizeImports

trait ScalaRefactoringBackCompat {

def organizeImportOptions(refactoring: OrganizeImports) = {
import refactoring.oiWorker.participants._
List(
SortImports,
SortImportSelectors,
RemoveDuplicates
)
}

}
@@ -0,0 +1,7 @@
// Copyright: 2010 - 2017 https://github.com/ensime/ensime-server/graphs
// License: http://www.gnu.org/licenses/gpl-3.0.en.html
package org.ensime.database

object SlickBackCompat {
val h2Api = slick.jdbc.H2Profile.api
}
@@ -9,12 +9,15 @@ import java.util.jar.JarFile
import org.ensime.api._

class DocResolver(
prefix: String,
forceJavaVersion: Option[String] // for testing
prefix: String,
forceJavaVersion: Option[String] // for testing
)(
implicit
config: EnsimeConfig
) extends Actor with ActorLogging with DocUsecaseHandling {
implicit
config: EnsimeConfig
) extends Actor
with ActorLogging
with DocUsecaseHandling
with DocResolverBackCompat {

var htmlToJar = Map.empty[String, File]
var jarNameToJar = Map.empty[String, File]
@@ -79,12 +82,6 @@ class DocResolver(
}
}

def scalaFqnToPath(fqn: DocFqn): String = {
if (fqn.typeName == "package") {
fqn.pack.replace(".", "/") + "/package.html"
} else fqn.pack.replace(".", "/") + "/" + fqn.typeName + ".html"
}

private def makeLocalUri(jar: File, sig: DocSigPair): String = {
val jarName = jar.getName
val docType = docTypes(jarName)
@@ -97,9 +94,7 @@ class DocResolver(
s"$prefix/$jarName/$path$anchor"
} else {
val scalaSig = maybeReplaceWithUsecase(jar, sig.scala)
val anchor = scalaSig.fqn.mkString +
scalaSig.member.map("@" + _).getOrElse("")
s"$prefix/$jarName/index.html#$anchor"
scalaSigToLocalUri(prefix, jarName, scalaSig)
}
}

@@ -31,7 +31,8 @@ trait DocUsecaseHandling { self: DocResolver =>
try {
val is = jarFile.getInputStream(jarFile.getEntry(scalaFqnToPath(sig.fqn)))
val html = Source.fromInputStream(is).mkString
val re = s"""<a id="(${Pattern.quote(prefix)}.+?)"""".r
// val re = s"""<a id="(${Pattern.quote(prefix)}.+?)"""".r
val re = s"""<a id="(${Pattern.quote(prefix)}[^a-zA-Z\\d].*?)"""".r
re.findFirstMatchIn(html).map { m =>
sig.copy(member = Some(StringEscapeUtils.unescapeHtml(m.group(1))))
}.getOrElse(sig)
@@ -3,10 +3,12 @@
package org.ensime.core

import java.nio.charset.Charset

import org.ensime.api._
import org.ensime.util.FileUtils._
import org.ensime.util._
import org.ensime.util.file.File

import scala.tools.nsc.io.AbstractFile
import scala.tools.refactoring._
import scala.tools.refactoring.analysis.GlobalIndexes
@@ -81,7 +83,8 @@ trait RefactoringControl { self: RichCompilerControl with RefactoringImpl =>

}

trait RefactoringImpl { self: RichPresentationCompiler =>
trait RefactoringImpl extends ScalaRefactoringBackCompat {
self: RichPresentationCompiler =>

import org.ensime.util.FileUtils._

@@ -91,7 +94,7 @@ trait RefactoringImpl { self: RichPresentationCompiler =>
val global = RefactoringImpl.this
val invalidSet = toBeRemoved.synchronized { toBeRemoved.toSet }
val cuIndexes = this.global.activeUnits().map { u => CompilationUnitIndex(u.body) }
val index = GlobalIndex(cuIndexes.toList)
val index = GlobalIndex(cuIndexes)
}
val result = performRefactoring(procId, tpe, name)
}.result
@@ -102,7 +105,7 @@ trait RefactoringImpl { self: RichPresentationCompiler =>
val refactoring = new ExtractMethod with GlobalIndexes {
val global = RefactoringImpl.this
val cuIndexes = this.global.activeUnits().map { u => CompilationUnitIndex(u.body) }
val index = GlobalIndex(cuIndexes.toList)
val index = GlobalIndex(cuIndexes)
}
val result = performRefactoring(procId, tpe, name)
}.result
@@ -113,7 +116,7 @@ trait RefactoringImpl { self: RichPresentationCompiler =>
val refactoring = new ExtractLocal with GlobalIndexes {
val global = RefactoringImpl.this
val cuIndexes = this.global.activeUnits().map { u => CompilationUnitIndex(u.body) }
val index = GlobalIndex(cuIndexes.toList)
val index = GlobalIndex(cuIndexes)
}
val result = performRefactoring(procId, tpe, name)
}.result
@@ -124,7 +127,7 @@ trait RefactoringImpl { self: RichPresentationCompiler =>
val refactoring = new InlineLocal with GlobalIndexes {
val global = RefactoringImpl.this
val cuIndexes = this.global.activeUnits().map { u => CompilationUnitIndex(u.body) }
val index = GlobalIndex(cuIndexes.toList)
val index = GlobalIndex(cuIndexes)
}
val result = performRefactoring(procId, tpe, new refactoring.RefactoringParameters())
}.result
@@ -136,12 +139,7 @@ trait RefactoringImpl { self: RichPresentationCompiler =>
}

val result = performRefactoring(procId, tpe, new refactoring.RefactoringParameters(
options = List(
refactoring.SortImports,
refactoring.SortImportSelectors,
refactoring.SimplifyWildcards,
refactoring.RemoveDuplicates
),
options = organizeImportOptions(refactoring),
config = Some(OrganizeImports.OrganizeImportsConfig(
importsStrategy = Some(OrganizeImports.ImportsStrategy.CollapseImports),
groups = List("java", "scala")
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.