@@ -11,6 +11,11 @@ object SourceLink:
11
11
val SubPath = " ([^=]+)=(.+)" .r
12
12
val KnownProvider = raw " (\w+):\/\/([^\/]+)\/([^\/]+) " .r
13
13
val BrokenKnownProvider = raw " (\w+):\/\/.+ " .r
14
+ val ScalaDocPatten = raw " €\{(TPL_NAME|TPL_NAME|FILE_PATH|FILE_EXT|FILE_LINE|FILE_PATH_EXT)\} " .r
15
+ val SupportedScalaDocPatternReplacements = Map (
16
+ " €{FILE_PATH_EXT}" -> " {{ path }}" ,
17
+ " €{FILE_LINE}" -> " {{ line }}"
18
+ )
14
19
15
20
def githubTemplate (organization : String , repo : String )(revision : String ) =
16
21
s """ https://github.com/ $organization/ $repo/{{ operation | replace: "view", "blob" }}/ $revision/{{ path }}#L{{ line }} """ .stripMargin
@@ -22,8 +27,8 @@ object SourceLink:
22
27
private def parseLinkDefinition (s : String ): Option [SourceLink ] = ???
23
28
24
29
def parse (string : String , revision : Option [String ]): Either [String , SourceLink ] =
25
- def asRawTemplate =
26
- try Right (SourceLink (None ,Template .parse(string ))) catch
30
+ def asTemplate ( template : String ) =
31
+ try Right (SourceLink (None ,Template .parse(template ))) catch
27
32
case e : RuntimeException =>
28
33
Left (s " Failed to parse template: ${e.getMessage}" )
29
34
@@ -49,7 +54,14 @@ object SourceLink:
49
54
Right (SourceLink (Some (Paths .get(prefix)), template))
50
55
case BrokenKnownProvider (" gitlab" | " github" ) =>
51
56
Left (s " Does not match known provider syntax: `<name>://organization/repository` " )
52
- case template => asRawTemplate
57
+ case scaladocSetting if ScalaDocPatten .findFirstIn(scaladocSetting).nonEmpty =>
58
+ val all = ScalaDocPatten .findAllIn(scaladocSetting)
59
+ val (supported, unsupported) = all.partition(SupportedScalaDocPatternReplacements .contains)
60
+ if unsupported.nonEmpty then Left (s " Unsupported patterns from scaladoc format are used: ${unsupported.mkString(" " )}" )
61
+ else asTemplate(supported.foldLeft(string)((template, pattern) =>
62
+ template.replace(pattern, SupportedScalaDocPatternReplacements (pattern))))
63
+
64
+ case template => asTemplate(template)
53
65
54
66
55
67
type Operation = " view" | " edit"
@@ -86,8 +98,12 @@ object SourceLinks:
86
98
|where <source-link> is one of following:
87
99
| - `github://<organization>/<repository>` (requires revision to be specified as argument for scala3doc)
88
100
| - `gitlab://<organization>/<repository>` (requires revision to be specified as argument for scala3doc)
101
+ | - <scaladoc-template>
89
102
| - <template>
90
103
|
104
+ |<scaladoc-template> is a format for `doc-source-url` parameter scaladoc.
105
+ |NOTE: We only supports `€{FILE_PATH_EXT}` and €{FILE_LINE} patterns
106
+ |
91
107
|<template> is a liqid template string that can accepts follwoing arguments:
92
108
| - `operation`: either "view" or "edit"
93
109
| - `path`: relative path of file to provide link to
0 commit comments