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

Hover on annotation in Scala just shows the Ref it's on #3593

Closed
ckipp01 opened this issue Feb 1, 2022 · 2 comments
Closed

Hover on annotation in Scala just shows the Ref it's on #3593

ckipp01 opened this issue Feb 1, 2022 · 2 comments
Labels
presentation-compiler Something relating to the presentation compiler Scala 3 Generic ticket relating to Scala 3
Milestone

Comments

@ckipp01
Copy link
Member

ckipp01 commented Feb 1, 2022

Describe the bug

Having a minimal piece of code like this:

import scala.annotation.nowarn

@no@@warn
class Foo

When you attempt to do a hover on @nowarn you actually get the TypeRef of Foo shown instead of the information about @nowarn.

Screenshot 2022-02-01 at 10 48 01

The tree that is returned here for this pos is:

TypeDef(
  name = Foo,
  rhs = Template(
    constr = DefDef(
      name = <init>,
      paramss = List(List()),
      tpt = TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Unit)],
      preRhs = Thicket(trees = List())
    ),
    parentsOrDerived = List(
      Apply(
        fun = Select(
          qualifier = New(
            tpt = TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class lang)),class Object)]
          ),
          name = <init>
        ),
        args = List()
      )
    ),
    self = ValDef(name = _, tpt = Thicket(trees = List()), preRhs = Thicket(trees = List())),
    preBody = List()
  )
)

I actually stumbled onto this because of something else (trying to understand when I'd see the Annotated tree) and then realizing I could never see it when testing with untyped trees or typed ones. Then I looked at how Metals would show this, and it also doesn't show the annotation. Is this actually an updates issue that Annotated is never in the tree?

Expected behavior

I'd expect that this show the signature and scaladocs for @nowarn instead of for Foo.

Operating system

macOS

Editor/Extension

Nvim (nvim-metals)

Version of Metals

0.11.1+47-66ea31ef-SNAPSHOT

Extra context or search terms

No response

@ckipp01 ckipp01 added Scala 3 Generic ticket relating to Scala 3 presentation-compiler Something relating to the presentation compiler labels Feb 1, 2022
@ckipp01 ckipp01 changed the title Hover on annotation in Scala just the Ref it's on Hover on annotation in Scala just shows the Ref it's on Feb 1, 2022
@tgodzik
Copy link
Contributor

tgodzik commented Feb 1, 2022

I dug into that recently actually and it seems that the annotation tree is in the type.

I did fix an issue related to it in https://github.com/lampepfl/dotty/pull/13834/files

@rochala
Copy link
Collaborator

rochala commented Feb 29, 2024

This was caused by a crash:

dotty.tools.dotc.ast.Trees$Tree.tpe(Trees.scala:72)
        dotty.tools.pc.utils.MtagsEnrichments$.tryTail$1(MtagsEnrichments.scala:262)
        dotty.tools.pc.utils.MtagsEnrichments$.expandRangeToEnclosingApply(MtagsEnrichments.scala:279)
        dotty.tools.pc.HoverProvider$.hover(HoverProvider.scala:51)
        dotty.tools.pc.ScalaPresentationCompiler.hover$$anonfun$1(ScalaPresentationCompiler.scala:326)

It was already solved by accident with scala/scala3#19488
image

It will also be backported in the future to LTS. Also this may hide the underlying problem so it may need a bit more investigation.

@rochala rochala closed this as completed Feb 29, 2024
@tgodzik tgodzik added this to the Metals v1.3.0 milestone Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
presentation-compiler Something relating to the presentation compiler Scala 3 Generic ticket relating to Scala 3
Projects
None yet
Development

No branches or pull requests

3 participants