Skip to content

fix: don't search for members in pc info when irrelevant #22674

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

Merged
merged 1 commit into from
Feb 27, 2025
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 @@ -55,7 +55,13 @@ class SymbolInformationProvider(using Context):
val classOwner =
sym.ownersIterator.drop(1).find(s => s.isClass || s.is(Flags.Module))
val overridden = sym.denot.allOverriddenSymbols.toList
val memberDefAnnots = sym.info.membersBasedOnFlags(Flags.Method, Flags.EmptyFlags).flatMap(_.allSymbols).flatMap(_.denot.annotations)
val memberDefAnnots =
if classSym.exists then
classSym.info
.membersBasedOnFlags(Flags.Method, Flags.EmptyFlags)
.flatMap(_.allSymbols)
.flatMap(_.denot.annotations)
else Nil

val pcSymbolInformation =
PcSymbolInformation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import scala.meta.pc.PcSymbolInformation
import dotty.tools.pc.base.BasePCSuite
import scala.language.unsafeNulls
import org.junit.Test
import scala.meta.internal.metals.CompilerOffsetParams
import java.nio.file.Paths
import scala.annotation.nowarn

class InfoSuite extends BasePCSuite {

Expand Down Expand Up @@ -53,4 +56,48 @@ class InfoSuite extends BasePCSuite {
|scala/collection/IterableOnceOps#flatMap().
|""".stripMargin
)

@Test def i7251 =
withSource(
"""|package a
|sealed trait TA:
| type SomeType
|trait TB extends TA:
| type SomeType = Int
|""".stripMargin
)
val info = presentationCompiler.info("a/TA#SomeType#").get()
assertNoDiff(info.get().symbol(), "a/TA#SomeType#")

@Test def memberDefsAnnotations =
def assertMemberDefsAnnotations(symbol: String, expected: String) =
val info = presentationCompiler.info(symbol).get()
assertNoDiff(info.get().memberDefsAnnotations().asScala.mkString("\n"), expected, Some(symbol))
withSource(
"""|package a
|import scala.annotation.nowarn
|sealed trait TA:
| @nowarn
| def aaa = 1
|
|object O:
| @nowarn
| def aaa = 1
|
|class D:
| @nowarn
| def bbb = 1
|""".stripMargin
)
assertMemberDefsAnnotations("a/TA#", "scala.annotation.nowarn")
assertMemberDefsAnnotations("a/O.", "scala.annotation.nowarn")
assertMemberDefsAnnotations("a/D#", "scala.annotation.nowarn")
assertMemberDefsAnnotations("a/D#bbb().", "")

// hacky way to add a source file to the presentation compiler sources
private def withSource(code: String) =
val filename = "Hover.scala"
val pcParams = CompilerOffsetParams(Paths.get(filename).toUri(), code, 0)
presentationCompiler.hover(pcParams).get()

}
Loading