ocaml-semver / ocaml-api-watch

Libraries and tools to keep watch on you OCaml lib's API changes
ISC License
21 stars 14 forks source link

Detect addition and removal of class type declarations #83

Open NathanReb opened 2 weeks ago

NathanReb commented 2 weeks ago

The current implementation of our API diffing does not handle every type of item that can be defined within a module.

It will compare items that we support, detecting addition, removal and modification of said items. If it fails to detect any such change, it will default back to comparing the whole module using Includemod.signatures.

Our ultimate goal is to support fine grained diffing of each and every signature items.

To get one step closer, we would like to add detection of the addition and removal of class_type_declaration items.

How to proceed

The diffing logic and representation is found in lib/diff.ml.

The content of a module is represented as a list even though the order does not matter there. To work around that we first build a map of its content, indexed by pairs of item type and name. We then proceed to compare the two maps we built from the two versions of the module we are diffing. If both map contain a mapping for a given type/name pair, we compare them to try and detect whether it was modified. If only one of the map contains a binding for a given pair, that means that it was either added or removed, based on which map has the binding.

To detect addition/removal of module type declarations, we will have to extend the item_type and sig_items types which are used to build the map mentioned above. These are then used in the extract_items function that builds the map from the module signature.

Finally, the actual diffing logic's entry point is the Diff.items function which handles the comparison of the two maps via the merge function (you can read the documentation here).

Testing

This should be tested at the library level. You can add a new tests/api-watch/test_diff_class_type_decl.ml file where you can write tests for type addition or removal. You can use the tests/api-watch/test_diff.ml or tests/api-watch/test_diff_module.ml files as examples on how to write such tests.

RitaAkor commented 1 week ago

Hello!

I am an Outreachy applicant and I’m interested in contributing to the project by working on the issue regarding "the detection of addition and removal of class_type_declaration items".

As requested, here’s the screenshot of the api-diff man page:

Screenshot 2024-10-02 at 10 26 51

Could you please assign this issue to me? Thank you!

panglesd commented 1 week ago

Yes sure! Let this issue be assigned to you.

panglesd commented 3 days ago

This was typoedly linked from a PR. It is not fixed by #92 but by #87.