@@ -4,14 +4,17 @@ package tasty.comments
4
4
import scala .collection .mutable
5
5
import scala .collection .immutable .SortedMap
6
6
import scala .util .matching .Regex
7
+ import java .net .URL
8
+ import java .nio .file .{Paths , Files }
9
+ import scala .util .Try
7
10
8
11
object Preparser {
9
12
import Regexes ._
10
13
11
14
/** Parses a raw comment string into a `Comment` object. */
12
15
def preparse (
13
16
comment : List [String ],
14
- ): PreparsedComment = {
17
+ )( using DocContext ) : PreparsedComment = {
15
18
16
19
/** Parses a comment (in the form of a list of lines) to a `Comment`
17
20
* instance, recursively on lines. To do so, it splits the whole comment
@@ -135,6 +138,24 @@ object Preparser {
135
138
def allTags (key : SimpleTagKey ): List [String ] =
136
139
(bodyTags remove key).getOrElse(Nil ).reverse
137
140
141
+ def processLink (key : SimpleTagKey ): SimpleTagKey =
142
+ if (! summon[DocContext ].args.noLinkWarnings) then
143
+ bodyTags(key).foreach(link => {
144
+ val newLink : String = link.replaceAll(" \\ [\\ [|\\ ]\\ ]" , " " )
145
+ val isValid = Try (URL (newLink)).isSuccess
146
+ if isValid then
147
+ val url = new URL (newLink)
148
+ val path = url.getPath().replaceFirst(" /docs/" , " docs/_docs/" ).replace(" .html" , " .md" )
149
+ // We check if the internal link to the static documentation is valid
150
+ val fileExists = Files .exists(Paths .get(path))
151
+ if ! fileExists then
152
+ report.warning(s " Link to $url will return a 404 not found " )
153
+ else
154
+ report.warning(s " Link $link is not a valid URL " )
155
+ }
156
+ )
157
+ key
158
+
138
159
def allSymsOneTag (key : TagKey , filterEmpty : Boolean = true ): SortedMap [String , String ] = {
139
160
val keys : Seq [SymbolTagKey ] =
140
161
bodyTags.keys.toSeq flatMap {
@@ -157,7 +178,7 @@ object Preparser {
157
178
val cmt = PreparsedComment (
158
179
body = docBody.toString,
159
180
authors = allTags(SimpleTagKey (" author" )),
160
- see = allTags(SimpleTagKey (" see" )),
181
+ see = allTags(processLink( SimpleTagKey (" see" ) )),
161
182
result = allTags(SimpleTagKey (" return" )),
162
183
throws = allSymsOneTag(SimpleTagKey (" throws" )),
163
184
valueParams = allSymsOneTag(SimpleTagKey (" param" )),
0 commit comments