scalameta / metals

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

`documentHighlight` a for `=>` is a bit odd #5837

Closed ckipp01 closed 1 year ago

ckipp01 commented 1 year ago

Describe the bug

I noticed today while browsing some code in Future.scala in the standard lib that the documentHighlight response wasn't really what I was expecting. The range that was returned was more than just the => causing highlighting in my editor to look a bit funky. I have a screenshot below explaining what I mean.

Screenshot 2023-11-15 at 10 48 02

The actual response looks like this:

[Trace - 10:41:01 AM] Sending response 'textDocument/documentHighlight - (165)'. Processing request took 8ms
Result: [
  {
    "range": {
      "start": {
        "line": 448,
        "character": 10
      },
      "end": {
        "line": 449,
        "character": 5
      }
    },
    "kind": 3
  }
]

You can reproduce this by navigating to fallBackTo in Future.scala.

Expected behavior

I would expect the range to only include => and not to go onto the next line.

Operating system

macOS

Editor/Extension

Nvim (nvim-metals)

Version of Metals

1.1.0+69-c68474d9-SNAPSHOT

Extra context or search terms

No response

tgodzik commented 1 year ago

Thanks for reporting. Can you consistently reproduce it? I wasn't able to do that:

repro

ckipp01 commented 1 year ago

Just checked and yea, I can reproduce this consistently. Here is the exact trace:

[Trace - 04:50:34 PM] Received request 'textDocument/documentHighlight - (15)'
Params: {
  "textDocument": {
    "uri": "file:///Users/ckipp/Documents/scala-workspace/minimal/.metals/readonly/dependencies/scala-library-2.13.10-sources.jar/scala/concurrent/Future.scala"
  },
  "position": {
    "line": 448,
    "character": 11
  }
}

[Trace - 04:50:34 PM] Sending response 'textDocument/documentHighlight - (15)'. Processing request took 13ms
Result: [
  {
    "range": {
      "start": {
        "line": 448,
        "character": 10
      },
      "end": {
        "line": 449,
        "character": 5
      }
    },
    "kind": 3
  }
]

Does it look the same in VS Code? Maybe it's just a highlighting thing and VS Code doesn't actually highlight the space so you never noticed?

tgodzik commented 1 year ago

Might be the same issue as https://github.com/scalameta/metals/issues/5840 :thinking: Let me double check if anything is sent.

tgodzik commented 1 year ago

It looks like VS Code doesn't even send a request in that case. I think we have some kind of synthetic there, that we should ignore.