aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuchen Pei <hi@ypei.me>2022-10-05 11:54:57 +1100
committerYuchen Pei <hi@ypei.me>2022-10-05 11:54:57 +1100
commit918dcdb602622af47f0607519b95c3aa2abab5ff (patch)
treeb2c0b34ada776f2fa9cbcd0c3440d350c06190ce
parent0fc6e35633ff69a8ff08784d32623f794ccba37b (diff)
Adding a greet api to get server info (currently only version)
-rw-r--r--app/Server.hs16
-rw-r--r--hcel.cabal2
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