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

Add missing -Yexplicit-nulls for presentation compiler #18776

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object AutoImports:
def renameConfigMap(config: PresentationCompilerConfig)(using
Context
): Map[Symbol, String] =
config.symbolPrefixes.asScala.flatMap { (from, to) =>
config.symbolPrefixes().nn.asScala.flatMap { (from, to) =>
val pkg = SemanticdbSymbols.inverseSemanticdbSymbol(from)
val rename = to.stripSuffix(".").stripSuffix("#")
List(pkg, pkg.map(_.moduleClass)).flatten
Expand Down Expand Up @@ -246,7 +246,7 @@ object AutoImports:
// see WorksheetProvider.worksheetScala3AdjustmentsForPC
val indent =
if pos.source.path.isWorksheet &&
editPos.getStart().getCharacter() == 0
editPos.getStart().nn.getCharacter() == 0
then indent0.drop(2)
else indent0
val topPadding =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ final class AutoImportsProvider(
)(using ReportContext):

def autoImports(isExtension: Boolean): List[AutoImportsResult] =
val uri = params.uri
val uri = params.uri().nn
val text = params.text().nn
val filePath = Paths.get(uri)
driver.run(
uri,
SourceFile.virtual(filePath.toString, params.text)
)
val unit = driver.currentCtx.run.units.head
driver.run(uri, SourceFile.virtual(filePath.toString, text))

val unit = driver.currentCtx.run.nn.units.head
val tree = unit.tpdTree

val pos = driver.sourcePosition(params)
Expand Down Expand Up @@ -81,7 +80,7 @@ final class AutoImportsProvider(
val generator =
AutoImports.generator(
correctedPos,
params.text,
text,
tree,
unit.comments,
indexedContext.importContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CompilerSearchVisitor(
)(using ctx: Context, reports: ReportContext)
extends SymbolSearchVisitor:

val logger: Logger = Logger.getLogger(classOf[CompilerSearchVisitor].getName)
val logger: Logger = Logger.getLogger(classOf[CompilerSearchVisitor].getName().nn).nn

private def isAccessible(sym: Symbol): Boolean = try
sym != NoSymbol && sym.isPublic && sym.isStatic
Expand Down Expand Up @@ -68,7 +68,7 @@ class CompilerSearchVisitor(
.split("\\$")

val added =
try toSymbols(pkg, innerPath.toList).filter(visitSymbol)
try toSymbols(pkg, innerPath.nn.toList.map(_.nn)).filter(visitSymbol)
catch
case NonFatal(e) =>
logger.log(Level.WARNING, e.getMessage(), e)
Expand All @@ -95,6 +95,6 @@ class CompilerSearchVisitor(
override def isCancelled: Boolean = false

private def normalizePackage(pkg: String): String =
pkg.replace("/", ".").stripSuffix(".")
pkg.replace("/", ".").nn.stripSuffix(".")

end CompilerSearchVisitor
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object CompletionItemResolver extends ItemResolver:
.orElse(
search.symbolDocumentation(gsym.companion)
) match
case Some(info) if item.getDetail != null =>
case Some(info) if item.getDetail() != null =>
enrichDocs(
item,
info,
Expand All @@ -50,7 +50,7 @@ object CompletionItemResolver extends ItemResolver:
Context
): String =
def docs(gsym: Symbol): String =
search.symbolDocumentation(gsym).fold("")(_.docstring())
search.symbolDocumentation(gsym).fold("")(_.docstring().nn)
val gsymDoc = docs(gsym)
def keyword(gsym: Symbol): String =
if gsym.isClass then "class"
Expand All @@ -60,7 +60,7 @@ object CompletionItemResolver extends ItemResolver:
else ""
val companion = gsym.companion
if companion == NoSymbol || gsym.is(JavaDefined) then
if gsymDoc.isEmpty then
if gsymDoc.isEmpty() then
if gsym.isAliasType then
fullDocstring(gsym.info.metalsDealias.typeSymbol, search)
else if gsym.is(Method) then
Expand All @@ -73,8 +73,8 @@ object CompletionItemResolver extends ItemResolver:
else gsymDoc
else
val companionDoc = docs(companion)
if companionDoc.isEmpty then gsymDoc
else if gsymDoc.isEmpty then companionDoc
if companionDoc.isEmpty() then gsymDoc
else if gsymDoc.isEmpty() then companionDoc
else
List(
s"""|### ${keyword(companion)} ${companion.name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ final class ConvertToNamedArgumentsProvider(
):

def convertToNamedArguments: Either[String, List[l.TextEdit]] =
val uri = params.uri
val uri = params.uri().nn
val text = params.text().nn
val filePath = Paths.get(uri)
driver.run(
uri,
SourceFile.virtual(filePath.toString, params.text)
)
val unit = driver.currentCtx.run.units.head
driver.run(uri, SourceFile.virtual(filePath.toString, text))

val unit = driver.currentCtx.run.nn.units.head
val newctx = driver.currentCtx.fresh.setCompilationUnit(unit)
val pos = driver.sourcePosition(params)
val trees = driver.openedTrees(uri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ final class ExtractMethodProvider(
extends ExtractMethodUtils:

def extractMethod(): List[TextEdit] =
val text = range.text()
val uri = range.uri
val text = range.text().nn
val uri = range.uri().nn
val filePath = Paths.get(uri)
val source = SourceFile.virtual(filePath.toString, text)
driver.run(uri, source)
val unit = driver.currentCtx.run.units.head
val unit = driver.currentCtx.run.nn.units.head
val pos = driver.sourcePosition(range).startPos
val path =
Interactive.pathTo(driver.openedTrees(uri), pos)(using driver.currentCtx)
Expand Down Expand Up @@ -145,7 +145,7 @@ final class ExtractMethodProvider(
val oldIndentLen = head.startPos.startColumnPadding.length()
val toExtract =
textToExtract(
range.text(),
text,
head.startPos.start,
expr.endPos.end,
newIndent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ object HoverProvider:
driver: InteractiveDriver,
search: SymbolSearch
)(implicit reportContext: ReportContext): ju.Optional[HoverSignature] =
val uri = params.uri
val sourceFile = SourceFile.virtual(params.uri, params.text)
val uri = params.uri().nn
val text = params.text().nn
val sourceFile = SourceFile.virtual(uri, text)
driver.run(uri, sourceFile)

given ctx: Context = driver.currentCtx
Expand All @@ -54,7 +55,7 @@ object HoverProvider:
then
def report =
val posId =
if path.isEmpty || path.head.sourcePos == null || !path.head.sourcePos.exists
if path.isEmpty || !path.head.sourcePos.exists
then pos.start
else path.head.sourcePos.start
Report(
Expand All @@ -77,7 +78,7 @@ object HoverProvider:
)
end report
reportContext.unsanitized.create(report, ifVerbose = true)
ju.Optional.empty()
ju.Optional.empty().nn
else
val skipCheckOnName =
!pos.isPoint // don't check isHoveringOnName for RangeHover
Expand Down Expand Up @@ -125,7 +126,7 @@ object HoverProvider:

val docString = symbolTpes
.flatMap(symTpe => search.symbolDocumentation(symTpe._1))
.map(_.docstring)
.map(_.docstring())
.mkString("\n")
printer.expressionType(exprTpw) match
case Some(expressionType) =>
Expand All @@ -143,9 +144,9 @@ object HoverProvider:
docstring = Some(docString),
forceExpressionType = forceExpressionType
)
)
).nn
case _ =>
ju.Optional.empty
ju.Optional.empty().nn
end match
end match
end if
Expand Down Expand Up @@ -188,7 +189,7 @@ object HoverProvider:

refTpe.flatMap(findRefinement).asJava
case _ =>
ju.Optional.empty()
ju.Optional.empty().nn

end HoverProvider

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import dotty.tools.dotc.core.Contexts.*
import dotty.tools.dotc.core.Flags.*
import dotty.tools.dotc.core.NameOps.moduleClassName
import dotty.tools.dotc.core.Names.*
import dotty.tools.dotc.core.Scopes.EmptyScope
import dotty.tools.dotc.core.Symbols.*
import dotty.tools.dotc.core.Types.*
import dotty.tools.dotc.typer.ImportInfo
Expand Down Expand Up @@ -82,7 +83,6 @@ object IndexedContext:

def apply(ctx: Context): IndexedContext =
ctx match
case null => Empty
case NoContext => Empty
case _ => LazyWrapper(using ctx)

Expand Down Expand Up @@ -205,14 +205,14 @@ object IndexedContext:
val (symbols, renames) =
if ctx.isImportContext then
val (syms, renames) =
fromImportInfo(ctx.importInfo)
fromImportInfo(ctx.importInfo.nn)
.map((sym, rename) => (sym, rename.map(r => sym -> r.decoded)))
.unzip
(syms, renames.flatten.toMap)
else if ctx.owner.isClass then
val site = ctx.owner.thisType
(accesibleMembers(site), Map.empty)
else if ctx.scope != null then (ctx.scope.toList, Map.empty)
else if ctx.scope != EmptyScope then (ctx.scope.toList, Map.empty)
else (List.empty, Map.empty)

val initial = Map.empty[String, List[Symbol]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ final class InferredTypeProvider(
adjustOpt: Option[AdjustTypeOpts] = None
): List[TextEdit] =
val retryType = adjustOpt.isEmpty
val uri = params.uri
val filePath = Paths.get(uri)
val uri = params.uri().nn
val filePath = Paths.get(uri).nn

val sourceText = adjustOpt.map(_.text).getOrElse(params.text)
val sourceText = adjustOpt.map(_.text).getOrElse(params.text().nn)
val source =
SourceFile.virtual(filePath.toString, sourceText)
SourceFile.virtual(filePath.toString(), sourceText)
driver.run(uri, source)
val unit = driver.currentCtx.run.units.head
val unit = driver.currentCtx.run.nn.units.head
val pos = driver.sourcePosition(params)
val path =
Interactive.pathTo(driver.openedTrees(uri), pos)(using driver.currentCtx)
Expand All @@ -78,15 +78,15 @@ final class InferredTypeProvider(
val indexedCtx = IndexedContext(locatedCtx)
val autoImportsGen = AutoImports.generator(
pos,
params.text,
sourceText,
unit.tpdTree,
unit.comments,
indexedCtx,
config
)

def removeType(nameEnd: Int, tptEnd: Int) =
sourceText.substring(0, nameEnd) +
sourceText.substring(0, nameEnd).nn +
sourceText.substring(tptEnd + 1, sourceText.length())

def optDealias(tpe: Type): Type =
Expand Down Expand Up @@ -134,7 +134,7 @@ final class InferredTypeProvider(
def baseEdit(withParens: Boolean): TextEdit =
val keywordOffset = if isParam then 0 else 4
val endPos =
findNamePos(params.text, vl, keywordOffset).endPos.toLsp
findNamePos(sourceText, vl, keywordOffset).endPos.toLsp
adjustOpt.foreach(adjust => endPos.setEnd(adjust.adjustedEndPos))
new TextEdit(
endPos,
Expand All @@ -148,11 +148,10 @@ final class InferredTypeProvider(
toCheckFor: Char,
blockStartPos: SourcePosition
) =
val text = params.text
val isParensFunction: Boolean = text(applyEndingPos) == toCheckFor
val isParensFunction: Boolean = sourceText(applyEndingPos) == toCheckFor

val alreadyHasParens =
text(blockStartPos.start) == '('
sourceText(blockStartPos.start) == '('

if isParensFunction && !alreadyHasParens then
new TextEdit(blockStartPos.toLsp, "(") :: baseEdit(withParens =
Expand Down Expand Up @@ -188,7 +187,7 @@ final class InferredTypeProvider(
Some(
AdjustTypeOpts(
removeType(vl.namePos.end, tpt.sourcePos.end - 1),
tpt.sourcePos.toLsp.getEnd()
tpt.sourcePos.toLsp.getEnd().nn
)
)
)
Expand Down Expand Up @@ -227,7 +226,7 @@ final class InferredTypeProvider(
Some(
AdjustTypeOpts(
removeType(lastColon, tpt.sourcePos.end - 1),
tpt.sourcePos.toLsp.getEnd()
tpt.sourcePos.toLsp.getEnd().nn
)
)
)
Expand Down Expand Up @@ -256,8 +255,8 @@ final class InferredTypeProvider(
val firstEnd = patterns(0).endPos.end
val secondStart = patterns(1).startPos.start
val hasDot = params
.text()
.substring(firstEnd, secondStart)
.text().nn
.substring(firstEnd, secondStart).nn
.exists(_ == ',')
if !hasDot then
val leftParen = new TextEdit(body.startPos.toLsp, "(")
Expand Down Expand Up @@ -309,7 +308,7 @@ final class InferredTypeProvider(
val end = if withBacktick then idx + 1 else idx
val pos = tree.source.atSpan(Span(start, end, start))
Some(pos)
case None if idx < text.length =>
case None if idx < text.length() =>
val ch = text.charAt(idx)
if ch == realName.head then
lookup(idx + 1, Some((idx, realName.tail)), withBacktick)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class MetalsDriver(

override def run(uri: URI, sourceCode: String): List[Diagnostic] =
val diags =
if alreadyCompiled(uri, sourceCode.toCharArray()) then Nil
if alreadyCompiled(uri, sourceCode.toCharArray().nn) then Nil
else super.run(uri, sourceCode)
lastCompiledURI = uri
diags
Expand Down
13 changes: 6 additions & 7 deletions presentation-compiler/src/main/dotty/tools/pc/PcCollector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,23 @@ abstract class PcCollector[T](
params: VirtualFileParams
):
private val caseClassSynthetics: Set[Name] = Set(nme.apply, nme.copy)
val uri = params.uri()
val filePath = Paths.get(uri)
val sourceText = params.text
val uri = params.uri().nn
val filePath = Paths.get(uri).nn
val sourceText = params.text().nn
val source =
SourceFile.virtual(filePath.toString, sourceText)
SourceFile.virtual(filePath.toString(), sourceText)
driver.run(uri, source)
given ctx: Context = driver.currentCtx

val unit = driver.currentCtx.run.units.head
val unit = driver.currentCtx.run.nn.units.head
val compilatonUnitContext = ctx.fresh.setCompilationUnit(unit)
val offset = params match
case op: OffsetParams => op.offset()
case _ => 0
val offsetParams =
params match
case op: OffsetParams => op
case _ =>
CompilerOffsetParams(params.uri(), params.text(), 0, params.token())
case _ => CompilerOffsetParams(uri, sourceText, 0, params.token().nn)
val pos = driver.sourcePosition(offsetParams)
val rawPath =
Interactive
Expand Down
Loading