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

Delias type members in hover #20173

Merged
merged 2 commits into from
Apr 29, 2024
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 @@ -13,7 +13,7 @@ import dotty.tools.dotc.core.Names.*
import dotty.tools.dotc.core.Symbols.*
import dotty.tools.dotc.util.SourcePosition
import dotty.tools.dotc.util.Spans
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*

import org.eclipse.lsp4j as l

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import dotty.tools.dotc.interactive.InteractiveDriver
import dotty.tools.dotc.util.SourceFile
import dotty.tools.pc.AutoImports.*
import dotty.tools.pc.completions.CompletionPos
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*

import org.eclipse.lsp4j as l

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Flags.*
import dotty.tools.dotc.core.Symbols.*
import dotty.tools.dotc.core.Types.TermRef
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*

import org.eclipse.lsp4j.CompletionItem

Expand Down Expand Up @@ -62,7 +62,7 @@ object CompletionItemResolver extends ItemResolver:
if companion == NoSymbol || gsym.is(JavaDefined) then
if gsymDoc.isEmpty() then
if gsym.isAliasType then
fullDocstring(gsym.info.metalsDealias.typeSymbol, search)
fullDocstring(gsym.info.deepDealias.typeSymbol, search)
else if gsym.is(Method) then
gsym.info.finalResultType match
case tr @ TermRef(_, sym) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import dotty.tools.dotc.core.Types.MethodType
import dotty.tools.dotc.interactive.Interactive
import dotty.tools.dotc.interactive.InteractiveDriver
import dotty.tools.dotc.util.SourceFile
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*

import org.eclipse.lsp4j as l

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import dotty.tools.dotc.util.SourceFile
import dotty.tools.dotc.util.SourcePosition
import dotty.tools.pc.printer.ShortenedTypePrinter
import dotty.tools.pc.printer.ShortenedTypePrinter.IncludeDefaultParam
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*

import org.eclipse.lsp4j.TextEdit
import org.eclipse.lsp4j as l
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import dotty.tools.dotc.util.SourceFile
import dotty.tools.dotc.util.SourcePosition
import dotty.tools.pc.printer.ShortenedTypePrinter
import dotty.tools.pc.printer.ShortenedTypePrinter.IncludeDefaultParam
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*

object HoverProvider:

Expand Down Expand Up @@ -106,7 +106,7 @@ object HoverProvider:
if symbol.name == nme.selectDynamic || symbol.name == nme.applyDynamic =>
fallbackToDynamics(path, printer)
case symbolTpes @ ((symbol, tpe) :: _) =>
val exprTpw = tpe.widenTermRefExpr.metalsDealias
val exprTpw = tpe.widenTermRefExpr.deepDealias
val hoverString =
tpw match
// https://github.com/scala/scala3/issues/8891
Expand All @@ -121,7 +121,7 @@ object HoverProvider:
if tpe != NoType then tpe
else tpw

printer.hoverSymbol(sym, finalTpe)
printer.hoverSymbol(sym, finalTpe.deepDealias)
end match
end hoverString

Expand Down Expand Up @@ -185,9 +185,9 @@ object HoverProvider:
findRefinement(parent)
case _ => None

val refTpe = sel.typeOpt.widen.metalsDealias match
val refTpe = sel.typeOpt.widen.deepDealias match
case r: RefinedType => Some(r)
case t: (TermRef | TypeProxy) => Some(t.termSymbol.info.metalsDealias)
case t: (TermRef | TypeProxy) => Some(t.termSymbol.info.deepDealias)
case _ => None

refTpe.flatMap(findRefinement).asJava
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import dotty.tools.dotc.core.Types.*
import dotty.tools.dotc.interactive.Interactive
import dotty.tools.dotc.typer.ImportInfo
import dotty.tools.pc.IndexedContext.Result
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*

sealed trait IndexedContext:
given ctx: Context
Expand Down Expand Up @@ -75,7 +75,7 @@ sealed trait IndexedContext:
)

private def isTypeAliasOf(alias: Symbol, queriedSym: Symbol): Boolean =
alias.isAliasType && alias.info.metalsDealias.typeSymbol == queriedSym
alias.isAliasType && alias.info.deepDealias.typeSymbol == queriedSym

final def isEmpty: Boolean = this match
case IndexedContext.Empty => true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import dotty.tools.dotc.util.Spans
import dotty.tools.dotc.util.Spans.Span
import dotty.tools.pc.printer.ShortenedTypePrinter
import dotty.tools.pc.printer.ShortenedTypePrinter.IncludeDefaultParam
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*

