Skip to content
This repository has been archived by the owner on Jul 19, 2022. It is now read-only.

Commit

Permalink
Move OperatingSystem to Lib and add CodebaseApi
Browse files Browse the repository at this point in the history
  • Loading branch information
hojberg committed Apr 6, 2022
1 parent 52383e5 commit 24f897b
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 33 deletions.
37 changes: 37 additions & 0 deletions src/Code/CodebaseApi.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Code.CodebaseApi exposing (..)

import Code.EntityId exposing (EntityId)
import Code.FullyQualifiedName exposing (FQN)
import Code.Perspective exposing (Perspective)
import Code.Syntax as Syntax
import Lib.Api as Api



{-
CodebaseApi
===========
The CodebaseApi module, describes the endpoints used for the Code library to
connect to a codebase, but is merely that; a description. Consumers of the Code
library will need to provide an implementation of `ToApiEndpointUrl` in order
to perform the actual HTTP requests.
-}


type CodebaseEndpoint
= Find
{ perspective : Perspective
, withinFqn : Maybe FQN
, limit : Int
, sourceWidth : Syntax.Width
, query : String
}
| Browse { perspective : Perspective, namespaceId : Maybe EntityId }
| Definition { perspective : Perspective, definitionId : EntityId }


type alias ToApiEndpointUrl =
CodebaseEndpoint -> Api.EndpointUrl
19 changes: 19 additions & 0 deletions src/Code/EntityId.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Code.EntityId exposing (EntityId, toString)

import Code.FullyQualifiedName as FQN exposing (FQN)
import Code.Hash as Hash exposing (Hash)


type EntityId
= HashId Hash
| NameId FQN


toString : EntityId -> String
toString id =
case id of
HashId h ->
Hash.toString h

NameId fqn ->
FQN.toString fqn
3 changes: 2 additions & 1 deletion src/Code/Workspace.elm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Env exposing (Env)
import Html exposing (Html, article, div, section)
import Html.Attributes exposing (class, id)
import Http
import Lib.OperatingSystem as OperatingSystem
import Task
import UI.Button as Button
import UI.Icon as Icon
Expand Down Expand Up @@ -356,7 +357,7 @@ handleKeyboardShortcut env ({ workspaceItems } as model) shortcut =
( model, Cmd.none, ShowFinderRequest Nothing )

KeyboardShortcut.Chord Meta (K _) ->
if env.operatingSystem == Env.MacOS then
if env.operatingSystem == OperatingSystem.MacOS then
( model, Cmd.none, ShowFinderRequest Nothing )

else
Expand Down
47 changes: 18 additions & 29 deletions src/Env.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@ module Env exposing (..)

import Api exposing (ApiBasePath(..))
import Browser.Navigation as Nav
import Code.CodebaseApi as CodebaseApi
import Code.Config
import Code.Perspective exposing (Perspective)


type OperatingSystem
= MacOS
| Windows
| Linux
| Android
| IOS
| Unknown
import Lib.Api
import Lib.OperatingSystem as OS exposing (OperatingSystem)


type alias Env =
Expand All @@ -32,31 +27,25 @@ type alias Flags =

init : Flags -> Nav.Key -> Perspective -> Env
init flags navKey perspective =
{ operatingSystem = operatingSystemFromString flags.operatingSystem
{ operatingSystem = OS.fromString flags.operatingSystem
, basePath = flags.basePath
, apiBasePath = ApiBasePath flags.apiBasePath
, navKey = navKey
, perspective = perspective
}


operatingSystemFromString : String -> OperatingSystem
operatingSystemFromString rawOs =
case rawOs of
"macOS" ->
MacOS

"iOS" ->
IOS

"Windows" ->
Windows
toCodeConfig : CodebaseApi.ToApiEndpointUrl -> Env -> Code.Config.Config
toCodeConfig toApiEndpointUrl env =
let
(ApiBasePath path) =
env.apiBasePath

"Android" ->
Android

"Linux" ->
Linux

_ ->
Unknown
apiBasePath =
Lib.Api.ApiBasePath path
in
{ operatingSystem = env.operatingSystem
, perspective = env.perspective
, toApiEndpointUrl = toApiEndpointUrl
, apiBasePath = apiBasePath
}
2 changes: 1 addition & 1 deletion src/UI/KeyboardShortcut.elm
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@

module UI.KeyboardShortcut exposing (..)

import Env exposing (OperatingSystem)
import Html exposing (Html, span, text)
import Html.Attributes exposing (class, classList)
import Lib.OperatingSystem exposing (OperatingSystem)
import List.Nonempty as NEL
import Process
import Task
Expand Down
2 changes: 1 addition & 1 deletion src/UI/KeyboardShortcut/Key.elm
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ module UI.KeyboardShortcut.Key exposing
, view
)

import Env exposing (OperatingSystem(..))
import Json.Decode as Decode
import Lib.OperatingSystem exposing (OperatingSystem(..))


type LetterCase
Expand Down
3 changes: 2 additions & 1 deletion src/UnisonLocal/App.elm
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import Code.Namespace as Namespace exposing (NamespaceDetails)
import Code.Perspective as Perspective exposing (Perspective(..))
import Code.Workspace as Workspace
import Code.Workspace.WorkspaceItems as WorkspaceItems
import Env exposing (Env, OperatingSystem(..))
import Env exposing (Env)
import Html exposing (Html, a, div, h1, h2, h3, nav, p, section, span, strong, text)
import Html.Attributes exposing (class, classList, href, id, rel, target, title)
import Html.Events exposing (onClick)
import Http
import Lib.OperatingSystem exposing (OperatingSystem(..))
import Lib.Util as Util
import RemoteData
import UI
Expand Down

0 comments on commit 24f897b

Please sign in to comment.