Skip to content

Commit

Permalink
improvement: trim hover body (#5694)
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek authored Oct 4, 2023
1 parent dfa965e commit 664dcce
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package scala.meta.internal.pc

object HoverMarkup {

// VSCode trims the message to ~100000, thus messing the markdown for very long messages.
// Number based on experiments from 29.09.2023.
private val MaxHoverBodyLength = 50000

/**
* Render the textDocument/hover result into markdown.
*
Expand Down Expand Up @@ -42,15 +46,19 @@ object HoverMarkup {
markdown.toString()
}

private def trimBody(body: String) =
if (body.length() <= MaxHoverBodyLength) body
else body.take(MaxHoverBodyLength) + "..."

def apply(body: String): String = {
s"""|```scala
|$body
|${trimBody(body)}
|```""".stripMargin
}

def javaHoverMarkup(body: String): String = {
s"""|```java
|$body
|${trimBody(body)}
|```""".stripMargin
}

Expand Down

0 comments on commit 664dcce

Please sign in to comment.