Skip to content

Commit c404611

Browse files
committed
Add Reference.toUrlPath
1 parent b16d6f5 commit c404611

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

src/Code/Definition/Reference.elm

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
module Code.Definition.Reference exposing (..)
22

3-
import Code.FullyQualifiedName exposing (FQN)
4-
import Code.Hash exposing (Hash)
3+
import Code.FullyQualifiedName as FQN exposing (FQN)
4+
import Code.Hash as Hash exposing (Hash)
55
import Code.HashQualified as HQ exposing (HashQualified)
6+
import List.Nonempty as NEL
67
import UI.Icon as Icon exposing (Icon)
78
import Url.Parser
89

@@ -199,3 +200,33 @@ map f ref =
199200

200201
DataConstructorReference hq ->
201202
DataConstructorReference (f hq)
203+
204+
205+
toUrlPath : Reference -> List String
206+
toUrlPath ref =
207+
let
208+
hqToPath hq =
209+
case hq of
210+
HQ.NameOnly fqn_ ->
211+
fqn_ |> FQN.toUrlSegments |> NEL.toList
212+
213+
HQ.HashOnly h ->
214+
[ Hash.toUrlString h ]
215+
216+
HQ.HashQualified _ h ->
217+
-- TODO: Currently not supported, since we favor the hash
218+
-- because HashQualified url parsing is broken
219+
[ Hash.toUrlString h ]
220+
in
221+
case ref of
222+
TypeReference hq ->
223+
"types" :: hqToPath hq
224+
225+
TermReference hq ->
226+
"terms" :: hqToPath hq
227+
228+
AbilityConstructorReference hq ->
229+
"ability-constructors" :: hqToPath hq
230+
231+
DataConstructorReference hq ->
232+
"data-constructors" :: hqToPath hq

0 commit comments

Comments
 (0)