Skip to content

Commit

Permalink
extract common scala docstring printers part
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Apr 18, 2024
1 parent 3889a9c commit 94276d2
Show file tree
Hide file tree
Showing 10 changed files with 294 additions and 293 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import scala.meta.internal.semanticdb.SymbolInformation
import scala.meta.internal.semanticdb.SymbolOccurrence
import scala.meta.io.AbsolutePath
import scala.meta.pc.ContentType
import scala.meta.pc.ParentSymbols
import scala.meta.pc.SymbolDocumentation
import scala.meta.pc.ContentType.MARKDOWN
import scala.meta.pc.ContentType.PLAINTEXT
import scala.meta.pc.ParentSymbols
import scala.meta.pc.SymbolDocumentation

/**
* Implementation of the `documentation(symbol: String): Option[SymbolDocumentation]` method in `SymbolSearch`.
Expand Down Expand Up @@ -183,7 +183,7 @@ class Markdown(val text: String) extends AnyVal with Content
class Plain(val text: String) extends AnyVal with Content

object Content {
def from(text: String, contentType: ContentType) =
def from(text: String, contentType: ContentType): AnyVal with Content =
contentType match {
case MARKDOWN => new Markdown(text)
case PLAINTEXT => new Plain(text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import scala.util.control.NonFatal

import scala.meta.inputs.Input
import scala.meta.inputs.Position
import scala.meta.internal.docstrings.MarkdownGenerator
import scala.meta.internal.docstrings.printers.MarkdownGenerator
import scala.meta.internal.jdk.CollectionConverters._
import scala.meta.internal.mtags.JavaMtags
import scala.meta.internal.semanticdb.Scala.Descriptor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ class ScaladocIndexer(
sinfo: SymbolInformation,
owner: String
): Unit = {
val printer =
contentType match {
case MARKDOWN => printers.MarkdownGenerator
case PLAINTEXT => printers.PlaintextGenerator
}

val docstring = currentTree.origin match {
case ScalametaCompat.ParsedOrigin(start, _) =>
val leadingDocstring =
Expand All @@ -47,23 +53,12 @@ class ScaladocIndexer(
// Register `@define` macros to use for expanding in later docstrings.
defines ++= ScaladocParser.extractDefines(docstring)
val comment = ScaladocParser.parseComment(docstring, defines)
val docstringContent =
contentType match {
case MARKDOWN =>
MarkdownGenerator.toMarkdown(comment, docstring)
case PLAINTEXT =>
PlaintextGenerator.toPlaintext(comment, docstring)
}
val docstringContent = printer.toText(comment, docstring)
def param(name: String, default: String): SymbolDocumentation = {
val paramDoc = comment.valueParams
.get(name)
.orElse(comment.typeParams.get(name))
.map { body =>
contentType match {
case MARKDOWN => MarkdownGenerator.toMarkdown(body)
case PLAINTEXT => PlaintextGenerator.toPlaintext(body)
}
}
.map(printer.toText)
.getOrElse("")
MetalsSymbolDocumentation(
Symbols.Global(owner, Descriptor.Parameter(name)),
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 94276d2

Please sign in to comment.