scalameta / metals

Scala language server with rich IDE features 🚀
https://scalameta.org/metals/
Apache License 2.0
2.1k stars 332 forks source link

[Scala3] Weird document highlighting in particular function in dotty repo #3053

Open dos65 opened 3 years ago

dos65 commented 3 years ago

Steps to reproduce the behavior:

  1. open the dotty repo in Metals
  2. open compiler/src/dotty/tools/dotc/ast/Desugar.scala
  3. put a cursor on any line in def classDef method body
  4. notice that full body is highlighted Screenshot from 2021-08-19 20-49-32
tanishiking commented 3 years ago

Looks like this happens when cursor on { ... }.method().

Actually, if we remove .showing at the end of the classDef method, it works fine.

--- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala
+++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala
@@ -824,7 +824,7 @@ object desugar {
     }

     flatTree(cdef1 :: companions ::: implicitWrappers ::: enumScaffolding)
-  }.showing(i"desugared: $result", Printers.desugar)
+  }

   /** Expand
    *
Screen Shot 2021-08-20 at 22 59 08
dos65 commented 3 years ago

@tanishiking I thought about that. However, I couldn't reproduce the similar thing on smaller samples. For example, if I add an method with a similar structure in this file it works well and provides correct highlithing Screenshot from 2021-08-20 21-12-13

tgodzik commented 3 years ago

It seems that we are getting a wrong range maybe?

ckipp01 commented 2 years ago

Related to this, I noticed that when this happens and you see usage of showing like in the above example, code navigation is also impacted. For example trying to goto a definition of a symbol inside of that block ends up leading you to showing instead.

2022-01-24 15 50 42

tgodzik commented 2 years ago

Looks like this is working correctly now :tada:

ckipp01 commented 2 years ago

Looks like this is working correctly now 🎉

I actually just tested the case I have above and I'm still getting the same issues. Using 0.11.9+90-31235494-SNAPSHOT if I am in the Dotty codebase and trigger a goto definition on isEnum as you see in the gif, I am still brought to showing.

https://github.com/lampepfl/dotty/blob/bf808b380859dc67bef397334f773015c17772f7/compiler/src/dotty/tools/dotc/ast/Desugar.scala#L529

tgodzik commented 2 years ago

Ach damn, the highlighting got fixed because we now use the compiler, but it seemed to me that it was working for go to definition also :/