Skip to content
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

Merged
merged 3 commits into from
Feb 9, 2025
Merged

Restore type-directed search #1325

merged 3 commits into from
Feb 9, 2025

Conversation

fsoikin
Copy link
Collaborator

@fsoikin fsoikin commented Feb 9, 2025

Description of the change

Fixes #1093

The problem was that IndexBuilder was writing a Maybe value into index files, and it came out like { tag: "Just", value: [ ... ] }, while the UI was expecting to read an Array value, not wrapped in a Maybe, silently failing at that, and returning empty results. I suspect the bug was introduced during migration from Argonaut to Codec, because they have different Maybe semantics: Argonaut writes the value itself for Just or null for Nothing, while Codec apparently wraps it like any other ADT.

To fix, I made the IndexBuilder write a naked Array value, coercing Nothing 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.

type-search

Checklist:

  • Added the change to the "Unreleased" section of the changelog
  • [ ] Added some example of the new feature to the README
  • [ ] Added a test for the contribution (if applicable)

@@ -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 }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WTF was this?!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😂

Comment on lines +73 to +74
, log :: String -> Aff Unit
, die :: String -> Aff Unit
Copy link
Collaborator Author

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.

Copy link
Member

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)

Comment on lines -236 to +232
(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
Copy link
Collaborator Author

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.

Copy link
Member

@f-f f-f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely!!

@f-f f-f merged commit 9af4429 into purescript:master Feb 9, 2025
5 checks passed
@fsoikin fsoikin deleted the type-search branch February 9, 2025 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

spago docs: Fix type directed search
2 participants