Skip to content

Commit

Permalink
refactor: Tweaks after reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Dec 15, 2023
1 parent 4ed074b commit e643cf5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ class CompilerSearchVisitor(

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

private def isAccessibleImplicitClass(sym: Symbol) =
val owner = sym.maybeOwner
owner != NoSymbol && owner.isClass &&
owner.is(Flags.Implicit) &&
owner.isStatic && owner.isPublic

private def isAccessible(sym: Symbol): Boolean = try
sym != NoSymbol && sym.isPublic && sym.isStatic || {
val owner = sym.maybeOwner
owner != NoSymbol && owner.isClass &&
owner.is(Flags.Implicit) &&
owner.isStatic && owner.isPublic
}
sym != NoSymbol && sym.isPublic && sym.isStatic ||
isAccessibleImplicitClass(sym)
catch
case err: AssertionError =>
logger.log(Level.WARNING, err.getMessage())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,11 @@ object SemanticdbSymbols:
/**
* Looks like decl doesn't work for:
* package a:
* implicit class A (i: Int):
* implicit class <<A>> (i: Int):
* def inc = i + 1
*/
else if typeSym == NoSymbol then
val searched = typeName(value)
owner.info.allMembers
.find(_.name == searched)
.map(_.symbol)
.toList
owner.info.member(typeName(value)).symbol :: Nil
else typeSym :: Nil
end if
case Descriptor.Term(value) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,14 @@ class Completions(
qualType.widenDealias <:< sym.extensionParam.info.widenDealias

def isImplicitClass(owner: Symbol) =

val constructorParam =
owner.info.allMembers
.find(_.symbol.isAllOf(Flags.PrivateParamAccessor))
owner.info
.membersBasedOnFlags(
Flags.ParamAccessor,
Flags.EmptyFlags,
)
.headOption
.map(_.info)
owner.isClass && owner.is(Flags.Implicit) &&
constructorParam.exists(p =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ class ScalaToplevelMtags(
loop(
indent,
isAfterNewline = false,
if (needsToGenerateFileClass) currRegion.withTermOwner(owner) else currRegion,
if (needsToGenerateFileClass) currRegion.withTermOwner(owner)
else currRegion,
template
)
// also covers extension methods because of `def` inside
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class CompletionExtensionMethodSuite extends BaseCompletionSuite {
|def main = "foo".iden@@
|""".stripMargin,
"""|identity: String (implicit)
|""".stripMargin // incr won't be available
|""".stripMargin // identity2 won't be available

)

Expand Down Expand Up @@ -266,7 +266,7 @@ class CompletionExtensionMethodSuite extends BaseCompletionSuite {
"""|package example
|
|object enrichments:
| implicit class A (num: Int):
| implicit class A (val num: Int):
| def plus(other: Int): Int = num + other
|
|def main = 100.pl@@
Expand All @@ -276,7 +276,7 @@ class CompletionExtensionMethodSuite extends BaseCompletionSuite {
|import example.enrichments.A
|
|object enrichments:
| implicit class A (num: Int):
| implicit class A (val num: Int):
| def plus(other: Int): Int = num + other
|
|def main = 100.plus($0)
Expand Down

0 comments on commit e643cf5

Please sign in to comment.