Skip to content

Scaladoc: Add member position IDs to anchors in searchbar #14454

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

Merged
merged 3 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion scaladoc-js/main/src/searchbar/SearchbarComponent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import org.scalajs.dom.html.Input
import scala.scalajs.js.timers._
import scala.concurrent.duration._

import java.net.URI

class SearchbarComponent(engine: SearchbarEngine, inkuireEngine: InkuireJSSearchEngine, parser: QueryParser):
val resultsChunkSize = 100
extension (p: PageEntry)
Expand All @@ -22,6 +24,10 @@ class SearchbarComponent(engine: SearchbarEngine, inkuireEngine: InkuireJSSearch
val resultA = document.createElement("a").asInstanceOf[html.Anchor]
resultA.href = Globals.pathToRoot + p.location
resultA.text = s"${p.fullName}"
resultA.onclick = (event: Event) =>
if (document.body.contains(rootDiv)) {
document.body.removeChild(rootDiv)
}

val location = document.createElement("span")
location.classList.add("pull-right")
Expand Down Expand Up @@ -51,8 +57,17 @@ class SearchbarComponent(engine: SearchbarEngine, inkuireEngine: InkuireJSSearch
icon.classList.add(m.entryType.take(2))

val resultA = document.createElement("a").asInstanceOf[html.Anchor]
resultA.href = m.pageLocation
resultA.href =
if(new URI(m.pageLocation).isAbsolute()) {
m.pageLocation
} else {
Globals.pathToRoot + m.pageLocation
}
resultA.text = m.functionName
resultA.onclick = (event: Event) =>
if (document.body.contains(rootDiv)) {
document.body.removeChild(rootDiv)
}

val packageDiv = document.createElement("div").asInstanceOf[html.Div]
packageDiv.classList.add("scaladoc-searchbar-inkuire-package")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ trait Locations(using ctx: DocContext):

def resolveRoot(dri: DRI, path: String): String = resolveRoot(rawLocation(dri), path)
def absolutePath(dri: DRI, extension: String = "html"): String = rawLocation(dri).mkString("", "/", s".$extension")
def absolutePathWithAnchor(dri: DRI, extension: String = "html"): String = s"${absolutePath(dri, extension)}#${dri.anchor}"

def resolveLink(dri: DRI, url: String): String =
if URI(url).isAbsolute then url else resolveRoot(dri, url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ trait Resources(using ctx: DocContext) extends Locations, Writer:
}.mkString

def mkEntry(dri: DRI, name: String, text: String, descr: String, kind: String) = jsonObject(
"l" -> jsonString(absolutePath(dri)),
"l" -> jsonString(absolutePathWithAnchor(dri)),
"n" -> jsonString(name),
"t" -> jsonString(text),
"d" -> jsonString(descr),
Expand Down
10 changes: 7 additions & 3 deletions scaladoc/src/dotty/tools/scaladoc/tasty/InkuireSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import collection.JavaConverters._
import dotty.tools.scaladoc._
import dotty.tools.scaladoc.{Signature => DSignature}
import dotty.tools.scaladoc.Inkuire
import dotty.tools.scaladoc.renderers.Resources

import scala.util.Random
import scala.quoted._
Expand All @@ -13,10 +14,13 @@ import SymOps._
import NameNormalizer._
import SyntheticsSupport._

trait InkuireSupport:
trait InkuireSupport(using DocContext) extends Resources:
self: TastyParser =>
import qctx.reflect._

// Unused in InkuireSupport, required for Resources
override def effectiveMembers: Map[DRI, Member] = Map.empty

private given qctx.type = qctx

def doInkuireStuff(classDef: ClassDef): Unit = {
Expand Down Expand Up @@ -110,7 +114,7 @@ trait InkuireSupport:
),
name = name,
packageName = ownerName,
uri = methodSymbol.dri.externalLink.getOrElse(""),
uri = methodSymbol.dri.externalLink.getOrElse(absolutePathWithAnchor(methodSymbol.dri)),
entryType = "def"
)
val curriedSgn = sgn.copy(signature = Inkuire.curry(sgn.signature))
Expand Down Expand Up @@ -138,7 +142,7 @@ trait InkuireSupport:
),
name = name,
packageName = ownerName,
uri = valSymbol.dri.externalLink.getOrElse(""),
uri = valSymbol.dri.externalLink.getOrElse(absolutePathWithAnchor(valSymbol.dri)),
entryType = "val"
)
val curriedSgn = sgn.copy(signature = Inkuire.curry(sgn.signature))
Expand Down