Remove loose code support from api

This commit is contained in:
Chris Penner 2024-07-01 13:37:28 -07:00
parent 5f78557170
commit 2002a562ca
8 changed files with 12 additions and 49 deletions

View File

@ -196,6 +196,7 @@ loop e = do
Cli.respond $ Typechecked (Text.pack sourceName) suffixifiedPPE sr uf
in Cli.time "InputPattern" case input of
ApiI -> do
pp <- Cli.getCurrentProjectPath
Cli.Env {serverBaseUrl} <- ask
whenJust serverBaseUrl \baseUrl ->
Cli.respond $
@ -203,7 +204,7 @@ loop e = do
P.lines
[ "The API information is as follows:",
P.newline,
P.indentN 2 (P.hiBlue ("UI: " <> Pretty.text (Server.urlFor (Server.LooseCodeUI Path.absoluteEmpty Nothing) baseUrl))),
P.indentN 2 (P.hiBlue ("UI: " <> Pretty.text (Server.urlFor (Server.ProjectBranchUI (PP.toProjectAndBranch . PP.toNames $ pp) Path.absoluteEmpty Nothing) baseUrl))),
P.newline,
P.indentN 2 (P.hiBlue ("API: " <> Pretty.text (Server.urlFor Server.Api baseUrl)))
]

View File

@ -83,6 +83,7 @@ import Unison.CommandLine.Main qualified as CommandLine
import Unison.CommandLine.Types qualified as CommandLine
import Unison.CommandLine.Welcome (CodebaseInitStatus (..))
import Unison.CommandLine.Welcome qualified as Welcome
import Unison.Core.Project (ProjectAndBranch (..), ProjectBranchName (..), ProjectName (..))
import Unison.LSP qualified as LSP
import Unison.Parser.Ann (Ann)
import Unison.Prelude
@ -338,7 +339,7 @@ main version = do
[ "I've started the Codebase API server at",
P.text $ Server.urlFor Server.Api baseUrl,
"and the Codebase UI at",
P.text $ Server.urlFor (Server.LooseCodeUI Path.absoluteEmpty Nothing) baseUrl
P.text $ Server.urlFor (Server.ProjectBranchUI (ProjectAndBranch (UnsafeProjectName "scratch") (UnsafeProjectBranchName "main")) Path.absoluteEmpty Nothing) baseUrl
]
PT.putPrettyLn $
P.string "Running the codebase manager headless with "

View File

