@@ -10,21 +10,22 @@ module Code.Workspace exposing
10
10
, view
11
11
)
12
12
13
- import Api exposing (ApiRequest )
14
13
import Browser.Dom as Dom
14
+ import Code.CodebaseApi as CodebaseApi
15
+ import Code.Config exposing (Config )
15
16
import Code.Definition.Doc as Doc
16
17
import Code.Definition.Reference as Reference exposing (Reference )
18
+ import Code.EntityId as EntityId
17
19
import Code.FullyQualifiedName exposing (FQN )
18
20
import Code.Hash as Hash
19
21
import Code.HashQualified as HQ
20
- import Code.Perspective exposing (Perspective )
21
22
import Code.Workspace.WorkspaceItem as WorkspaceItem exposing (Item , WorkspaceItem )
22
23
import Code.Workspace.WorkspaceItems as WorkspaceItems exposing (WorkspaceItems )
23
- import Env exposing (Env )
24
24
import Html exposing (Html , article , div , section )
25
25
import Html.Attributes exposing (class , id )
26
26
import Http
27
- import Lib.OperatingSystem as OperatingSystem
27
+ import Lib.Api as Api exposing (ApiRequest )
28
+ import Lib.OperatingSystem as OperatingSystem exposing (OperatingSystem )
28
29
import Task
29
30
import UI.Button as Button
30
31
import UI.Icon as Icon
@@ -44,12 +45,12 @@ type alias Model =
44
45
}
45
46
46
47
47
- init : Env -> Maybe Reference -> ( Model , Cmd Msg )
48
- init env mRef =
48
+ init : Config -> Maybe Reference -> ( Model , Cmd Msg )
49
+ init config mRef =
49
50
let
50
51
model =
51
52
{ workspaceItems = WorkspaceItems . init Nothing
52
- , keyboardShortcut = KeyboardShortcut . init env . operatingSystem
53
+ , keyboardShortcut = KeyboardShortcut . init config . operatingSystem
53
54
}
54
55
in
55
56
case mRef of
@@ -59,7 +60,7 @@ init env mRef =
59
60
Just ref ->
60
61
let
61
62
( m, c ) =
62
- open env model ref
63
+ open config model ref
63
64
in
64
65
( m, c )
65
66
@@ -86,8 +87,8 @@ type OutMsg
86
87
| ChangePerspectiveToNamespace FQN
87
88
88
89
89
- update : Env -> Msg -> Model -> ( Model , Cmd Msg , OutMsg )
90
- update env msg ( { workspaceItems } as model) =
90
+ update : Config -> Msg -> Model -> ( Model , Cmd Msg , OutMsg )
91
+ update config msg ( { workspaceItems } as model) =
91
92
case msg of
92
93
NoOp ->
93
94
( model, Cmd . none, None )
@@ -177,14 +178,14 @@ update env msg ({ workspaceItems } as model) =
177
178
KeyboardShortcut . fromKeyboardEvent model. keyboardShortcut event
178
179
179
180
( nextModel, cmd, out ) =
180
- handleKeyboardShortcut env { model | keyboardShortcut = keyboardShortcut } shortcut
181
+ handleKeyboardShortcut config . operatingSystem { model | keyboardShortcut = keyboardShortcut } shortcut
181
182
in
182
183
( nextModel, Cmd . batch [ cmd, Cmd . map KeyboardShortcutMsg kCmd ], out )
183
184
184
185
WorkspaceItemMsg wiMsg ->
185
186
case wiMsg of
186
187
WorkspaceItem . OpenReference relativeToRef ref ->
187
- openReference env model relativeToRef ref
188
+ openReference config model relativeToRef ref
188
189
189
190
WorkspaceItem . Close ref ->
190
191
let
@@ -254,30 +255,30 @@ replaceWorkspaceItemReferencesWithHashOnly model =
254
255
{ model | workspaceItems = workspaceItems }
255
256
256
257
257
- open : Env -> WithWorkspaceItems m -> Reference -> ( WithWorkspaceItems m , Cmd Msg )
258
- open env model ref =
259
- openItem env model Nothing ref
258
+ open : Config -> WithWorkspaceItems m -> Reference -> ( WithWorkspaceItems m , Cmd Msg )
259
+ open config model ref =
260
+ openItem config model Nothing ref
260
261
261
262
262
263
{- | openReference opens a definition relative to another definition. This is
263
264
done within Workspace, as opposed to from the outside via a URL change. This
264
265
function returns a Focused command for the newly opened reference and as such
265
266
changes the URL.
266
267
-}
267
- openReference : Env -> WithWorkspaceItems m -> Reference -> Reference -> ( WithWorkspaceItems m , Cmd Msg , OutMsg )
268
- openReference env model relativeToRef ref =
268
+ openReference : Config -> WithWorkspaceItems m -> Reference -> Reference -> ( WithWorkspaceItems m , Cmd Msg , OutMsg )
269
+ openReference config model relativeToRef ref =
269
270
let
270
271
( newModel, cmd ) =
271
- openItem env model ( Just relativeToRef) ref
272
+ openItem config model ( Just relativeToRef) ref
272
273
273
274
out =
274
275
openDefinitionsFocusToOutMsg newModel. workspaceItems
275
276
in
276
277
( newModel, cmd, out )
277
278
278
279
279
- openItem : Env -> WithWorkspaceItems m -> Maybe Reference -> Reference -> ( WithWorkspaceItems m , Cmd Msg )
280
- openItem env ( { workspaceItems } as model) relativeToRef ref =
280
+ openItem : Config -> WithWorkspaceItems m -> Maybe Reference -> Reference -> ( WithWorkspaceItems m , Cmd Msg )
281
+ openItem config ( { workspaceItems } as model) relativeToRef ref =
281
282
-- We don't want to refetch or replace any already open definitions, but we
282
283
-- do want to focus and scroll to it
283
284
if WorkspaceItems . member workspaceItems ref then
@@ -303,7 +304,7 @@ openItem env ({ workspaceItems } as model) relativeToRef ref =
303
304
WorkspaceItems . insertWithFocusBefore workspaceItems r toInsert
304
305
in
305
306
( { model | workspaceItems = nextWorkspaceItems }
306
- , Cmd . batch [ Api . perform env . apiBasePath ( fetchDefinition env . perspective ref) , scrollToDefinition ref ]
307
+ , Cmd . batch [ Api . perform config . apiBasePath ( fetchDefinition config ref) , scrollToDefinition ref ]
307
308
)
308
309
309
310
@@ -315,8 +316,8 @@ openDefinitionsFocusToOutMsg openDefs =
315
316
|> Maybe . withDefault Emptied
316
317
317
318
318
- handleKeyboardShortcut : Env -> Model -> KeyboardShortcut -> ( Model , Cmd Msg , OutMsg )
319
- handleKeyboardShortcut env ( { workspaceItems } as model) shortcut =
319
+ handleKeyboardShortcut : OperatingSystem -> Model -> KeyboardShortcut -> ( Model , Cmd Msg , OutMsg )
320
+ handleKeyboardShortcut os ( { workspaceItems } as model) shortcut =
320
321
let
321
322
scrollToCmd =
322
323
WorkspaceItems . focus
@@ -357,7 +358,7 @@ handleKeyboardShortcut env ({ workspaceItems } as model) shortcut =
357
358
( model, Cmd . none, ShowFinderRequest Nothing )
358
359
359
360
KeyboardShortcut . Chord Meta ( K _) ->
360
- if env . operatingSystem == OperatingSystem . MacOS then
361
+ if os == OperatingSystem . MacOS then
361
362
( model, Cmd . none, ShowFinderRequest Nothing )
362
363
363
364
else
@@ -432,14 +433,28 @@ handleKeyboardShortcut env ({ workspaceItems } as model) shortcut =
432
433
-- EFFECTS
433
434
434
435
435
- fetchDefinition : Perspective -> Reference -> ApiRequest Item Msg
436
- fetchDefinition perspective ref =
436
+ fetchDefinition : Config -> Reference -> ApiRequest Item Msg
437
+ fetchDefinition config ref =
437
438
let
438
- definitionHash =
439
- ( Reference . hashQualified >> HQ . toString) ref
439
+ definitionId =
440
+ case Reference . hashQualified ref of
441
+ HQ . NameOnly fqn ->
442
+ EntityId . NameId fqn
443
+
444
+ HQ . HashOnly h ->
445
+ EntityId . HashId h
446
+
447
+ HQ . HashQualified _ h ->
448
+ EntityId . HashId h
449
+
450
+ endpoint =
451
+ CodebaseApi . Definition
452
+ { perspective = config. perspective
453
+ , definitionId = definitionId
454
+ }
440
455
in
441
- [ definitionHash ]
442
- |> Api . getDefinition perspective
456
+ endpoint
457
+ |> config . toApiEndpointUrl
443
458
|> Api . toRequest ( WorkspaceItem . decodeItem ref) ( FetchItemFinished ref)
444
459
445
460
0 commit comments