import org.eclipse.lsp4j.TextEdit
import org.eclipse.lsp4j as l
Expand Down Expand Up @@ -101,7 +101,7 @@ final class InferredTypeProvider(
case _ => true
if isInScope(tpe)
then tpe
else tpe.metalsDealias
else tpe.deepDealias

val printer = ShortenedTypePrinter(
symbolSearch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ object MetalsInteractive:
end match
end enclosingSymbolsWithExpressionType

import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*

private def recoverError(
tree: Tree,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import dotty.tools.dotc.interactive.InteractiveDriver
import dotty.tools.dotc.util.SourceFile
import dotty.tools.dotc.util.SourcePosition
import dotty.tools.dotc.util.Spans.Span
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*

abstract class PcCollector[T](
driver: InteractiveDriver,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import dotty.tools.dotc.interactive.Interactive
import dotty.tools.dotc.interactive.InteractiveDriver
import dotty.tools.dotc.util.SourceFile
import dotty.tools.dotc.util.SourcePosition
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*

import org.eclipse.lsp4j.Location

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import dotty.tools.dotc.ast.tpd.*
import dotty.tools.dotc.core.Symbols.*
import dotty.tools.dotc.interactive.InteractiveDriver
import dotty.tools.dotc.util.SourcePosition
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*

import org.eclipse.lsp4j.DocumentHighlight
import org.eclipse.lsp4j.DocumentHighlightKind
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package dotty.tools.pc
import java.nio.file.Paths

import scala.meta.internal.metals.ReportContext
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*
import dotty.tools.pc.printer.ShortenedTypePrinter
import scala.meta.internal.pc.InlayHints
import scala.meta.internal.pc.LabelPart
Expand Down Expand Up @@ -139,7 +139,7 @@ class PcInlayHintsProvider(
isInScope(tycon) && args.forall(isInScope)
case _ => true
if isInScope(tpe) then tpe
else tpe.metalsDealias(using indexedCtx.ctx)
else tpe.deepDealias(using indexedCtx.ctx)

val dealiased = optDealias(tpe)
val tpeStr = printer.tpe(dealiased)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import dotty.tools.dotc.core.Symbols.Symbol
import dotty.tools.dotc.interactive.Interactive
import dotty.tools.dotc.interactive.InteractiveDriver
import dotty.tools.dotc.util.SourcePosition
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*

import org.eclipse.lsp4j as l

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import dotty.tools.dotc.core.Flags.*
import dotty.tools.dotc.core.Symbols.Symbol
import dotty.tools.dotc.interactive.InteractiveDriver
import dotty.tools.dotc.util.SourcePosition
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*

import org.eclipse.lsp4j as l

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import dotty.tools.dotc.core.Symbols.NoSymbol
import dotty.tools.dotc.core.Symbols.Symbol
import dotty.tools.dotc.interactive.InteractiveDriver
import dotty.tools.dotc.util.SourcePosition
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*

import org.eclipse.lsp4j.SemanticTokenModifiers
import org.eclipse.lsp4j.SemanticTokenTypes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import dotty.tools.dotc.interactive.Interactive
import dotty.tools.dotc.interactive.InteractiveDriver
import dotty.tools.dotc.util.SourceFile
import dotty.tools.dotc.util.SourcePosition
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*

import org.eclipse.lsp4j
import org.eclipse.lsp4j.SelectionRange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import dotty.tools.dotc.core.Flags.*
import dotty.tools.dotc.core.Names.*
import dotty.tools.dotc.core.Symbols.*
import dotty.tools.dotc.semanticdb.*
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*

object SemanticdbSymbols:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import dotty.tools.dotc.util.Signatures
import dotty.tools.dotc.util.SourceFile
import dotty.tools.pc.printer.ShortenedTypePrinter
import dotty.tools.pc.printer.ShortenedTypePrinter.IncludeDefaultParam
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*
import org.eclipse.lsp4j as l

import scala.jdk.CollectionConverters.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import dotty.tools.dotc.core.Flags
import dotty.tools.dotc.core.Names.*
import dotty.tools.dotc.core.StdNames.nme
import dotty.tools.dotc.core.Symbols.*
import dotty.tools.pc.utils.MtagsEnrichments.metalsDealias
import dotty.tools.pc.utils.InteractiveEnrichments.deepDealias
import dotty.tools.pc.SemanticdbSymbols
import dotty.tools.pc.utils.MtagsEnrichments.allSymbols
import dotty.tools.pc.utils.InteractiveEnrichments.allSymbols

class SymbolInformationProvider(using Context):
private def toSymbols(
Expand Down Expand Up @@ -77,7 +77,7 @@ class SymbolInformationProvider(using Context):
then classSym.asClass.parentSyms.map(SemanticdbSymbols.symbolName)
else Nil
val dealisedSymbol =
if sym.isAliasType then sym.info.metalsDealias.typeSymbol else sym
if sym.isAliasType then sym.info.deepDealias.typeSymbol else sym
val classOwner =
sym.ownersIterator.drop(1).find(s => s.isClass || s.is(Flags.Module))
val overridden = sym.denot.allOverriddenSymbols.toList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package dotty.tools.pc

import java.nio.file.Path

import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*

trait WorksheetSemanticdbProvider:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import dotty.tools.dotc.ast.tpd.Tree
import dotty.tools.dotc.ast.untpd.ImportSelector
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.StdNames.*
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*

import org.eclipse.lsp4j as l

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import scala.meta.internal.mtags.CoursierComplete

import dotty.tools.dotc.ast.untpd.ImportSelector
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*

object AmmoniteIvyCompletions:
def contribute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import dotty.tools.dotc.core.Contexts.*
import dotty.tools.dotc.util.SourcePosition
import dotty.tools.dotc.util.Spans.*
import dotty.tools.dotc.interactive.Completion
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*

import org.eclipse.lsp4j as l

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import dotty.tools.pc.AutoImports.AutoImportEdits
import dotty.tools.pc.AutoImports.AutoImportsGenerator
import dotty.tools.pc.printer.ShortenedTypePrinter
import dotty.tools.pc.printer.ShortenedTypePrinter.IncludeDefaultParam
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*

import org.eclipse.lsp4j.Command
import org.eclipse.lsp4j.CompletionItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import dotty.tools.dotc.core.StdNames.nme
import dotty.tools.dotc.core.Symbols.Symbol
import dotty.tools.dotc.core.Types.Type
import dotty.tools.pc.printer.ShortenedTypePrinter
import dotty.tools.pc.utils.MtagsEnrichments.decoded
import dotty.tools.pc.utils.InteractiveEnrichments.decoded

import org.eclipse.lsp4j.CompletionItemKind
import org.eclipse.lsp4j.CompletionItemTag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ import dotty.tools.dotc.util.SrcPos
import dotty.tools.pc.AutoImports.AutoImportsGenerator
import dotty.tools.pc.buildinfo.BuildInfo
import dotty.tools.pc.completions.OverrideCompletions.OverrideExtractor
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*
import dotty.tools.dotc.core.Denotations.SingleDenotation
import dotty.tools.dotc.interactive.Interactive

class Completions(
text: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package completions
import dotty.tools.dotc.ast.tpd.TypeDef
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Flags
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*

object FilenameCompletions:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import dotty.tools.dotc.core.Symbols.Symbol
import dotty.tools.dotc.core.Types.Type
import dotty.tools.pc.CompilerSearchVisitor
import dotty.tools.pc.IndexedContext
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*

import org.eclipse.lsp4j as l

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import dotty.tools.pc.AutoImports.SymbolImport
import dotty.tools.pc.MetalsInteractive.*
import dotty.tools.pc.printer.ShortenedTypePrinter
import dotty.tools.pc.printer.ShortenedTypePrinter.IncludeDefaultParam
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*

import org.eclipse.lsp4j as l

Expand Down Expand Up @@ -86,12 +86,12 @@ object CaseKeywordCompletion:
) =>
val args = head.argTypes.init
if args.length > 1 then
Some(definitions.tupleType(args).widen.metalsDealias)
else args.headOption.map(_.widen.metalsDealias)
Some(definitions.tupleType(args).widen.deepDealias)
else args.headOption.map(_.widen.deepDealias)
case _ => None
case _ => None
case sel =>
Some(sel.tpe.widen.metalsDealias)
Some(sel.tpe.widen.deepDealias)

selTpe
.map { selTpe =>
Expand Down Expand Up @@ -156,7 +156,7 @@ object CaseKeywordCompletion:

indexedContext.scopeSymbols
.foreach(s =>
val ts = s.info.metalsDealias.typeSymbol
val ts = s.info.deepDealias.typeSymbol
if isValid(ts) then visit(autoImportsGen.inferSymbolImport(ts))
)
// Step 2: walk through known subclasses of sealed types.
Expand Down Expand Up @@ -259,8 +259,8 @@ object CaseKeywordCompletion:
clientSupportsSnippets
)

val tpeStr = printer.tpe(selector.tpe.widen.metalsDealias.bounds.hi)
val tpe = selector.typeOpt.widen.metalsDealias.bounds.hi match
val tpeStr = printer.tpe(selector.tpe.widen.deepDealias.bounds.hi)
val tpe = selector.typeOpt.widen.deepDealias.bounds.hi match
case tr @ TypeRef(_, _) => tr.underlying
case t => t

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import dotty.tools.dotc.core.Types.TypeBounds
import dotty.tools.dotc.core.Types.WildcardType
import dotty.tools.dotc.util.SourcePosition
import dotty.tools.pc.IndexedContext
import dotty.tools.pc.utils.MtagsEnrichments.*
import dotty.tools.pc.utils.InteractiveEnrichments.*
import scala.annotation.tailrec

object NamedArgCompletions:
Expand Down
Loading
Loading