Skip to content

Commit

Permalink
remove duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
rochala committed Aug 24, 2023
1 parent aa04b2f commit 281576d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class Completions(
case Literal(Constant(_: String)) :: _ => Mode.Term // literal completions
case _ => mode


private lazy val shouldAddSnippet =
path match
/* In case of `method@@()` we should not add snippets and the path
Expand Down Expand Up @@ -114,7 +113,6 @@ class Completions(
end if
end includeSymbol


def completions(): (List[CompletionValue], SymbolSearch.Result) =
val (advanced, exclusive) = advancedCompletions(path, pos, completionPos)
val (all, result) =
Expand Down Expand Up @@ -242,9 +240,8 @@ class Completions(
def companionSynthetic = sym.companion.exists && sym.companion.is(Synthetic)
// find the apply completion that would need a snippet
val methodSymbols =
if shouldAddSnippet &&
(sym.is(Flags.Module) || sym.isClass && !sym.is(Flags.Trait)) &&
!sym.is(Flags.JavaDefined) && completionMode.is(Mode.Term)
if shouldAddSnippet && completionMode.is(Mode.Term) &&
(sym.is(Flags.Module) || sym.isClass && !sym.is(Flags.Trait)) && !sym.is(Flags.JavaDefined)
then
val info =
/* Companion will be added even for normal classes now,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,25 @@ class ShortenedTypePrinter(
end match
end hoverSymbol

def isImportedByDefault(sym: Symbol): Boolean =
import dotty.tools.dotc.core.Symbols.defn
lazy val effectiveOwner = sym.effectiveOwner
sym.isType && (effectiveOwner == defn.ScalaPackageClass || effectiveOwner == defn.ScalaPredefModuleClass)

def completionSymbol(sym: Symbol): String =
val info = sym.info.widenTermRefExpr
val typeSymbol = info.typeSymbol

if sym.is(Flags.Package) || sym.isClass then " " + fullNameString(sym.effectiveOwner)
else if sym.is(Flags.Module) || typeSymbol.is(Flags.Module) then
lazy val typeEffectiveOwner =
if typeSymbol != NoSymbol then " " + fullNameString(typeSymbol.effectiveOwner)
else " " + fullNameString(sym.effectiveOwner)

if isImportedByDefault(sym) then typeEffectiveOwner
else if sym.is(Flags.Package) || sym.isClass then " " + fullNameString(sym.effectiveOwner)
else if sym.is(Flags.Module) || typeSymbol.is(Flags.Module) then typeEffectiveOwner
else if sym.is(Flags.Method) then
defaultMethodSignature(sym, info, onlyMethodParams = true)
else if sym.isType
then
else if sym.isType then
info match
case TypeAlias(t) => " = " + tpe(t.resultType)
case t => tpe(t.resultType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,8 @@ class CompletionSuite extends BaseCompletionSuite:
|}
|""".stripMargin,
"""|Some[?] scala
|SafeVarargs java.lang
|ScalaReflectionException scala
|Seq[A] scala.collection.immutable
|""".stripMargin,
topLines = Some(3)
)
Expand Down Expand Up @@ -709,8 +709,8 @@ class CompletionSuite extends BaseCompletionSuite:
|}
|""".stripMargin,
"""|Number: Regex
|NegativeArraySizeException java.lang
|NoClassDefFoundError java.lang
|NoSuchElementException java.util
|NoSuchFieldError java.lang
|""".stripMargin,
topLines = Option(3)
)
Expand All @@ -724,12 +724,24 @@ class CompletionSuite extends BaseCompletionSuite:
|}
|""".stripMargin,
"""|Number: Regex
|NegativeArraySizeException java.lang
|NoClassDefFoundError java.lang
|NoSuchElementException java.util
|NoSuchFieldError java.lang
|""".stripMargin,
topLines = Option(3)
)

@Test def `no-methods-on-case-type` =
check(
s"""|object Main {
| val Number = "".r
| "" match {
| case _: NotImpl@@
|}
|""".stripMargin,
"""|NotImplementedError scala
|""".stripMargin,
)

@Test def underscore =
check(
s"""|object Main {
Expand Down Expand Up @@ -1344,7 +1356,7 @@ class CompletionSuite extends BaseCompletionSuite:
"""|object T:
| extension (x: ListBuffe@@)
|""".stripMargin,
"""|ListBuffer[T] - scala.collection.mutable
"""|ListBuffer[A] - scala.collection.mutable
|ListBuffer - scala.collection.mutable
|""".stripMargin,
)
Expand All @@ -1364,7 +1376,7 @@ class CompletionSuite extends BaseCompletionSuite:
"""|object T:
| extension [A <: ListBuffe@@]
|""".stripMargin,
"""|ListBuffer[T] - scala.collection.mutable
"""|ListBuffer[A] - scala.collection.mutable
|ListBuffer - scala.collection.mutable
|""".stripMargin
)
Expand Down

0 comments on commit 281576d

Please sign in to comment.