Basic server working!

This commit is contained in:
runarorama 2020-10-01 15:30:45 -04:00
parent 60b0b7e8ed
commit 7b5f8bb168
2 changed files with 15 additions and 7 deletions

View File

@ -18,6 +18,7 @@ import Data.Text ( Text )
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import GHC.Generics
import Network.Wai.Handler.Warp ( run )
import Servant.API
import Servant.Server
import Servant ( throwError )
@ -39,7 +40,6 @@ import qualified Unison.Reference as Reference
import qualified Unison.Referent as Referent
import qualified Unison.Server.Backend as Backend
import Unison.ShortHash ( ShortHash )
import Unison.Symbol ( Symbol(..) )
import Unison.Type ( Type )
import Unison.Util.Pretty ( render
, Width
@ -49,6 +49,7 @@ import qualified Unison.Util.SyntaxText as SyntaxText
import Unison.Var ( Var )
import qualified Unison.TypePrinter as TypePrinter
--import GHC.TypeLits
--import Network.Wai.Handler.Warp
@ -102,7 +103,6 @@ instance ToJSON NamedTerm
data NamedType = NamedType
{ typeName :: HashQualifiedName
, typeHash :: UnisonHash
, typeKind :: Maybe KindExpression
} deriving Generic
instance ToJSON NamedType
@ -155,7 +155,6 @@ backendListEntryToNamespaceObject ppe typeWidth = \case
Backend.ShallowTypeEntry r name -> TypeObject $ NamedType
{ typeName = HQ'.toText name
, typeHash = Reference.toText r
, typeKind = Nothing
}
Backend.ShallowBranchEntry name size -> Subnamespace $ NamedNamespace
{ namespaceName = NameSegment.toText name
@ -210,16 +209,19 @@ noSuchNamespace namespace =
api :: Proxy API
api = Proxy
app :: Codebase IO Symbol Ann -> Application
app :: Var v => Codebase IO v Ann -> Application
app codebase = serve api $ server codebase
server :: Codebase IO Symbol Ann -> Server API
start :: Var v => Codebase IO v Ann -> Int -> IO ()
start codebase port = run port $ app codebase
server :: Var v => Codebase IO v Ann -> Server API
server codebase = serveNamespace :<|> foo
where
foo = pure ()
serveNamespace :: Maybe HashQualifiedName -> Handler NamespaceListing
serveNamespace hqn = case hqn of
Nothing -> undefined -- list the root
Nothing -> serveNamespace $ Just ""
-- parse client-specified hash-qualified name
Just hqn -> case HQ.fromText hqn of
Nothing -> throwError $ badHQN hqn
@ -260,3 +262,4 @@ server codebase = serveNamespace :<|> foo
-- error if path not found
-- gather the immediate children under the path
-- list them out

View File

@ -6,7 +6,10 @@
module Main where
import Unison.Prelude
import Control.Concurrent ( mkWeakThreadId, myThreadId )
import Control.Concurrent ( mkWeakThreadId
, myThreadId
, forkIO
)
import Control.Error.Safe (rightMay)
import Control.Exception ( throwTo, AsyncException(UserInterrupt) )
import Data.Configurator.Types ( Config )
@ -27,6 +30,7 @@ import qualified Unison.Runtime.Interface as RTI
import Unison.Symbol ( Symbol )
import qualified Unison.Codebase.Path as Path
import qualified Unison.Util.Cache as Cache
import qualified Unison.Server.CodebaseServer as Server
import qualified Version
import qualified Unison.Codebase.TranscriptParser as TR
import qualified System.Path as Path
@ -151,6 +155,7 @@ main = do
case restargs of
[] -> do
theCodebase <- FileCodebase.getCodebaseOrExit branchCache mcodepath
_ <- forkIO $ Server.start theCodebase 8081
launch currentDir mNewRun config theCodebase branchCache []
[version] | isFlag "version" version ->
putStrLn $ progName ++ " version: " ++ Version.gitDescribe