Skip to content

Commit

Permalink
New modules for SyntaxSegment.view, Syntax.Linked
Browse files Browse the repository at this point in the history
  • Loading branch information
hojberg committed Jul 8, 2024
1 parent 5b4d104 commit 653029c
Show file tree
Hide file tree
Showing 11 changed files with 334 additions and 359 deletions.
5 changes: 3 additions & 2 deletions src/Code/Definition/Doc.elm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Code.Definition.Source as Source
import Code.Definition.Term exposing (TermSignature(..))
import Code.Source.SourceViewConfig as SourceViewConfig
import Code.Syntax as Syntax exposing (Syntax)
import Code.Syntax.Linked exposing (Linked(..), LinkedWithTooltipConfig)
import Dict exposing (Dict)
import Html
exposing
Expand Down Expand Up @@ -388,14 +389,14 @@ toString sep doc =
""


view : Syntax.LinkedWithTooltipConfig msg -> (FoldId -> msg) -> DocFoldToggles -> Doc -> Html msg
view : LinkedWithTooltipConfig msg -> (FoldId -> msg) -> DocFoldToggles -> Doc -> Html msg
view linkedCfg toggleFoldMsg docFoldToggles document =
let
viewSignature =
Source.viewTermSignature (SourceViewConfig.rich linkedCfg)

linked =
Syntax.LinkedWithTooltip linkedCfg
LinkedWithTooltip linkedCfg

viewSyntax =
Syntax.view linked
Expand Down
4 changes: 2 additions & 2 deletions src/Code/Definition/Readme.elm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Code.Definition.Readme exposing (..)

import Code.Definition.Doc as Doc exposing (Doc, DocFoldToggles, FoldId)
import Code.Syntax as Syntax
import Code.Syntax.Linked exposing (LinkedWithTooltipConfig)
import Html exposing (Html, div)
import Html.Attributes exposing (class)
import Json.Decode as Decode
Expand All @@ -20,7 +20,7 @@ type Readme


view :
Syntax.LinkedWithTooltipConfig msg
LinkedWithTooltipConfig msg
-> (FoldId -> msg)
-> DocFoldToggles
-> Readme
Expand Down
12 changes: 6 additions & 6 deletions src/Code/DefinitionDetailTooltip.elm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Code.Definition.Type as Type exposing (Type(..), TypeDetail)
import Code.FullyQualifiedName as FQN
import Code.Hash as Hash
import Code.Source.SourceViewConfig as SourceViewConfig
import Code.Syntax as Syntax
import Code.Syntax.Linked exposing (Linked(..), TooltipConfig)
import Dict exposing (Dict)
import Html exposing (div)
import Html.Attributes exposing (class)
Expand Down Expand Up @@ -130,7 +130,7 @@ update config msg model =

