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 18, 2023
1 parent 4ed074b commit 15f8b3e
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 30 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
9 changes: 9 additions & 0 deletions tests/cross/src/main/scala/tests/BasePCSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,15 @@ abstract class BasePCSuite extends BaseSuite with PCSuite {
}

object IgnoreScalaVersion {

def or(
ignoreScalaVersion1: IgnoreScalaVersion,
IgnoreScalaVersion2: IgnoreScalaVersion
): IgnoreScalaVersion =
IgnoreScalaVersion { v =>
ignoreScalaVersion1.ignored(v) || IgnoreScalaVersion2.ignored(v)
}

def apply(version: String): IgnoreScalaVersion = {
IgnoreScalaVersion(_ == version)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CompletionExtensionMethodSuite extends BaseCompletionSuite {
)

check(
"simple-old-syntax",
"simple-old-syntax".tag(IgnoreForScala3CompilerPC),
"""|package example
|
|object Test:
Expand Down Expand Up @@ -51,7 +51,7 @@ class CompletionExtensionMethodSuite extends BaseCompletionSuite {
)

check(
"simple2-old-syntax",
"simple2-old-syntax".tag(IgnoreForScala3CompilerPC),
"""|package example
|
|object enrichments:
Expand Down Expand Up @@ -81,7 +81,7 @@ class CompletionExtensionMethodSuite extends BaseCompletionSuite {
)

check(
"simple-empty-old",
"simple-empty-old".tag(IgnoreForScala3CompilerPC),
"""|package example
|
|object enrichments:
Expand Down Expand Up @@ -113,7 +113,7 @@ class CompletionExtensionMethodSuite extends BaseCompletionSuite {
)

check(
"filter-by-type-old",
"filter-by-type-old".tag(IgnoreForScala3CompilerPC),
"""|package example
|
|object enrichments:
Expand All @@ -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 All @@ -148,7 +148,7 @@ class CompletionExtensionMethodSuite extends BaseCompletionSuite {
)

check(
"filter-by-type-subtype-old",
"filter-by-type-subtype-old".tag(IgnoreForScala3CompilerPC),
"""|package example
|
|class A
Expand Down Expand Up @@ -188,7 +188,7 @@ class CompletionExtensionMethodSuite extends BaseCompletionSuite {
)

checkEdit(
"simple-edit-old",
"simple-edit-old".tag(IgnoreForScala3CompilerPC),
"""|package example
|
|object enrichments:
Expand Down Expand Up @@ -262,11 +262,11 @@ class CompletionExtensionMethodSuite extends BaseCompletionSuite {
)

checkEdit(
"simple-edit-suffix-old",
"simple-edit-suffix-old".tag(IgnoreForScala3CompilerPC),
"""|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 All @@ -300,7 +300,13 @@ class CompletionExtensionMethodSuite extends BaseCompletionSuite {
)

check(
"directly-in-pkg1-old".tag(IgnoreScalaVersion.forLessThan("3.2.2")),
"directly-in-pkg1-old"
.tag(
IgnoreScalaVersion.or(
IgnoreScalaVersion.forLessThan("3.2.2"),
IgnoreForScala3CompilerPC
)
),
"""|
|package examples:
| implicit class A(num: Int):
Expand Down Expand Up @@ -328,7 +334,13 @@ class CompletionExtensionMethodSuite extends BaseCompletionSuite {
)

check(
"directly-in-pkg2-old".tag(IgnoreScalaVersion.forLessThan("3.2.2")),
"directly-in-pkg2-old"
.tag(
IgnoreScalaVersion.or(
IgnoreScalaVersion.forLessThan("3.2.2"),
IgnoreForScala3CompilerPC
)
),
"""|package examples:
| object X:
| def fooBar(num: Int) = num + 1
Expand Down Expand Up @@ -359,7 +371,13 @@ class CompletionExtensionMethodSuite extends BaseCompletionSuite {
)

checkEdit(
"directly-in-pkg3-old".tag(IgnoreScalaVersion.forLessThan("3.2.2")),
"directly-in-pkg3-old"
.tag(
IgnoreScalaVersion.or(
IgnoreScalaVersion.forLessThan("3.2.2"),
IgnoreForScala3CompilerPC
)
),
"""|package examples:
| implicit class A (num: Int) { def incr: Int = num + 1 }
|
Expand Down Expand Up @@ -394,7 +412,13 @@ class CompletionExtensionMethodSuite extends BaseCompletionSuite {
)

check(
"nested-pkg-old".tag(IgnoreScalaVersion.forLessThan("3.2.2")),
"nested-pkg-old"
.tag(
IgnoreScalaVersion.or(
IgnoreScalaVersion.forLessThan("3.2.2"),
IgnoreForScala3CompilerPC
)
),
"""|package aa: // some comment
| package cc:
| implicit class A (num: Int):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ example/Scalalib.scala -> example/Scalalib#
example/StructuralTypes.scala -> example/StructuralTypes.
example/ToplevelDefVal.scala -> example/ToplevelDefVal$package.
example/ToplevelImplicit.scala -> example/ToplevelImplicit$package.
example/ToplevelImplicit.scala -> example/ToplevelImplicit$package.
example/ToplevelImplicit.scala -> example/ToplevelImplicit$package.Xtension#
example/ToplevelImplicit.scala -> example/ToplevelImplicit$package.XtensionAnyVal#
example/TryCatch.scala -> example/TryCatch#
Expand Down

0 comments on commit 15f8b3e

Please sign in to comment.