Skip to content

Commit f5364c5

Browse files
committed
Fix formatting of definitions response
1 parent 9b24f52 commit f5364c5

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

docker/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ services:
2020
# Optionally persist the data between container invocations
2121
- postgresVolume:/var/lib/postgresql/data
2222
- ./postgresql.conf:/etc/postgresql/postgresql.conf
23-
command: postgres -c config_file=/etc/postgresql/postgresql.conf
23+
command: postgres -c config_file=/etc/postgresql/postgresql.conf # -c log_statement=all
2424

2525

2626
redis:

src/Share/BackgroundJobs/Search/DefinitionSync.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import Unison.Debug qualified as Debug
4343
import Unison.HashQualifiedPrime qualified as HQ'
4444
import Unison.LabeledDependency qualified as LD
4545
import Unison.Name (Name)
46+
import Unison.Name qualified as Name
4647
import Unison.PrettyPrintEnv qualified as PPE
4748
import Unison.PrettyPrintEnvDecl qualified as PPED
4849
import Unison.PrettyPrintEnvDecl.Postgres qualified as PPEPostgres
@@ -123,7 +124,14 @@ syncTerms namesPerspective bhId projectId releaseId termsCursor = do
123124
PG.timeTransaction "Building terms" $
124125
terms & foldMapM \(fqn, ref) -> fmap (either (\err -> ([err], [])) (\doc -> ([], [doc]))) . runExceptT $ do
125126
typ <- lift (Codebase.loadTypeOfReferent ref) `whenNothingM` throwError (NoTypeSigForTerm fqn ref)
126-
termSummary <- lift $ Summary.termSummaryForReferent ref typ (Just fqn) bhId Nothing Nothing
127+
let displayName =
128+
fqn
129+
& Name.reverseSegments
130+
-- For now we treat the display name for search as just the last 2 segments of the name.
131+
& \case
132+
(ns :| rest) -> ns :| take 1 rest
133+
& Name.fromReverseSegments
134+
termSummary <- lift $ Summary.termSummaryForReferent ref typ (Just displayName) bhId Nothing Nothing
127135
let sh = Referent.toShortHash ref
128136
let (refTokens, arity) = tokensForTerm fqn ref typ termSummary
129137
let dd =

src/Share/Web/Share/Types.hs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Share.Utils.API (NullableUpdate, parseNullableUpdate)
1616
import Share.Utils.URI
1717
import Unison.Name (Name)
1818
import Unison.Server.Doc (Doc)
19+
import Unison.Server.Share.DefinitionSummary.Types (TermSummary (..), TypeSummary (..))
1920

2021
data UpdateUserRequest = UpdateUserRequest
2122
{ name :: NullableUpdate Text,
@@ -189,8 +190,29 @@ data DefinitionSearchResult
189190
instance ToJSON DefinitionSearchResult where
190191
toJSON DefinitionSearchResult {..} =
191192
Aeson.object
192-
[ "fqn" .= fqn,
193-
"summary" .= summary,
194-
"project" .= project,
195-
"release" .= release
193+
[ "fqn" Aeson..= fqn,
194+
"projectRef" Aeson..= project,
195+
"branchRef" Aeson..= release,
196+
"kind" Aeson..= kind,
197+
"definition" Aeson..= definition
196198
]
199+
where
200+
(kind, definition) = case summary of
201+
DefSync.ToTTermSummary TermSummary {displayName, hash, summary, tag} ->
202+
( Aeson.String "term",
203+
Aeson.object
204+
[ "displayName" Aeson..= displayName,
205+
"hash" Aeson..= hash,
206+
"summary" Aeson..= summary,
207+
"tag" Aeson..= tag
208+
]
209+
)
210+
DefSync.ToTTypeSummary TypeSummary {displayName, hash, summary, tag} ->
211+
( Aeson.String "type",
212+
Aeson.object
213+
[ "displayName" Aeson..= displayName,
214+
"hash" Aeson..= hash,
215+
"summary" Aeson..= summary,
216+
"tag" Aeson..= tag
217+
]
218+
)

0 commit comments

Comments
 (0)