@ -141,11 +141,8 @@ type OpenApiJSON = "openapi.json" :> Get '[JSON] OpenApi
type UnisonAndDocsAPI = UnisonLocalAPI :<|> OpenApiJSON :<|> Raw
type LooseCodeAPI = CodebaseServerAPI
type UnisonLocalAPI =
("projects" :> ProjectsAPI)
:<|> ("non-project-code" :> LooseCodeAPI)
:<|> ("ucm" :> UCMAPI)
type CodebaseServerAPI =
@ -233,8 +230,7 @@ data DefinitionReference
deriving stock (Show)
data Service
= LooseCodeUI Path.Absolute (Maybe DefinitionReference)
| -- (Project branch names, perspective within project, definition reference)
= -- (Project branch names, perspective within project, definition reference)
ProjectBranchUI (ProjectAndBranch ProjectName ProjectBranchName) Path.Absolute (Maybe DefinitionReference)
| Api
deriving stock (Show)
@ -294,8 +290,6 @@ data URISegment
urlFor :: Service -> BaseUrl -> Text
urlFor service baseUrl =
case service of
LooseCodeUI perspective def ->
tShow baseUrl <> "/" <> toUrlPath ([DontEscape "ui", DontEscape "non-project-code"] <> path perspective def)
ProjectBranchUI (ProjectAndBranch projectName branchName) perspective def ->
tShow baseUrl <> "/" <> toUrlPath ([DontEscape "ui", DontEscape "projects", DontEscape $ into @Text projectName, DontEscape $ into @Text branchName] <> path perspective def)
Api -> tShow baseUrl <> "/" <> toUrlPath [DontEscape "api"]
@ -559,18 +553,6 @@ serveOpenAPI = pure openAPI
hoistWithAuth :: forall api. (HasServer api '[]) => Proxy api -> ByteString -> ServerT api Handler -> ServerT (Authed api) Handler
hoistWithAuth api expectedToken server token = hoistServer @api @Handler @Handler api (\h -> handleAuth expectedToken token *> h) server
serveLooseCode ::
Codebase IO Symbol Ann ->
Rt.Runtime Symbol ->
ServerT LooseCodeAPI (Backend IO)
serveLooseCode codebase rt =
(\root rel name -> setCacheControl <$> NamespaceListing.serve codebase (Left root) rel name)
:<|> (\namespaceName mayRoot renderWidth -> setCacheControl <$> NamespaceDetails.namespaceDetails rt codebase namespaceName (Left mayRoot) renderWidth)
:<|> (\mayRoot relativePath rawHqns renderWidth suff -> setCacheControl <$> serveDefinitions rt codebase (Left mayRoot) relativePath rawHqns renderWidth suff)
:<|> (\mayRoot relativePath limit renderWidth query -> setCacheControl <$> serveFuzzyFind codebase (Left mayRoot) relativePath limit renderWidth query)
:<|> (\shortHash mayName mayRoot relativeTo renderWidth -> setCacheControl <$> serveTermSummary codebase shortHash mayName (Left mayRoot) relativeTo renderWidth)
:<|> (\shortHash mayName mayRoot relativeTo renderWidth -> setCacheControl <$> serveTypeSummary codebase shortHash mayName (Left mayRoot) relativeTo renderWidth)
serveProjectsCodebaseServerAPI ::
Codebase IO Symbol Ann ->
Rt.Runtime Symbol ->
@ -586,26 +568,26 @@ serveProjectsCodebaseServerAPI codebase rt projectName branchName = do
:<|> serveTypeSummaryEndpoint
where
projectAndBranchName = ProjectAndBranch projectName branchName
namespaceListingEndpoint _rootParam rel name = do
namespaceListingEndpoint rel name = do
root <- resolveProjectRootHash codebase projectAndBranchName
setCacheControl <$> NamespaceListing.serve codebase (Right $ root) rel name
namespaceDetailsEndpoint namespaceName _rootParam renderWidth = do
namespaceDetailsEndpoint namespaceName renderWidth = do
root <- resolveProjectRootHash codebase projectAndBranchName
setCacheControl <$> NamespaceDetails.namespaceDetails rt codebase namespaceName (Right $ root) renderWidth
serveDefinitionsEndpoint _rootParam relativePath rawHqns renderWidth suff = do
serveDefinitionsEndpoint relativePath rawHqns renderWidth suff = do
root <- resolveProjectRootHash codebase projectAndBranchName
setCacheControl <$> serveDefinitions rt codebase (Right $ root) relativePath rawHqns renderWidth suff
serveFuzzyFindEndpoint _rootParam relativePath limit renderWidth query = do
serveFuzzyFindEndpoint relativePath limit renderWidth query = do
root <- resolveProjectRootHash codebase projectAndBranchName
setCacheControl <$> serveFuzzyFind codebase (Right $ root) relativePath limit renderWidth query
serveTermSummaryEndpoint shortHash mayName _rootParam relativeTo renderWidth = do
serveTermSummaryEndpoint shortHash mayName relativeTo renderWidth = do
root <- resolveProjectRootHash codebase projectAndBranchName
setCacheControl <$> serveTermSummary codebase shortHash mayName (Right $ root) relativeTo renderWidth
serveTypeSummaryEndpoint shortHash mayName _rootParam relativeTo renderWidth = do
serveTypeSummaryEndpoint shortHash mayName relativeTo renderWidth = do
root <- resolveProjectRootHash codebase projectAndBranchName
setCacheControl <$> serveTypeSummary codebase shortHash mayName (Right $ root) relativeTo renderWidth
@ -687,7 +669,7 @@ serveUnisonLocal ::
Server UnisonLocalAPI
serveUnisonLocal env codebase rt =
hoistServer (Proxy @UnisonLocalAPI) (backendHandler env) $
serveProjectsAPI codebase rt :<|> serveLooseCode codebase rt :<|> (setCacheControl <$> ucmServer codebase)
serveProjectsAPI codebase rt :<|> (setCacheControl <$> ucmServer codebase)
backendHandler :: BackendEnv -> Backend IO a -> Handler a
backendHandler env m =

View File

@ -48,7 +48,6 @@ import Unison.Server.Backend qualified as Backend
import Unison.Server.Syntax (SyntaxText)
import Unison.Server.Types
( APIGet,
RequiredQueryParam,
TermTag (..),
TypeTag,
mayDefaultWidth,
@ -68,7 +67,6 @@ type TermSummaryAPI =
-- It's propagated through to the response as-is.
-- If missing, the short hash will be used instead.
:> QueryParam "name" Name
:> RequiredQueryParam "rootBranch" ShortCausalHash
:> QueryParam "relativeTo" Path.Path
:> QueryParam "renderWidth" Width
:> APIGet TermSummary
@ -151,7 +149,6 @@ type TypeSummaryAPI =
-- It's propagated through to the response as-is.
-- If missing, the short hash will be used instead.
:> QueryParam "name" Name
:> RequiredQueryParam "rootBranch" ShortCausalHash
:> QueryParam "relativeTo" Path.Path
:> QueryParam "renderWidth" Width
:> APIGet TypeSummary

View File

@ -37,7 +37,6 @@ import Unison.Server.Types
HashQualifiedName,
NamedTerm,
NamedType,
RequiredQueryParam,
UnisonName,
mayDefaultWidth,
)
@ -47,7 +46,6 @@ import Unison.Util.Pretty (Width)
type FuzzyFindAPI =
"find"
:> RequiredQueryParam "rootBranch" SCH.ShortCausalHash
:> QueryParam "relativeTo" Path.Path
:> QueryParam "limit" Int
:> QueryParam "renderWidth" Width

View File

@ -35,7 +35,6 @@ import Unison.Server.Local.Definitions qualified as Local
import Unison.Server.Types
( APIGet,
DefinitionDisplayResults,
RequiredQueryParam,
Suffixify (..),
defaultWidth,
)
@ -45,7 +44,6 @@ import Unison.Util.Pretty (Width)
type DefinitionsAPI =
"getDefinition"
:> RequiredQueryParam "rootBranch" ShortCausalHash
:> QueryParam "relativeTo" Path.Path
:> QueryParams "names" (HQ.HashQualified Name)
:> QueryParam "renderWidth" Width
@ -97,16 +95,6 @@ instance ToParam (QueryParam "namespace" Path.Path) where
)
Normal
instance ToParam (RequiredQueryParam "rootBranch" ShortCausalHash) where
toParam _ =
DocQueryParam
"rootBranch"
["#abc123"]
( "The hash or hash prefix of the namespace root. "
<> "If left absent, the most recent root will be used."
)
Normal
instance ToParam (QueryParams "names" (HQ.HashQualified Name)) where
toParam _ =
DocQueryParam

View File

@ -24,7 +24,6 @@ import Unison.Server.Doc qualified as Doc
import Unison.Server.Types
( APIGet,
NamespaceDetails (..),
RequiredQueryParam,
v2CausalBranchToUnisonHash,
)
import Unison.Symbol (Symbol)
@ -33,7 +32,6 @@ import Unison.Util.Pretty (Width)
type NamespaceDetailsAPI =
"namespaces"
:> Capture "namespace" Path.Path
:> RequiredQueryParam "rootBranch" ShortCausalHash
:> QueryParam "renderWidth" Width
:> APIGet NamespaceDetails

View File

@ -35,7 +35,6 @@ import Unison.Server.Types
HashQualifiedName,
NamedTerm (..),
NamedType (..),
RequiredQueryParam,
UnisonHash,
UnisonName,
v2CausalBranchToUnisonHash,
@ -47,7 +46,6 @@ import Unison.Var (Var)
type NamespaceListingAPI =
"list"
:> RequiredQueryParam "rootBranch" ShortCausalHash
:> QueryParam "relativeTo" Path.Path
:> QueryParam "namespace" Path.Path
:> APIGet NamespaceListing