From 918dcdb602622af47f0607519b95c3aa2abab5ff Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 5 Oct 2022 11:54:57 +1100 Subject: Adding a greet api to get server info (currently only version) --- app/Server.hs | 16 ++++++++++++---- hcel.cabal | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/Server.hs b/app/Server.hs index 1c9980d..e4efd36 100644 --- a/app/Server.hs +++ b/app/Server.hs @@ -48,7 +48,7 @@ import Data.IntervalMap.Interval (Interval(..), subsumes) import qualified Data.IntervalMap.Strict as IVM import qualified Data.List as L import qualified Data.Map.Strict as M -import Data.Maybe (fromMaybe, listToMaybe, mapMaybe) +import Data.Maybe (fromMaybe, mapMaybe) import qualified Data.Vector as V import qualified GHC.Compact as C import Data.Pagination @@ -67,7 +67,7 @@ import qualified Data.Text as T import qualified Data.Text.Encoding as TE import Data.Text.Lazy (toStrict) import Data.Text.Read(decimal) -import Data.Version (Version(..)) +import Data.Version (Version(..), showVersion) import GHC.Exts (Down(..), groupWith) import GHC.Generics (Generic) import qualified HaskellCodeExplorer.Types as HCE @@ -114,6 +114,7 @@ import Options.Applicative , strOption , switch ) +import qualified Paths_hcel (version) import Servant ( (:<|>)(..) , (:>) @@ -909,7 +910,8 @@ handleSync onError = -- Servant API -------------------------------------------------------------------------------- -type API = GetAllPackages +type API = Greet + :<|> GetAllPackages :<|> GetDefinitionSite :<|> GetExpressions :<|> GetReferences @@ -920,6 +922,8 @@ type API = GetAllPackages :<|> GetGlobalIdentifierE :<|> GetHoogleDocs +type Greet = "api" :> "greet" :> Get '[JSON] T.Text + type GetAllPackages = "api" :> "packages" :> Get '[JSON] AllPackages type GetDefinitionSite = "api" :> "definitionSite" @@ -1067,6 +1071,9 @@ data SourceFile = SourceFile instance A.ToJSON ReferenceWithSource instance A.ToJSON SourceFile +greet :: ReaderT Environment IO T.Text +greet = return $ T.pack $ showVersion Paths_hcel.version + getAllPackages :: ReaderT Environment IO AllPackages getAllPackages = asks envPackageVersions @@ -1853,7 +1860,8 @@ server env = hoistServer (Proxy :: Proxy API) toServantHandler - (getAllPackages :<|> + (greet :<|> + getAllPackages :<|> getDefinitionSite :<|> getExpressions :<|> getReferences :<|> diff --git a/hcel.cabal b/hcel.cabal index 99fde6d..34d7c2d 100644 --- a/hcel.cabal +++ b/hcel.cabal @@ -80,7 +80,7 @@ executable haskell-code-server main-is: Server.hs ghc-options: -Wall -O2 -rtsopts -funbox-strict-fields -threaded hs-source-dirs: app,src - other-modules: HaskellCodeExplorer.Types, Store + other-modules: HaskellCodeExplorer.Types, Paths_hcel, Store build-depends: IntervalMap , aeson , base -- cgit v1.2.3