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

sbt-scalafix 0.13.0 #6810

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .scalafix3.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
rules = [
OrganizeImports
OrganizeImports,
ExplicitResultTypes
]

OrganizeImports.groupedImports = Explode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import dotty.tools.dotc.printing.Texts.Text
but haven't managed to port all of them yet to the LTS */
abstract class RefinedDotcPrinter(_ctx: Context) extends RefinedPrinter(_ctx):

def toTextPrefix(tp: Type) =
def toTextPrefix(tp: Type): Text =
tp match
case tp: NamedType => super.toTextPrefixOf(tp)
case tp => Text()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import dotty.tools.dotc.ast.NavigateAST
import dotty.tools.dotc.ast.untpd.ExtMethods
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.util.Spans.Span
import dotty.tools.dotc.ast.Positioned

object MetalsNavigateAST:
def pathToExtensionParam(span: Span, methods: ExtMethods)(using Context) =
def pathToExtensionParam(span: Span, methods: ExtMethods)(using Context): List[Positioned] =
NavigateAST.pathTo(span, methods.paramss.flatten)
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import dotty.tools.dotc.core.Types.*
import dotty.tools.dotc.interactive.Interactive
import dotty.tools.dotc.interactive.InteractiveDriver
import dotty.tools.dotc.util.SourcePosition
import dotty.tools.dotc.ast.Trees.Tree

object HoverProvider:

Expand Down Expand Up @@ -208,7 +209,7 @@ object HoverProvider:
end HoverProvider

