-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restore type-directed search #1325
Conversation
@@ -102,9 +113,8 @@ query | |||
:: TypeIndex | |||
-> TypeQuery | |||
-> Aff { index :: TypeIndex, results :: Array SearchResult } | |||
query typeIndex typeQuery = do | |||
res <- lookup (stringifyShape $ shapeOfTypeQuery typeQuery) typeIndex | |||
pure $ res { results = res.results } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WTF was this?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😂
, log :: String -> Aff Unit | ||
, die :: String -> Aff Unit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IndexBuilder
was logging directly to console with no indirection at all. I added these parameters so that it would respect the --quiet
option.
Looking at the larger picture, I don't understand why this is a separate project and not part of Spago proper. It's not used from anywhere else, only from the docs
command implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was born as a separate experiment, and was integrated only recently in Spago's codebase. It could be used independently from the command line as well (functionality that we ought to restore as a Spago command)
(mkHeader typeShape <> JSON.print (CJ.encode codec results)) | ||
(mkHeader typeShape <> JSON.print (CJ.encode codec $ fromMaybe [] results)) | ||
where | ||
mkHeader typeShape = | ||
"// This file was generated by docs-search\n" | ||
<> "window.DocsSearchTypeIndex[\"" | ||
<> typeShape | ||
<> "\"] = " | ||
|
||
codec = CJ.Common.maybe $ CJ.array SearchResult.searchResultCodec | ||
codec = CJ.array SearchResult.searchResultCodec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines are the actual fix of the actual problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lovely!!
Description of the change
Fixes #1093
The problem was that
IndexBuilder
was writing aMaybe
value into index files, and it came out like{ tag: "Just", value: [ ... ] }
, while the UI was expecting to read anArray
value, not wrapped in aMaybe
, silently failing at that, and returning empty results. I suspect the bug was introduced during migration from Argonaut to Codec, because they have differentMaybe
semantics: Argonaut writes the value itself forJust
ornull
forNothing
, while Codec apparently wraps it like any other ADT.To fix, I made the
IndexBuilder
write a nakedArray
value, coercingNothing
to an empty array.I took the opportunity to also clean up and straighten the code a bit. See comments in the code.
I did not add a test for this particular issue, because the test would have to be an integration one: build docs, open browser under Selenium, try to search. I think it would be valuable to add such test, but it felt like too big of a scope for this fix.
Checklist:
[ ] Added some example of the new feature to theREADME
[ ] Added a test for the contribution (if applicable)