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

Support inline record fields in doc extraction #889

Merged
merged 5 commits into from
Jan 11, 2024

Conversation

zth
Copy link
Collaborator

@zth zth commented Jan 9, 2024

Closes #887

I've also removed all of the JSON decoding code, because with untagged variants we can just map to the result zero cost, which is a lot easier to maintain.

cc @aspeddro

@woeps
Copy link
Contributor

woeps commented Jan 9, 2024

Removing the JSON decoding code let a bug surface: type item in Tools_Docgen.resi defines

Module({
  id: 
  docstrings: array<string>,
  deprecated?: string,
  name: string,
  items: array<item>,
})

having docstrings not being optional, but the generated json (by analysis binary) does not contain the docstrings field for module items.

I believe, I found the issue in DocExtraction.ml#L156-166:

  | Module m ->
    stringifyObject ~startOnNewline:true ~indentation
      [
        ("id", Some (wrapInQuotes m.id));
        ("name", Some (wrapInQuotes m.name));
        ("kind", Some (wrapInQuotes "module"));
        ("docstrings", Some (stringifyDocstrings m.docstring));  (* THIS LINE IS MISSING! *)
        ( "items",
          Some
            (m.items
            |> List.map
                 (stringifyDocItem ~originalEnv ~indentation:(indentation + 1))
            |> array) );
      ]

which doesn't stringified the docstring field yet.

@zth
Copy link
Collaborator Author

zth commented Jan 10, 2024

@woeps perfect, I'll fix it!

@zth
Copy link
Collaborator Author

zth commented Jan 10, 2024

@woeps can you test the latest commits?

type constructor = {
name: string,
docstrings: array<string>,
signature: string,
deprecated?: string,
constructorPayload?: constructorPayload,
Copy link
Contributor

@woeps woeps Jan 10, 2024

Choose a reason for hiding this comment

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

@zth This field name (constructorPayload) is not matching the field name given in stringifyDetail in DocExtraction.ml (items).
If I'm not mistaken, both names need to be identical: either items or constructorPayload.

edit:
Just tested it locally: Yes, if I change the fieldname to items in Tools_Docgen.res(i) my tests work as expected.

Copy link
Contributor

Choose a reason for hiding this comment

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

@zth changed items from array to object then better rename field to payload or params?

@aspeddro
Copy link
Contributor

Gabriel, can we remove JSON decode soon (maybe 0.5 release)? At the moment, I use the decode function on the website.

@zth zth force-pushed the inline-record-field-constructors-docextraction branch from 6ddba8d to 430d44e Compare January 11, 2024 07:26
@zth zth merged commit ddf14cf into master Jan 11, 2024
@zth zth deleted the inline-record-field-constructors-docextraction branch January 11, 2024 07:28
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.

doc extracted signature of variant with inline-record incomplete?
3 participants