object SelectDynamicExtractor:
def unapply(path: List[Tree])(using Context) =
def unapply(path: List[Tree])(using Context): Option[(Tree[Type | Null], Name, String)] =
path match
// the same tests as below, since 3.3.1-RC1 path starts with Select
case Select(_, _) :: Apply(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ object PcCollector:
// Folds over the tree as `DeepFolder` but `f` takes also the parent.
class DeepFolderWithParent[X](f: (X, Tree, Option[Tree]) => X):
private val traverser = WithParentTraverser[X](f)
def apply(x: X, tree: Tree)(using Context) =
def apply(x: X, tree: Tree)(using Context): X =
traverser.traverse(x, tree, None)
end PcCollector

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,28 @@ import dotty.tools.dotc.util.Spans.Span
import org.eclipse.lsp4j as l
import org.eclipse.lsp4j.InlayHint
import org.eclipse.lsp4j.InlayHintKind
import java.net.URI
import java.nio.file.Path
import dotty.tools.dotc.ast.Trees.Tree
import dotty.tools.dotc.ast.Trees.Untyped

class PcInlayHintsProvider(
driver: InteractiveDriver,
params: InlayHintsParams,
symbolSearch: SymbolSearch,
)(using ReportContext):

val uri = params.uri()
val filePath = Paths.get(uri)
val uri: URI = params.uri()
val filePath: Path = Paths.get(uri)
val sourceText = params.text
val text = sourceText.toCharArray()
val source =
val text: Array[Char] = sourceText.toCharArray()
val source: SourceFile =
SourceFile.virtual(filePath.toString, sourceText)
driver.run(uri, source)
given ctx: Context = driver.currentCtx
val unit = driver.latestRun
given InferredType.Text = InferredType.Text(text)
val pos = driver.sourcePosition(params)
val pos: SourcePosition = driver.sourcePosition(params)
given InlayHintsParams = params

def provide(): List[InlayHint] =
Expand Down Expand Up @@ -193,7 +197,7 @@ class PcInlayHintsProvider(
end PcInlayHintsProvider

object ImplicitConversion:
def unapply(tree: Tree)(using params: InlayHintsParams, ctx: Context) =
def unapply(tree: Tree)(using params: InlayHintsParams, ctx: Context): Option[(Symbol, SourcePosition)] =
if (params.implicitConversions()) {
tree match
case Apply(fun: Ident, args) if isSynthetic(fun) && args.exists(!_.span.isZeroExtent) =>
Expand All @@ -216,7 +220,7 @@ object ImplicitConversion:
end ImplicitConversion

object ImplicitParameters:
def unapply(tree: Tree)(using params: InlayHintsParams, ctx: Context) =
def unapply(tree: Tree)(using params: InlayHintsParams, ctx: Context): Option[(List[Symbol], SourcePosition, Boolean)] =
if (params.implicitParameters()) {
tree match
case Apply(fun, args)
Expand Down Expand Up @@ -246,7 +250,7 @@ object ImplicitParameters:
end ImplicitParameters

object ValueOf:
def unapply(tree: Tree)(using params: InlayHintsParams, ctx: Context) =
def unapply(tree: Tree)(using params: InlayHintsParams, ctx: Context): Option[(String, SourcePosition)] =
if (params.implicitParameters()) {
tree match
case Apply(ta @ TypeApply(fun, _), _)
Expand All @@ -263,7 +267,7 @@ object ValueOf:
end ValueOf

object TypeParameters:
def unapply(tree: Tree)(using params: InlayHintsParams, ctx: Context) =
def unapply(tree: Tree)(using params: InlayHintsParams, ctx: Context): Option[(List[Type], SourcePosition, Tree[Type | Null])] =
if (params.typeParameters()) {
tree match
case TypeApply(sel: Select, _)
Expand All @@ -287,7 +291,7 @@ object InferredType:
object Text:
def apply(text: Array[Char]): Text = text

def unapply(tree: Tree)(using params: InlayHintsParams, text: Text, ctx: Context) =
def unapply(tree: Tree)(using params: InlayHintsParams, text: Text, ctx: Context): Option[(Untyped, SourcePosition, dotty.tools.dotc.ast.Trees.ValDef[Untyped]) | ((Untyped, SourcePosition, dotty.tools.dotc.ast.Trees.DefDef[Untyped]) | (Type, SourcePosition, dotty.tools.dotc.ast.Trees.Bind[Untyped]))] =
if (params.inferredTypes()) {
tree match
case vd @ ValDef(_, tpe, _)
Expand Down Expand Up @@ -325,7 +329,7 @@ object InferredType:
/* If is left part of val definition bind:
* val <<t>> @ ... =
*/
def isValDefBind(text: Text, vd: ValDef)(using Context) =
def isValDefBind(text: Text, vd: ValDef)(using Context): Boolean =
val afterDef = text.drop(vd.nameSpan.end)
val index = indexAfterSpacesAndComments(afterDef)
index >= 0 && index < afterDef.size && afterDef(index) == '@'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ final class PcInlineValueProviderImpl(
end PcInlineValueProviderImpl

case class Occurence(tree: Tree, parent: Option[Tree], pos: SourcePosition):
def isDefn =
def isDefn: Boolean =
tree match
case _: ValDef => true
case _ => false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class PcRenameProvider(
else None
)

val newName = name.map(_.stripBackticks.backticked).getOrElse("newName")
val newName: String = name.map(_.stripBackticks.backticked).getOrElse("newName")

def collect(
parent: Option[Tree]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ import dotty.tools.dotc.core.Types.*
import dotty.tools.dotc.interactive.Interactive
import dotty.tools.dotc.util.SourcePosition
import dotty.tools.dotc.util.Spans.Span
import dotty.tools.dotc.ast.Trees.Tree
import dotty.tools.dotc.ast.Trees.Tree

trait PcSymbolSearch:
self: WithCompilationUnit =>

private val caseClassSynthetics: Set[Name] = Set(nme.apply, nme.copy)

lazy val rawPath =
lazy val rawPath: List[Tree[Type]] =
Interactive
.pathTo(driver.openedTrees(uri), pos)(using driver.currentCtx)
.dropWhile(t => // NamedArg anyway doesn't have symbol
Expand All @@ -35,12 +37,12 @@ trait PcSymbolSearch:
t.isInstanceOf[TypeTree]
)

lazy val extensionMethods =
lazy val extensionMethods: Option[ExtMethods] =
NavigateAST
.untypedPath(pos.span)(using compilatonUnitContext)
.collectFirst { case em @ ExtMethods(_, _) => em }

lazy val path = rawPath match
lazy val path: List[Tree[Type]] = rawPath match
// For type it will sometimes go into the wrong tree since TypeTree also contains the same span
// https://github.com/lampepfl/dotty/issues/15937
case TypeApply(sel: Select, _) :: tail if sel.span.contains(pos.span) =>
Expand Down Expand Up @@ -274,7 +276,7 @@ object PcSymbolSearch:
case sel: Select => sel.sourcePos.withSpan(selectNameSpan(sel))
case _ => tree.sourcePos

def isGeneratedGiven(df: NamedDefTree, sourceText: String)(using Context) =
def isGeneratedGiven(df: NamedDefTree, sourceText: String)(using Context): Boolean =
val nameSpan = df.nameSpan
df.symbol.is(Flags.Given) && sourceText.substring(
nameSpan.start,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Scala3CompilerWrapper(driver: MetalsDriver)

override def reporterAccess: ReporterAccess[StoreReporter] =
new ReporterAccess[StoreReporter]:
def reporter = driver.currentCtx.reporter.asInstanceOf[StoreReporter]
def reporter: StoreReporter = driver.currentCtx.reporter.asInstanceOf[StoreReporter]

override def askShutdown(): Unit = ()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ case class ScalaPresentationCompiler(
.map(StdReportContext(_, _ => buildTargetName, reportsLevel))
.getOrElse(EmptyReportContext)

override def withBuildTargetName(buildTargetName: String) =
override def withBuildTargetName(buildTargetName: String): PresentationCompiler =
copy(buildTargetName = Some(buildTargetName))

override def withReportsLoggerLevel(level: String): PresentationCompiler =
Expand Down Expand Up @@ -468,7 +468,7 @@ case class ScalaPresentationCompiler(
def withWorkspace(workspace: Path): PresentationCompiler =
copy(folderPath = Some(workspace))

override def isLoaded() = compilerAccess.isLoaded()
override def isLoaded(): Boolean = compilerAccess.isLoaded()

override def buildTargetId(): String = buildTargetIdentifier

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object SignatureHelpProvider:
driver: InteractiveDriver,
params: OffsetParams,
search: SymbolSearch,
) =
): l.SignatureHelp =
val uri = params.uri
val sourceFile = CompilerInterfaces.toSource(params.uri, params.text)
driver.run(uri, sourceFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,37 @@ import dotty.tools.dotc.core.NameOps.*
import dotty.tools.dotc.core.Symbols.*
import dotty.tools.dotc.interactive.InteractiveDriver
import dotty.tools.dotc.util.SourceFile
import java.net.URI
import java.nio.file.Path
import dotty.tools.dotc.util.SourcePosition

class WithCompilationUnit(
val driver: InteractiveDriver,
params: VirtualFileParams,
):
val uri = params.uri()
val filePath = Paths.get(uri)
val uri: URI = params.uri()
val filePath: Path = Paths.get(uri)
val sourceText = params.text
val text = sourceText.toCharArray()
val source =
val text: Array[Char] = sourceText.toCharArray()
val source: SourceFile =
SourceFile.virtual(filePath.toString, sourceText)
driver.run(uri, source)
given ctx: Context = driver.currentCtx

val unit = driver.latestRun
val compilatonUnitContext = ctx.fresh.setCompilationUnit(unit)
val offset = params match
val compilatonUnitContext: FreshContext = ctx.fresh.setCompilationUnit(unit)
val offset: Int = params match
case op: OffsetParams => op.offset()
case _ => 0
val offsetParams =
val offsetParams: OffsetParams =
params match
case op: OffsetParams => op
case _ =>
CompilerOffsetParams(params.uri(), params.text(), 0, params.token())
val pos = driver.sourcePosition(offsetParams)
val pos: SourcePosition = driver.sourcePosition(offsetParams)

// First identify the symbol we are at, comments identify @@ as current cursor position
def symbolAlternatives(sym: Symbol)(using Context) =
def symbolAlternatives(sym: Symbol)(using Context): Set[Symbol] =
def member(parent: Symbol) = parent.info.member(sym.name).symbol
def primaryConstructorTypeParam(owner: Symbol) =
for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ case class CompletionSuffix(
suffixes: Set[SuffixKind],
snippet: SuffixKind,
):
def addLabelSnippet = suffixes.contains(SuffixKind.Bracket)
def hasSnippet = snippet != SuffixKind.NoSuffix
def chain(copyFn: CompletionSuffix => CompletionSuffix) = copyFn(this)
def withNewSuffix(kind: SuffixKind) =
def addLabelSnippet: Boolean = suffixes.contains(SuffixKind.Bracket)
def hasSnippet: Boolean = snippet != SuffixKind.NoSuffix
def chain(copyFn: CompletionSuffix => CompletionSuffix): CompletionSuffix = copyFn(this)
def withNewSuffix(kind: SuffixKind): CompletionSuffix =
CompletionSuffix(suffixes + kind, snippet)
def withNewSuffixSnippet(kind: SuffixKind) =
def withNewSuffixSnippet(kind: SuffixKind): CompletionSuffix =
CompletionSuffix(suffixes + kind, kind)
def toEdit: String =
def loop(suffixes: List[SuffixKind]): String =
Expand All @@ -30,7 +30,7 @@ case class CompletionSuffix(
end CompletionSuffix

object CompletionSuffix:
val empty = CompletionSuffix(
val empty: CompletionSuffix = CompletionSuffix(
suffixes = Set.empty,
snippet = SuffixKind.NoSuffix,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Completions(
val coursierComplete = new CoursierComplete(BuildInfo.scalaCompilerVersion)

// versions prior to 3.1.0 sometimes didn't manage to detect properly Java objects
val canDetectJavaObjectsCorrectly =
val canDetectJavaObjectsCorrectly: Boolean =
SemVer.isLaterVersion("3.1.0", BuildInfo.scalaCompilerVersion)

private lazy val shouldAddSnippet =
Expand Down Expand Up @@ -843,7 +843,7 @@ class Completions(
def postProcess(items: List[CompletionValue]): List[CompletionValue]

object CompletionApplication:
val empty = new CompletionApplication:
val empty: CompletionApplication = new CompletionApplication:
def isImplicitConversion(symbol: Symbol): Boolean = false
def isMember(symbol: Symbol): Boolean = false
def isInherited(symbol: Symbol): Boolean = false
Expand Down Expand Up @@ -892,8 +892,8 @@ class Completions(
cursorPos: CursorPos,
): Ordering[CompletionValue] =
new Ordering[CompletionValue]:
val queryLower = completionPos.query.toLowerCase()
val fuzzyCache = mutable.Map.empty[CompletionValue, Int]
val queryLower: String = completionPos.query.toLowerCase()
val fuzzyCache: scala.collection.mutable.Map[CompletionValue, Int] = mutable.Map.empty[CompletionValue, Int]

def compareLocalSymbols(s1: Symbol, s2: Symbol): Int =
if s1.isLocal && s2.isLocal && s1.sourcePos.exists && s2.sourcePos.exists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object InterpolatorCompletions:
search: SymbolSearch,
config: PresentationCompilerConfig,
buildTargetIdentifier: String,
)(using Context, ReportContext) =
)(using Context, ReportContext): List[CompletionValue] =
InterpolationSplice(pos.span.point, text.toCharArray(), text) match
case Some(interpolator) =>
InterpolatorCompletions.contributeScope(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import dotty.tools.dotc.core.Types.Type
import dotty.tools.dotc.core.Types.TypeRef
import dotty.tools.dotc.util.SourcePosition
import org.eclipse.lsp4j as l
import dotty.tools.dotc.ast.Trees.Tree
import dotty.tools.dotc.ast.Trees.Tree
import dotty.tools.dotc.ast.Trees.Tree

object CaseKeywordCompletion:

Expand Down Expand Up @@ -390,7 +393,7 @@ class CompletionValueGenerator(
patternOnly: Option[String] = None,
hasBind: Boolean = false,
):
def fuzzyMatches(name: String) =
def fuzzyMatches(name: String): Boolean =
patternOnly match
case None => true
case Some("") => true
Expand Down Expand Up @@ -525,7 +528,7 @@ class MatchCaseExtractor(
completionPos: CompletionPos,
):
object MatchExtractor:
def unapply(path: List[Tree]) =
def unapply(path: List[Tree]): Option[Tree[Type | Null]] =
path match
// foo mat@@
case (sel @ Select(qualifier, name)) :: _
Expand Down Expand Up @@ -594,7 +597,7 @@ class MatchCaseExtractor(
end CaseExtractor

object CasePatternExtractor:
def unapply(path: List[Tree])(using Context) =
def unapply(path: List[Tree])(using Context): Option[(Tree[Type], Tree[Type], String)] =
path match
// case @@
case (c @ CaseDef(
Expand All @@ -621,7 +624,7 @@ class MatchCaseExtractor(
end CasePatternExtractor

object TypedCasePatternExtractor:
def unapply(path: List[Tree])(using Context) =
def unapply(path: List[Tree])(using Context): Option[(Tree[Type], Tree[Type], String)] =
path match
// case _: Som@@ =>
case Ident(name) :: Typed(_, _) :: CaseExtractor(selector, parent, _) =>
Expand Down
Loading
Loading