-
Notifications
You must be signed in to change notification settings - Fork 182
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 3.7.0 with default settings. #675
Changes from all commits
cc9d864
7c733f0
9dcf454
3da338d
f3653e4
7e1b69b
7845d60
25b8d27
ef47a2d
5414a5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,54 @@ | ||
package scalafix.internal.cli | ||
|
||
import java.io.File | ||
import java.io.OutputStream | ||
import java.io.PrintStream | ||
import org.langmeta.io.AbsolutePath | ||
import scala.meta.Classpath | ||
import scala.meta.metacp | ||
import scalafix.internal.util.LazySymbolTable | ||
import scalafix.internal.util.SymbolTable | ||
|
||
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], | ||
parallel: Boolean, // unused until we upgrade scalameta for https://github.com/scalameta/scalameta/pull/1474 | ||
out: PrintStream): Option[Classpath] = { | ||
val withJDK = Classpath( | ||
bootClasspath.fold(sclasspath.shallow)(_.shallow ::: sclasspath.shallow)) | ||
val default = metacp.Settings() | ||
val settings = default | ||
.withClasspath(withJDK) | ||
.withScalaLibrarySynthetics(true) | ||
.withCacheDir(cacheDirectory.getOrElse(default.cacheDir)) | ||
val reporter = metacp | ||
.Reporter() | ||
.withOut(devNull) // out prints classpath of proccessed classpath, which is not relevant for scalafix. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh, this is unfortunate, given that we're calling |
||
.withErr(out) | ||
val mclasspath = scala.meta.cli.Metacp.process(settings, reporter) | ||
mclasspath | ||
} | ||
|
||
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 getCurrentClasspath: String = { | ||
Thread.currentThread.getContextClassLoader match { | ||
case url: java.net.URLClassLoader => | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,12 +55,30 @@ case class ScalafixOptions( | |
sourceroot: Option[String] = None, | ||
@HelpMessage( | ||
"java.io.File.pathSeparator separated list of directories or jars containing " + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a list or a single directory? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It remains a list, unchanged from the previous behavior of --classpath. I've renamed it back to --classpath and added more details about --dependency-classpath. |
||
"'.semanticdb' files. The 'semanticdb' files are emitted by the " + | ||
"META-INF/semanticdb/**/*.semanticdb files. SemanticDB files are emitted by the " + | ||
"semanticdb-scalac compiler plugin and are necessary for semantic rules " + | ||
"like ExplicitResultTypes to function." | ||
) | ||
@ValueDescription("entry1.jar:entry2.jar:target/scala-2.12/classes/") | ||
classpath: Option[String] = None, | ||
@HelpMessage( | ||
"Same as --classpath except for dependencies that do not need to be compiled with SemanticDB. " + | ||
"Must be accompanied with --classpath. " + | ||
"This option is required for rules like ExplicitResultTypes to lookup symbol information from the classpath." + | ||
"This option is processed with metacp and produced artifacts are globally cached using --metacp-cache-dir" | ||
) | ||
@ValueDescription("entry1.jar:entry2.jar:target/scala-2.12/classes/") | ||
dependencyClasspath: Option[String] = None, | ||
@HelpMessage( | ||
"Global cache location to persist metacp artifacts produced by analyzing --dependency-classpath. " + | ||
"The default location depends on the OS and is computed with https://github.com/soc/directories-jvm " + | ||
"using the project name 'semanticdb'. " + | ||
"On macOS the default cache directory is ~/Library/Caches/semanticdb. ") | ||
metacpCacheDir: Option[String] = None, | ||
@HelpMessage( | ||
"Set this flag to disable parallel processing with metacp. " + | ||
"Metacp uses the standard library parallel collections, which may enter deadlocks.") | ||
metacpNoPar: Boolean = false, | ||
@HelpMessage( | ||
"Automatically infer --classpath starting from these directories. " + | ||
"Ignored if --classpath is provided.") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import scalafix.syntax._ | |
import scalafix.util.TokenOps | ||
import metaconfig.Conf | ||
import metaconfig.Configured | ||
import org.langmeta.internal.semanticdb.XtensionDenotationsInternal | ||
|
||
case class ExplicitResultTypes( | ||
index: SemanticdbIndex, | ||
|
@@ -74,9 +75,16 @@ case class ExplicitResultTypes( | |
def defnType(defn: Defn): Option[(Type, Patch)] = | ||
for { | ||
name <- defnName(defn) | ||
symbol <- name.symbol | ||
typ <- symbol.resultType | ||
} yield TypeSyntax.prettify(typ, ctx, config.unsafeShortenNames) | ||
denot <- name.denotation | ||
tpe <- denot.tpeInternal | ||
// Skip existential types for now since they cause problems. | ||
if !tpe.tag.isExistentialType | ||
result <- TypeSyntax.prettify( | ||
tpe, | ||
ctx, | ||
config.unsafeShortenNames, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this config passed? https://scalacenter.github.io/scalafix/docs/users/configuration shows how to add rules to the scalafix config, but does not show if it is possible to pass rule specific config. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's configuration for ExplicitResultTypes documented here https://scalacenter.github.io/scalafix/docs/rules/ExplicitResultTypes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn’t able to put that together from the docs for some reason but I get it now, thanks. |
||
name.pos) | ||
} yield result | ||
import scala.meta._ | ||
def fix(defn: Defn, body: Term): Patch = { | ||
val lst = ctx.tokenList | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this formatting change intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, for consistency with the changes below