{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module Unison.Server.Local.Endpoints.Definitions where
import Data.Bifoldable (Bifoldable (..))
import Data.Bitraversable (Bitraversable (..))
import Data.Set qualified as Set
import Servant
( QueryParam,
QueryParams,
ServerT,
(:<|>) (..),
(:>),
)
import Servant.Docs
( DocQueryParam (..),
ParamKind (..),
ToParam (..),
ToSample (..),
noSamples,
)
import U.Codebase.Causal qualified as Causal
import U.Codebase.Reference (TermReferenceId)
import Unison.Codebase (Codebase)
import Unison.Codebase qualified as Codebase
import Unison.Codebase.Branch qualified as Branch
import Unison.Codebase.Branch.Names qualified as Branch
import Unison.Codebase.Path qualified as Path
import Unison.Codebase.ProjectPath
import Unison.HashQualified qualified as HQ
import Unison.Name (Name)
import Unison.NamesWithHistory (SearchType (..))
import Unison.Parser.Ann (Ann)
import Unison.Prelude
import Unison.PrettyPrintEnv qualified as PPE
import Unison.PrettyPrintEnv.Names qualified as PPE
import Unison.PrettyPrintEnvDecl qualified as PPED
import Unison.Project
import Unison.Reference qualified as Reference
import Unison.Referent qualified as Referent
import Unison.Runtime (Runtime)
import Unison.Server.Backend qualified as Backend
import Unison.Server.Local.Definitions qualified as Local
import Unison.Server.NameSearch.FromNames (makeNameSearch)
import Unison.Server.QueryResult (QueryResult (..))
import Unison.Server.SearchResult (SearchResult (..), TermResult (..), TypeResult (..))
import Unison.Server.Types
( APIGet,
APIHeaders,
DefinitionDisplayResults,
DefinitionSearchResult (..),
DefinitionSearchResults (..),
RequiredQueryParam,
Suffixify (..),
TermOrTypeSummary (..),
defaultWidth,
setCacheControl,
)
import Unison.Symbol (Symbol)
import Unison.Util.Defns (Defns (..))
import Unison.Util.Monoid (foldMapM)
import Unison.Util.Pretty (Width)
type DefinitionsAPI =
("getDefinition" :> GetDefinitionEndpoint)
:<|> ("getDefinitionDependents" :> GetDefinitionDependentsEndpoint)
:<|> ("getDefinitionDependencies" :> GetDefinitionDependenciesEndpoint)
type GetDefinitionEndpoint =
QueryParam "relativeTo" Path.Path
:> QueryParams "names" (HQ.HashQualified Name)
:> QueryParam "renderWidth" Width
:> QueryParam "suffixifyBindings" Suffixify
:> APIGet DefinitionDisplayResults
type GetDefinitionDependentsEndpoint =
RequiredQueryParam "name" (HQ.HashQualified Name)
:> QueryParam "renderWidth" Width
:> APIGet DefinitionSearchResults
type GetDefinitionDependenciesEndpoint =
RequiredQueryParam "name" (HQ.HashQualified Name)
:> QueryParam "renderWidth" Width
:> APIGet DefinitionSearchResults
instance ToParam (QueryParam "renderWidth" Width) where
toParam :: Proxy (QueryParam "renderWidth" Width) -> DocQueryParam
toParam Proxy (QueryParam "renderWidth" Width)
_ =
String -> [String] -> String -> ParamKind -> DocQueryParam
DocQueryParam
String
"renderWidth"
[String
"80", String
"100", String
"120"]
( String
"The preferred maximum line width (in characters) of the source code of "
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"definitions to be rendered. "
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"If left absent, the render width is assumed to be "
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Width -> String
forall a. Show a => a -> String
show Width
defaultWidth
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"."
)
ParamKind
Normal
instance ToParam (QueryParam "suffixifyBindings" Suffixify) where
toParam :: Proxy (QueryParam "suffixifyBindings" Suffixify) -> DocQueryParam
toParam Proxy (QueryParam "suffixifyBindings" Suffixify)
_ =
String -> [String] -> String -> ParamKind -> DocQueryParam
DocQueryParam
String
"suffixifyBindings"
[String
"True", String
"False"]
( String
"If True or absent, renders definitions using the shortest unambiguous "
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"suffix. If False, uses the fully qualified name. "
)
ParamKind
Normal
instance ToParam (QueryParam "relativeTo" Path.Path) where
toParam :: Proxy (QueryParam "relativeTo" Path) -> DocQueryParam
toParam Proxy (QueryParam "relativeTo" Path)
_ =
String -> [String] -> String -> ParamKind -> DocQueryParam
DocQueryParam
String
"relativeTo"
[]
( String
"The namespace relative to which names will be resolved and displayed. "
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"If left absent, the root namespace will be used."
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"E.g. base.List"
)
ParamKind
Normal
instance ToParam (QueryParam "namespace" Path.Path) where
toParam :: Proxy (QueryParam "namespace" Path) -> DocQueryParam
toParam Proxy (QueryParam "namespace" Path)
_ =
String -> [String] -> String -> ParamKind -> DocQueryParam
DocQueryParam
String
"namespace"
[]
( String
"The namespace required by the endpoint."
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"If left absent, the relativeTo namespace will be used."
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"E.g. base.List"
)
ParamKind
Normal
instance ToParam (QueryParams "names" (HQ.HashQualified Name)) where
toParam :: Proxy (QueryParams "names" (HashQualified Name)) -> DocQueryParam
toParam Proxy (QueryParams "names" (HashQualified Name))
_ =
String -> [String] -> String -> ParamKind -> DocQueryParam
DocQueryParam
String
"names"
[String
".base.List", String
"foo.bar", String
"@abc123"]
(String
"A fully qualified name, hash-qualified name, " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"or hash.")
ParamKind
List
instance ToSample DefinitionDisplayResults where
toSamples :: Proxy DefinitionDisplayResults
-> [(Text, DefinitionDisplayResults)]
toSamples Proxy DefinitionDisplayResults
_ = [(Text, DefinitionDisplayResults)]
forall a. [(Text, a)]
noSamples
getDefinitionDependentsEndpoint ::
Runtime Symbol ->
Codebase IO Symbol Ann ->
ProjectAndBranch ProjectName ProjectBranchName ->
HQ.HashQualified Name ->
Maybe Width ->
Backend.Backend IO (APIHeaders DefinitionSearchResults)
getDefinitionDependentsEndpoint :: Runtime Symbol
-> Codebase IO Symbol Ann
-> ProjectAndBranch ProjectName ProjectBranchName
-> HashQualified Name
-> Maybe Width
-> Backend IO (APIHeaders DefinitionSearchResults)
getDefinitionDependentsEndpoint Runtime Symbol
_rt Codebase IO Symbol Ann
codebase ProjectAndBranch ProjectName ProjectBranchName
projectAndBranch HashQualified Name
hqn Maybe Width
mayWidth = do
hqLength <- IO Int -> Backend IO Int
forall a. IO a -> Backend IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Int -> Backend IO Int) -> IO Int -> Backend IO Int
forall a b. (a -> b) -> a -> b
$ Codebase IO Symbol Ann -> Transaction Int -> IO Int
forall (m :: * -> *) v a b.
MonadIO m =>
Codebase m v a -> Transaction b -> m b
Codebase.runTransaction Codebase IO Symbol Ann
codebase (Transaction Int -> IO Int) -> Transaction Int -> IO Int
forall a b. (a -> b) -> a -> b
$ Transaction Int
Codebase.hashLength
rootCausal <- Backend.resolveProjectRoot codebase projectAndBranch
(dependents, namesWithoutLibdeps) <- Backend.hoistBackend (Codebase.runTransaction codebase) $ do
rootBranch <- lift $ Codebase.expectBranchForHashTx codebase (Causal.causalHash rootCausal)
let rootBranch0 = Branch Transaction -> Branch0 Transaction
forall (m :: * -> *). Branch m -> Branch0 m
Branch.head Branch Transaction
rootBranch
let rootBranch0WithoutLibdeps = Branch0 Transaction -> Branch0 Transaction
forall (m :: * -> *). Branch0 m -> Branch0 m
Branch.deleteLibdeps Branch0 Transaction
rootBranch0
let namesWithoutLibdeps = Branch0 Transaction -> Names
forall (m :: * -> *). Branch0 m -> Names
Branch.toNames (Branch0 Transaction -> Names) -> Branch0 Transaction -> Names
forall a b. (a -> b) -> a -> b
$ Branch0 Transaction -> Branch0 Transaction
forall (m :: * -> *). Branch0 m -> Branch0 m
Branch.deleteLibdeps Branch0 Transaction
rootBranch0
let nameSearch = Int -> Names -> NameSearch Transaction
forall (m :: * -> *). Applicative m => Int -> Names -> NameSearch m
makeNameSearch Int
hqLength Names
namesWithoutLibdeps
QueryResult {hits} <- lift $ Backend.hqNameQuery codebase nameSearch ExactName [hqn]
let defs =
[SearchResult]
hits [SearchResult]
-> ([SearchResult] -> Defns (Set Referent) (Set Reference))
-> Defns (Set Referent) (Set Reference)
forall a b. a -> (a -> b) -> b
& (SearchResult -> Defns (Set Referent) (Set Reference))
-> [SearchResult] -> Defns (Set Referent) (Set Reference)
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap \case
Tp TypeResult {Reference
reference :: Reference
reference :: TypeResult -> Reference
reference} -> Defns {terms :: Set Referent
terms = Set Referent
forall a. Set a
Set.empty, types :: Set Reference
types = (Reference -> Set Reference
forall a. a -> Set a
Set.singleton Reference
reference)}
Tm TermResult {Referent
referent :: Referent
referent :: TermResult -> Referent
referent} -> Defns {terms :: Set Referent
terms = (Referent -> Set Referent
forall a. a -> Set a
Set.singleton Referent
referent), types :: Set Reference
types = Set Reference
forall a. Set a
Set.empty}
dependents <- lift $ Codebase.dependentsWithinBranchScope rootBranch0WithoutLibdeps defs
pure (dependents, namesWithoutLibdeps)
let pped = Namer -> Suffixifier -> PrettyPrintEnvDecl
PPED.makePPED (Int -> Names -> Namer
PPE.hqNamer Int
10 Names
namesWithoutLibdeps) Suffixifier
PPE.dontSuffixify
definitionSearchResults <-
dependents
& bitraverse (wither (doTerm pped) . Set.toList) (wither (doType pped) . Set.toList)
definitionSearchResults
& bifold
& DefinitionSearchResults
& setCacheControl
& pure
where
project :: ProjectName
project = ProjectAndBranch ProjectName ProjectBranchName
projectAndBranch.project
branchRef :: ProjectBranchName
branchRef = ProjectAndBranch ProjectName ProjectBranchName
projectAndBranch.branch
doTerm :: PPED.PrettyPrintEnvDecl -> TermReferenceId -> Backend.Backend IO (Maybe DefinitionSearchResult)
doTerm :: PrettyPrintEnvDecl
-> TermReferenceId -> Backend IO (Maybe DefinitionSearchResult)
doTerm PrettyPrintEnvDecl
pped TermReferenceId
refId = MaybeT (Backend IO) DefinitionSearchResult
-> Backend IO (Maybe DefinitionSearchResult)
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT do
let referent :: Referent
referent = TermReferenceId -> Referent
Referent.fromTermReferenceId TermReferenceId
refId
fqn <- Maybe Name -> MaybeT (Backend IO) Name
forall (m :: * -> *) a. Applicative m => Maybe a -> MaybeT m a
hoistMaybe (Maybe Name -> MaybeT (Backend IO) Name)
-> Maybe Name -> MaybeT (Backend IO) Name
forall a b. (a -> b) -> a -> b
$ HashQualified Name -> Maybe Name
forall n. HashQualified n -> Maybe n
HQ.toName (HashQualified Name -> Maybe Name)
-> HashQualified Name -> Maybe Name
forall a b. (a -> b) -> a -> b
$ PrettyPrintEnv -> Referent -> HashQualified Name
PPE.termName (PrettyPrintEnvDecl -> PrettyPrintEnv
PPED.unsuffixifiedPPE PrettyPrintEnvDecl
pped) Referent
referent
summary <- lift $ Backend.termSummaryForReferent codebase referent Nothing (\Set LabeledDependency
_ -> PrettyPrintEnvDecl -> Transaction PrettyPrintEnvDecl
forall a. a -> Transaction a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PrettyPrintEnvDecl
pped) mayWidth
pure $
DefinitionSearchResult
{ fqn,
summary = ToTTermSummary summary,
project,
branchRef
}
doType :: PrettyPrintEnvDecl
-> TermReferenceId -> Backend IO (Maybe DefinitionSearchResult)
doType PrettyPrintEnvDecl
pped TermReferenceId
refId = do
MaybeT (Backend IO) DefinitionSearchResult
-> Backend IO (Maybe DefinitionSearchResult)
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT do
let reference :: Reference
reference = TermReferenceId -> Reference
Reference.fromId TermReferenceId
refId
fqn <- Maybe Name -> MaybeT (Backend IO) Name
forall (m :: * -> *) a. Applicative m => Maybe a -> MaybeT m a
hoistMaybe (Maybe Name -> MaybeT (Backend IO) Name)
-> Maybe Name -> MaybeT (Backend IO) Name
forall a b. (a -> b) -> a -> b
$ HashQualified Name -> Maybe Name
forall n. HashQualified n -> Maybe n
HQ.toName (HashQualified Name -> Maybe Name)
-> HashQualified Name -> Maybe Name
forall a b. (a -> b) -> a -> b
$ PrettyPrintEnv -> Reference -> HashQualified Name
PPE.typeName (PrettyPrintEnvDecl -> PrettyPrintEnv
PPED.unsuffixifiedPPE PrettyPrintEnvDecl
pped) Reference
reference
summary <- lift $ Backend.typeSummaryForReference codebase reference Nothing (\Set LabeledDependency
_ -> PrettyPrintEnvDecl -> Transaction PrettyPrintEnvDecl
forall a. a -> Transaction a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PrettyPrintEnvDecl
pped) mayWidth
pure $
DefinitionSearchResult
{ fqn,
summary = ToTTypeSummary summary,
project,
branchRef
}
getDefinitionDependenciesEndpoint ::
Runtime Symbol ->
Codebase IO Symbol Ann ->
ProjectAndBranch ProjectName ProjectBranchName ->
HQ.HashQualified Name ->
Maybe Width ->
Backend.Backend IO (APIHeaders DefinitionSearchResults)
getDefinitionDependenciesEndpoint :: Runtime Symbol
-> Codebase IO Symbol Ann
-> ProjectAndBranch ProjectName ProjectBranchName
-> HashQualified Name
-> Maybe Width
-> Backend IO (APIHeaders DefinitionSearchResults)
getDefinitionDependenciesEndpoint Runtime Symbol
_rt Codebase IO Symbol Ann
codebase ProjectAndBranch ProjectName ProjectBranchName
projectAndBranch HashQualified Name
hqn Maybe Width
mayWidth = do
hqLength <- IO Int -> Backend IO Int
forall a. IO a -> Backend IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Int -> Backend IO Int) -> IO Int -> Backend IO Int
forall a b. (a -> b) -> a -> b
$ Codebase IO Symbol Ann -> Transaction Int -> IO Int
forall (m :: * -> *) v a b.
MonadIO m =>
Codebase m v a -> Transaction b -> m b
Codebase.runTransaction Codebase IO Symbol Ann
codebase (Transaction Int -> IO Int) -> Transaction Int -> IO Int
forall a b. (a -> b) -> a -> b
$ Transaction Int
Codebase.hashLength
rootCausal <- Backend.resolveProjectRoot codebase projectAndBranch
(dependencies, names) <- Backend.hoistBackend (Codebase.runTransaction codebase) $ do
rootBranch <- lift $ Codebase.expectBranchForHashTx codebase (Causal.causalHash rootCausal)
let rootBranch0 = Branch Transaction -> Branch0 Transaction
forall (m :: * -> *). Branch m -> Branch0 m
Branch.head Branch Transaction
rootBranch
let names = Branch0 Transaction -> Names
forall (m :: * -> *). Branch0 m -> Names
Branch.toNames Branch0 Transaction
rootBranch0
let nameSearch = Int -> Names -> NameSearch Transaction
forall (m :: * -> *). Applicative m => Int -> Names -> NameSearch m
makeNameSearch Int
hqLength Names
names
QueryResult {hits} <- lift $ Backend.hqNameQuery codebase nameSearch ExactName [hqn]
let defs =
[SearchResult]
hits [SearchResult]
-> ([SearchResult] -> Defns (Set Referent) (Set Reference))
-> Defns (Set Referent) (Set Reference)
forall a b. a -> (a -> b) -> b
& (SearchResult -> Defns (Set Referent) (Set Reference))
-> [SearchResult] -> Defns (Set Referent) (Set Reference)
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap \case
Tp TypeResult {Reference
reference :: TypeResult -> Reference
reference :: Reference
reference} -> Defns {terms :: Set Referent
terms = Set Referent
forall a. Set a
Set.empty, types :: Set Reference
types = (Reference -> Set Reference
forall a. a -> Set a
Set.singleton Reference
reference)}
Tm TermResult {Referent
referent :: TermResult -> Referent
referent :: Referent
referent} -> Defns {terms :: Set Referent
terms = (Referent -> Set Referent
forall a. a -> Set a
Set.singleton Referent
referent), types :: Set Reference
types = Set Reference
forall a. Set a
Set.empty}
dependencies <- lift $ Codebase.directDependencies defs
pure (dependencies, names)
let pped = Namer -> Suffixifier -> PrettyPrintEnvDecl
PPED.makePPED (Int -> Names -> Namer
PPE.hqNamer Int
10 Names
names) Suffixifier
PPE.dontSuffixify
definitionSearchResults <-
dependencies
& bitraverse (wither (doTerm pped) . Set.toList) (wither (doType pped) . Set.toList)
definitionSearchResults
& bifold
& DefinitionSearchResults
& setCacheControl
& pure
where
project :: ProjectName
project = ProjectAndBranch ProjectName ProjectBranchName
projectAndBranch.project
branchRef :: ProjectBranchName
branchRef = ProjectAndBranch ProjectName ProjectBranchName
projectAndBranch.branch
doTerm :: PPED.PrettyPrintEnvDecl -> Reference.TermReference -> Backend.Backend IO (Maybe DefinitionSearchResult)
doTerm :: PrettyPrintEnvDecl
-> Reference -> Backend IO (Maybe DefinitionSearchResult)
doTerm PrettyPrintEnvDecl
pped Reference
reference = MaybeT (Backend IO) DefinitionSearchResult
-> Backend IO (Maybe DefinitionSearchResult)
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT do
let referent :: Referent
referent = Reference -> Referent
Referent.fromTermReference Reference
reference
fqn <- Maybe Name -> MaybeT (Backend IO) Name
forall (m :: * -> *) a. Applicative m => Maybe a -> MaybeT m a
hoistMaybe (Maybe Name -> MaybeT (Backend IO) Name)
-> Maybe Name -> MaybeT (Backend IO) Name
forall a b. (a -> b) -> a -> b
$ HashQualified Name -> Maybe Name
forall n. HashQualified n -> Maybe n
HQ.toName (HashQualified Name -> Maybe Name)
-> HashQualified Name -> Maybe Name
forall a b. (a -> b) -> a -> b
$ PrettyPrintEnv -> Referent -> HashQualified Name
PPE.termName (PrettyPrintEnvDecl -> PrettyPrintEnv
PPED.unsuffixifiedPPE PrettyPrintEnvDecl
pped) Referent
referent
summary <- lift $ Backend.termSummaryForReferent codebase referent Nothing (\Set LabeledDependency
_ -> PrettyPrintEnvDecl -> Transaction PrettyPrintEnvDecl
forall a. a -> Transaction a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PrettyPrintEnvDecl
pped) mayWidth
pure $
DefinitionSearchResult
{ fqn,
summary = ToTTermSummary summary,
project,
branchRef
}
doType :: PPED.PrettyPrintEnvDecl -> Reference.TypeReference -> Backend.Backend IO (Maybe DefinitionSearchResult)
doType :: PrettyPrintEnvDecl
-> Reference -> Backend IO (Maybe DefinitionSearchResult)
doType PrettyPrintEnvDecl
pped Reference
reference = do
MaybeT (Backend IO) DefinitionSearchResult
-> Backend IO (Maybe DefinitionSearchResult)
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT do
fqn <- Maybe Name -> MaybeT (Backend IO) Name
forall (m :: * -> *) a. Applicative m => Maybe a -> MaybeT m a
hoistMaybe (Maybe Name -> MaybeT (Backend IO) Name)
-> Maybe Name -> MaybeT (Backend IO) Name
forall a b. (a -> b) -> a -> b
$ HashQualified Name -> Maybe Name
forall n. HashQualified n -> Maybe n
HQ.toName (HashQualified Name -> Maybe Name)
-> HashQualified Name -> Maybe Name
forall a b. (a -> b) -> a -> b
$ PrettyPrintEnv -> Reference -> HashQualified Name
PPE.typeName (PrettyPrintEnvDecl -> PrettyPrintEnv
PPED.unsuffixifiedPPE PrettyPrintEnvDecl
pped) Reference
reference
summary <- lift $ Backend.typeSummaryForReference codebase reference Nothing (\Set LabeledDependency
_ -> PrettyPrintEnvDecl -> Transaction PrettyPrintEnvDecl
forall a. a -> Transaction a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PrettyPrintEnvDecl
pped) mayWidth
pure $
DefinitionSearchResult
{ fqn,
summary = ToTTypeSummary summary,
project,
branchRef
}
getDefinitionsEndpoint ::
Runtime Symbol ->
Codebase IO Symbol Ann ->
ProjectAndBranch ProjectName ProjectBranchName ->
Maybe Path.Path ->
[HQ.HashQualified Name] ->
Maybe Width ->
Maybe Suffixify ->
Backend.Backend IO (APIHeaders DefinitionDisplayResults)
getDefinitionsEndpoint :: Runtime Symbol
-> Codebase IO Symbol Ann
-> ProjectAndBranch ProjectName ProjectBranchName
-> Maybe Path
-> [HashQualified Name]
-> Maybe Width
-> Maybe Suffixify
-> Backend IO (APIHeaders DefinitionDisplayResults)
getDefinitionsEndpoint Runtime Symbol
rt Codebase IO Symbol Ann
codebase ProjectAndBranch ProjectName ProjectBranchName
projectAndBranchName Maybe Path
relativePath [HashQualified Name]
hqns Maybe Width
width Maybe Suffixify
suff = do
root <- Codebase IO Symbol Ann
-> ProjectAndBranch ProjectName ProjectBranchName
-> Backend IO (CausalBranch Transaction)
forall v a.
Codebase IO v a
-> ProjectAndBranch ProjectName ProjectBranchName
-> Backend IO (CausalBranch Transaction)
Backend.resolveProjectRoot Codebase IO Symbol Ann
codebase ProjectAndBranch ProjectName ProjectBranchName
projectAndBranchName
r <-
foldMapM
( Local.prettyDefinitionsForHQName
(maybe Path.Root Path.Absolute relativePath)
root
width
(fromMaybe (Suffixify True) suff)
rt
codebase
)
hqns
pure $ setCacheControl r
serveDefinitionsServer ::
Runtime Symbol ->
Codebase IO Symbol Ann ->
ProjectAndBranch ProjectName ProjectBranchName ->
ServerT DefinitionsAPI (Backend.Backend IO)
serveDefinitionsServer :: Runtime Symbol
-> Codebase IO Symbol Ann
-> ProjectAndBranch ProjectName ProjectBranchName
-> ServerT DefinitionsAPI (Backend IO)
serveDefinitionsServer Runtime Symbol
rt Codebase IO Symbol Ann
codebase ProjectAndBranch ProjectName ProjectBranchName
projectAndBranch = do
Runtime Symbol
-> Codebase IO Symbol Ann
-> ProjectAndBranch ProjectName ProjectBranchName
-> Maybe Path
-> [HashQualified Name]
-> Maybe Width
-> Maybe Suffixify
-> Backend IO (APIHeaders DefinitionDisplayResults)
getDefinitionsEndpoint Runtime Symbol
rt Codebase IO Symbol Ann
codebase ProjectAndBranch ProjectName ProjectBranchName
projectAndBranch
(Maybe Path
-> [HashQualified Name]
-> Maybe Width
-> Maybe Suffixify
-> Backend IO (APIHeaders DefinitionDisplayResults))
-> ((HashQualified Name
-> Maybe Width -> Backend IO (APIHeaders DefinitionSearchResults))
:<|> (HashQualified Name
-> Maybe Width -> Backend IO (APIHeaders DefinitionSearchResults)))
-> (Maybe Path
-> [HashQualified Name]
-> Maybe Width
-> Maybe Suffixify
-> Backend IO (APIHeaders DefinitionDisplayResults))
:<|> ((HashQualified Name
-> Maybe Width -> Backend IO (APIHeaders DefinitionSearchResults))
:<|> (HashQualified Name
-> Maybe Width -> Backend IO (APIHeaders DefinitionSearchResults)))
forall a b. a -> b -> a :<|> b
:<|> Runtime Symbol
-> Codebase IO Symbol Ann
-> ProjectAndBranch ProjectName ProjectBranchName
-> HashQualified Name
-> Maybe Width
-> Backend IO (APIHeaders DefinitionSearchResults)
getDefinitionDependentsEndpoint Runtime Symbol
rt Codebase IO Symbol Ann
codebase ProjectAndBranch ProjectName ProjectBranchName
projectAndBranch
(HashQualified Name
-> Maybe Width -> Backend IO (APIHeaders DefinitionSearchResults))
-> (HashQualified Name
-> Maybe Width -> Backend IO (APIHeaders DefinitionSearchResults))
-> (HashQualified Name
-> Maybe Width -> Backend IO (APIHeaders DefinitionSearchResults))
:<|> (HashQualified Name
-> Maybe Width -> Backend IO (APIHeaders DefinitionSearchResults))
forall a b. a -> b -> a :<|> b
:<|> Runtime Symbol
-> Codebase IO Symbol Ann
-> ProjectAndBranch ProjectName ProjectBranchName
-> HashQualified Name
-> Maybe Width
-> Backend IO (APIHeaders DefinitionSearchResults)
getDefinitionDependenciesEndpoint Runtime Symbol
rt Codebase IO Symbol Ann
codebase ProjectAndBranch ProjectName ProjectBranchName
projectAndBranch