{-| This is intended to be used over `view`, and comes with a way to map the msg.
-}
tooltipConfig : (Msg -> msg) -> Model -> Syntax.TooltipConfig msg
tooltipConfig : (Msg -> msg) -> Model -> TooltipConfig msg
tooltipConfig toMsg model =
{ toHoverStart = ShowTooltip >> toMsg
, toHoverEnd = HideTooltip >> toMsg
Expand Down Expand Up @@ -161,16 +161,16 @@ viewDetail detail =
viewDetail_ s =
case s of
TermHover (Term _ _ { info, source }) ->
Source.viewTermSource (SourceViewConfig.rich_ Syntax.NotLinked) info.name source
Source.viewTermSource (SourceViewConfig.rich_ NotLinked) info.name source

TypeHover (Type _ _ { source }) ->
Source.viewTypeSource (SourceViewConfig.rich_ Syntax.NotLinked) source
Source.viewTypeSource (SourceViewConfig.rich_ NotLinked) source

AbilityConstructorHover (AbilityConstructor _ { source }) ->
Source.viewTypeSource (SourceViewConfig.rich_ Syntax.NotLinked) source
Source.viewTypeSource (SourceViewConfig.rich_ NotLinked) source

DataConstructorHover (DataConstructor _ { source }) ->
Source.viewTypeSource (SourceViewConfig.rich_ Syntax.NotLinked) source
Source.viewTypeSource (SourceViewConfig.rich_ NotLinked) source

loading =
Tooltip.rich
Expand Down
11 changes: 6 additions & 5 deletions src/Code/DefinitionSummaryTooltip.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Code.Definition.Type as Type exposing (Type(..), TypeSummary, typeSourceS
import Code.FullyQualifiedName as FQN
import Code.Hash as Hash
import Code.Syntax as Syntax
import Code.Syntax.Linked exposing (Linked(..), TooltipConfig)
import Code.Syntax.SyntaxSegment as SyntaxSegment
import Dict exposing (Dict)
import Html exposing (div, span, text)
Expand Down Expand Up @@ -129,7 +130,7 @@ update config msg model =

{-| This is intended to be used over `view`, and comes with a way to map the msg.
-}
tooltipConfig : (Msg -> msg) -> Model -> Syntax.TooltipConfig msg
tooltipConfig : (Msg -> msg) -> Model -> TooltipConfig msg
tooltipConfig toMsg model =
{ toHoverStart = ShowTooltip >> toMsg
, toHoverEnd = HideTooltip >> toMsg
Expand Down Expand Up @@ -204,19 +205,19 @@ viewSummary summary =
viewSummary_ s =
case s of
TermHover (Term _ _ { signature }) ->
Syntax.view Syntax.NotLinked (termSignatureSyntax signature)
Syntax.view NotLinked (termSignatureSyntax signature)

TypeHover (Type h _ { fqn, source }) ->
source
|> viewTypeSourceSyntax h fqn
|> Maybe.map (Syntax.view Syntax.NotLinked)
|> Maybe.map (Syntax.view NotLinked)
|> Maybe.withDefault (viewBuiltinType h fqn)

AbilityConstructorHover (AbilityConstructor _ { signature }) ->
Syntax.view Syntax.NotLinked (termSignatureSyntax signature)
Syntax.view NotLinked (termSignatureSyntax signature)

DataConstructorHover (DataConstructor _ { signature }) ->
Syntax.view Syntax.NotLinked (termSignatureSyntax signature)
Syntax.view NotLinked (termSignatureSyntax signature)

loading =
Tooltip.rich
Expand Down
4 changes: 2 additions & 2 deletions src/Code/ReadmeCard.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Code.Definition.Doc as Doc exposing (DocFoldToggles)
import Code.Definition.Readme as Readme exposing (Readme)
import Code.Definition.Reference exposing (Reference)
import Code.DefinitionSummaryTooltip as DefinitionSummaryTooltip
import Code.Syntax as Syntax
import Code.Syntax.Linked exposing (linkedWithTooltipConfig)
import Html exposing (Html, p)
import UI.Button as Button
import UI.Card as Card exposing (Card)
Expand Down Expand Up @@ -71,7 +71,7 @@ asCard : Model -> Readme -> Card Msg
asCard model readme =
let
syntaxConfig =
Syntax.linkedWithTooltipConfig
linkedWithTooltipConfig
(OpenReference >> Click.onClick)
(DefinitionSummaryTooltip.tooltipConfig
DefinitionSummaryTooltipMsg
Expand Down
14 changes: 7 additions & 7 deletions src/Code/Source/SourceViewConfig.elm
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ module Code.Source.SourceViewConfig exposing
, toSyntaxLinked
)

import Code.Syntax as Syntax
import Code.Syntax.Linked exposing (Linked(..), LinkedWithTooltipConfig)


type SourceViewConfig msg
= Rich (Syntax.Linked msg)
= Rich (Linked msg)
| Monochrome
| Plain


rich : Syntax.LinkedWithTooltipConfig msg -> SourceViewConfig msg
rich : LinkedWithTooltipConfig msg -> SourceViewConfig msg
rich linkedWithTooltip =
rich_ (Syntax.LinkedWithTooltip linkedWithTooltip)
rich_ (LinkedWithTooltip linkedWithTooltip)


rich_ : Syntax.Linked msg -> SourceViewConfig msg
rich_ : Linked msg -> SourceViewConfig msg
rich_ =
Rich

Expand Down Expand Up @@ -54,11 +54,11 @@ toClassName viewConfig =
"plain"


toSyntaxLinked : SourceViewConfig msg -> Syntax.Linked msg
toSyntaxLinked : SourceViewConfig msg -> Linked msg
toSyntaxLinked viewConfig =
case viewConfig of
Rich linked ->
linked

_ ->
Syntax.NotLinked
NotLinked
Loading

0 comments on commit 653029c

Please sign in to comment.