Skip to content

Commit 9939009

Browse files
committed
Refactor
- Test only the assets and Api link
1 parent cd73a8d commit 9939009

File tree

3 files changed

+6
-74
lines changed

3 files changed

+6
-74
lines changed

scaladoc/src/dotty/tools/scaladoc/renderers/MemberRenderer.scala

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -112,54 +112,19 @@ class MemberRenderer(signatureRenderer: SignatureRenderer)(using DocContext) ext
112112
def validationLink(str: String): String =
113113
def asValidURL = Try(URL(str)).toOption.map(_ => str)
114114

115-
def asAsset =
116-
Option.when(
117-
Files.exists(Paths.get("src/main/ressources").resolve(str.stripPrefix("/")))
118-
)(
119-
s"src/main/ressources/$str"
120-
)
121-
122-
def asStaticSite: Option[String] =
123-
Option.when(
124-
Files.exists(Paths.get("docs/_docs").resolve(str.stripPrefix("/")))
125-
)(
126-
s"docs/_docs/$str"
127-
)
128-
129-
def asApiLink: Option[String] =
130-
val strWithoutHtml = if str.endsWith("$.html") then
131-
str.stripSuffix("$.html")
132-
else
133-
str.stripSuffix(".html")
134-
val sourceDir = Paths.get("src", "main", "scala")
135-
val scalaPath = sourceDir.resolve(s"$strWithoutHtml.scala")
136-
val scalaDirPath = sourceDir.resolve(strWithoutHtml)
137-
Option.when(
138-
Files.exists(scalaPath) || Files.exists(scalaDirPath))
139-
(
140-
s"api/$strWithoutHtml.html"
141-
)
142-
115+
def asAsset: Option[String] = Option.when(
116+
Files.exists(Paths.get("docs/_assets").resolve(str))
117+
)(
118+
s"docs/_assets/$str"
119+
)
143120

144121
asValidURL
145-
.orElse(asStaticSite)
146122
.orElse(asAsset)
147-
.orElse(asApiLink)
148123
.getOrElse{
149124
report.warning(s"Unable to resolve link '$str'")
150125
str
151126
}
152127

153-
// println(asValidURL)
154-
155-
// println(Paths.get("src/main/ressources").resolve(str.stripPrefix("/")).toAbsolutePath)
156-
// println(Files.exists(Paths.get("src/main/ressources").resolve(str.stripPrefix("/"))))
157-
// def asAsset = Option.when(
158-
// Files.exists(Paths.get("docs/_assets").resolve(str.stripPrefix("/")))
159-
// )(
160-
// s"docs/_assets/$str"
161-
// )
162-
163128
def memberInfo(m: Member, withBrief: Boolean = false, full: Boolean = false): Seq[AppliedTag] =
164129
val comment = m.docs
165130
val bodyContents = m.docs.fold(Nil)(e => renderDocPart(e.body) :: Nil)
@@ -189,14 +154,6 @@ class MemberRenderer(signatureRenderer: SignatureRenderer)(using DocContext) ext
189154
element.attr("src", validationLink(element.attr("src")))
190155
)
191156

192-
document.select("a").forEach(element =>
193-
element.attr("href", processLocalLinkWithGuard(element.attr("href")))
194-
)
195-
196-
// document2.select("a").forEach(element =>
197-
// println("BONJOUR"+element.attr("href"))
198-
// ) <--- Take some href that I don't want
199-
200157
Seq(
201158
Option.when(withBrief && comment.flatMap(_.short).nonEmpty)(div(cls := "documentableBrief doc")(comment.flatMap(_.short).fold("")(renderDocPart))),
202159
Option.when(bodyContents.nonEmpty || attributes.nonEmpty)(

scaladoc/src/dotty/tools/scaladoc/tasty/comments/Comments.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ abstract class MarkupConversion[T](val repr: Repr)(using dctx: DocContext) {
112112
case None => sym.dri
113113
DocLink.ToDRI(dri, targetText)
114114
case None =>
115-
val txt = s"No DRI found for query"
115+
val txt = s"No DRI found for query, the link seems to be wrong or the file may not exist."
116116
val msg = s"$txt: $queryStr"
117117

118118
if (!summon[DocContext].args.noLinkWarnings) then

scaladoc/src/dotty/tools/scaladoc/tasty/comments/Preparser.scala

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -132,32 +132,7 @@ object Preparser {
132132
val stripTags = List(inheritDiagramTag, contentDiagramTag, SimpleTagKey("template"), SimpleTagKey("documentable"))
133133
val tagsWithoutDiagram = tags.filterNot(pair => stripTags.contains(pair._1))
134134

135-
def processLink: Unit =
136-
if (!summon[DocContext].args.noLinkWarnings) then tags.get(SimpleTagKey("see")).get.foreach(link => {
137-
val newLink = link.replaceAll("\\[\\[|\\]\\]", "")
138-
val newUrl = new URL(newLink)
139-
if(Try(newUrl).isSuccess) {
140-
if(newUrl.getPath.contains("/docs/")) {
141-
if (newLink.contains("oracle") || newLink.contains("excludeValidation")) then None
142-
else
143-
// We check if the internal link to the static documentation is valid
144-
val docPath = newUrl.getPath.substring(newUrl.getPath.indexOf("/docs/"))
145-
.replaceFirst("/docs/(docs/)?", "docs/_docs/")
146-
.replace(".html", ".md")
147-
println(docPath)
148-
val fileExists = Files.exists(Paths.get(docPath))
149-
if !fileExists then
150-
val newDocPath = docPath + ".md"
151-
if !Files.exists(Paths.get(newDocPath)) then report.warning(s"Link to $newLink will return a 404 not found")
152-
}
153-
else None
154-
}
155-
else None
156-
})
157-
158135
val bodyTags: mutable.Map[TagKey, List[String]] =
159-
if tags.get(SimpleTagKey("see")).isDefined then
160-
processLink
161136
mutable.Map((tagsWithoutDiagram).toSeq: _*)
162137

163138
def allTags(key: SimpleTagKey): List[String] =

0 commit comments

Comments
 (0)