Skip to content

Commit 39278e6

Browse files
committed
Add Workspace.currentlyOpenFqns
1 parent e13c0bb commit 39278e6

File tree

4 files changed

+68
-2
lines changed

4 files changed

+68
-2
lines changed

src/Code/Definition/Info.elm

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,25 @@ type alias Info =
2222

2323

2424
makeInfo : Reference -> FQN -> NEL.Nonempty FQN -> Info
25-
makeInfo ref suffixName allFqns =
25+
makeInfo ref suffixName allFqns_ =
2626
let
2727
( namespace, otherNames ) =
28-
namespaceAndOtherNames ref suffixName allFqns
28+
namespaceAndOtherNames ref suffixName allFqns_
2929
in
3030
Info suffixName namespace otherNames
3131

3232

33+
allFqns : Info -> List FQN
34+
allFqns info =
35+
let
36+
reconstructed =
37+
info.namespace
38+
|> Maybe.map (\namespace -> FQN.extend namespace info.name)
39+
|> Maybe.withDefault info.name
40+
in
41+
reconstructed :: info.otherNames
42+
43+
3344

3445
-- Helpers
3546

src/Code/Workspace.elm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Code.Workspace exposing
22
( Model
33
, Msg
44
, OutMsg(..)
5+
, currentlyOpenFqns
56
, currentlyOpenReferences
67
, init
78
, open
@@ -585,6 +586,11 @@ currentlyOpenReferences model =
585586
WorkspaceItems.references model.workspaceItems
586587

587588

589+
currentlyOpenFqns : Model -> List FQN
590+
currentlyOpenFqns model =
591+
WorkspaceItems.fqns model.workspaceItems
592+
593+
588594

589595
-- EFFECTS
590596

src/Code/Workspace/WorkspaceItem.elm

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,30 @@ reference item =
181181
refResponse
182182

183183

184+
allFqns : WorkspaceItem -> List FQN
185+
allFqns workspaceItem =
186+
case workspaceItem of
187+
Loading r ->
188+
MaybeE.values [ Reference.fqn r ]
189+
190+
Failure r _ ->
191+
MaybeE.values [ Reference.fqn r ]
192+
193+
Success _ { item } ->
194+
case item of
195+
TermItem (Term _ _ { info }) ->
196+
Info.allFqns info
197+
198+
TypeItem (Type _ _ { info }) ->
199+
Info.allFqns info
200+
201+
AbilityConstructorItem (AbilityConstructor _ { info }) ->
202+
Info.allFqns info
203+
204+
DataConstructorItem (DataConstructor _ { info }) ->
205+
Info.allFqns info
206+
207+
184208
{-| Convert the Reference of a WorkspaceItem to be HashOnly
185209
-}
186210
toHashReference : WorkspaceItem -> WorkspaceItem

src/Code/Workspace/WorkspaceItems.elm

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
module Code.Workspace.WorkspaceItems exposing (..)
1919

2020
import Code.Definition.Reference exposing (Reference)
21+
import Code.FullyQualifiedName exposing (FQN)
2122
import Code.Hash exposing (Hash)
2223
import Code.Workspace.WorkspaceItem as WorkspaceItem exposing (WorkspaceItem)
2324
import List
@@ -288,6 +289,11 @@ references items =
288289
|> List.map WorkspaceItem.reference
289290

290291

292+
fqns : WorkspaceItems -> List FQN
293+
fqns items =
294+
concatMapToList (\i _ -> WorkspaceItem.allFqns i) items
295+
296+
291297
head : WorkspaceItems -> Maybe WorkspaceItem
292298
head items =
293299
items
@@ -525,6 +531,25 @@ mapToList f wItems =
525531
before ++ (f data.focus True :: after)
526532

527533

534+
concatMapToList : (WorkspaceItem -> Bool -> List a) -> WorkspaceItems -> List a
535+
concatMapToList f wItems =
536+
case wItems of
537+
Empty ->
538+
[]
539+
540+
WorkspaceItems data ->
541+
let
542+
before =
543+
data.before
544+
|> List.concatMap (\i -> f i False)
545+
546+
after =
547+
data.after
548+
|> List.concatMap (\i -> f i False)
549+
in
550+
before ++ f data.focus True ++ after
551+
552+
528553
{-| Converting the workspace items to a list, looses the focus indicator
529554
-}
530555
toList : WorkspaceItems -> List WorkspaceItem

0 commit comments

Comments
 (0)