Skip to content

Commit

Permalink
Fix formatting of definitions response
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPenner committed Jul 25, 2024
1 parent 9b24f52 commit f5364c5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ services:
# Optionally persist the data between container invocations
- postgresVolume:/var/lib/postgresql/data
- ./postgresql.conf:/etc/postgresql/postgresql.conf
command: postgres -c config_file=/etc/postgresql/postgresql.conf
command: postgres -c config_file=/etc/postgresql/postgresql.conf # -c log_statement=all


redis:
Expand Down
10 changes: 9 additions & 1 deletion src/Share/BackgroundJobs/Search/DefinitionSync.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import Unison.Debug qualified as Debug
import Unison.HashQualifiedPrime qualified as HQ'
import Unison.LabeledDependency qualified as LD
import Unison.Name (Name)
import Unison.Name qualified as Name
import Unison.PrettyPrintEnv qualified as PPE
import Unison.PrettyPrintEnvDecl qualified as PPED
import Unison.PrettyPrintEnvDecl.Postgres qualified as PPEPostgres
Expand Down Expand Up @@ -123,7 +124,14 @@ syncTerms namesPerspective bhId projectId releaseId termsCursor = do
PG.timeTransaction "Building terms" $
terms & foldMapM \(fqn, ref) -> fmap (either (\err -> ([err], [])) (\doc -> ([], [doc]))) . runExceptT $ do
typ <- lift (Codebase.loadTypeOfReferent ref) `whenNothingM` throwError (NoTypeSigForTerm fqn ref)
termSummary <- lift $ Summary.termSummaryForReferent ref typ (Just fqn) bhId Nothing Nothing
let displayName =
fqn
& Name.reverseSegments
-- For now we treat the display name for search as just the last 2 segments of the name.
& \case
(ns :| rest) -> ns :| take 1 rest
& Name.fromReverseSegments
termSummary <- lift $ Summary.termSummaryForReferent ref typ (Just displayName) bhId Nothing Nothing
let sh = Referent.toShortHash ref
let (refTokens, arity) = tokensForTerm fqn ref typ termSummary
let dd =
Expand Down
30 changes: 26 additions & 4 deletions src/Share/Web/Share/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Share.Utils.API (NullableUpdate, parseNullableUpdate)
import Share.Utils.URI
import Unison.Name (Name)
import Unison.Server.Doc (Doc)
import Unison.Server.Share.DefinitionSummary.Types (TermSummary (..), TypeSummary (..))

data UpdateUserRequest = UpdateUserRequest
{ name :: NullableUpdate Text,
Expand Down Expand Up @@ -189,8 +190,29 @@ data DefinitionSearchResult
instance ToJSON DefinitionSearchResult where
toJSON DefinitionSearchResult {..} =
Aeson.object
[ "fqn" .= fqn,
"summary" .= summary,
"project" .= project,
"release" .= release
[ "fqn" Aeson..= fqn,
"projectRef" Aeson..= project,
"branchRef" Aeson..= release,
"kind" Aeson..= kind,
"definition" Aeson..= definition
]
where
(kind, definition) = case summary of
DefSync.ToTTermSummary TermSummary {displayName, hash, summary, tag} ->
( Aeson.String "term",
Aeson.object
[ "displayName" Aeson..= displayName,
"hash" Aeson..= hash,
"summary" Aeson..= summary,
"tag" Aeson..= tag
]
)
DefSync.ToTTypeSummary TypeSummary {displayName, hash, summary, tag} ->
( Aeson.String "type",
Aeson.object
[ "displayName" Aeson..= displayName,
"hash" Aeson..= hash,
"summary" Aeson..= summary,
"tag" Aeson..= tag
]
)

0 comments on commit f5364c5

Please sign in to comment.