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

Generate enum constant Documentation #74

Merged
merged 7 commits into from
Jul 27, 2023
Merged

Conversation

nikkirad
Copy link
Contributor

@nikkirad nikkirad commented Jul 13, 2023

Implement enumconstantand its documentation. These changes, along with PR #22750, allow chpldoc to generate documentation for each enum constant rather than only for the enum. Solution to chapel-lang/chapel#5022.

Previously, documentation for enum constants have been either nonexistent, or written in different ways (such as a table) in order to be shown. Since this form of documentation is already available for other attribute-like types (i.e. records), it is intuitive for enum constant documentation to exist as well.

This PR changes enum to a Class Object and enumconstant to a Class Member (suggested by Thomas Van Doren in 2015). It includes test cases for enumconstant and presents the changes made in PR #22750.

An example of affected code:
Screenshot 2023-07-25 at 5 08 17 PM
Screenshot 2023-07-25 at 5 11 14 PM
Screenshot 2023-07-25 at 5 07 05 PM

nikkirad added 4 commits July 13, 2023 13:35
Signed-off-by: nikkirad <nikkizrad@gmail.com>
Signed-off-by: nikkirad <nikkizrad@gmail.com>
Signed-off-by: nikkirad <nikkizrad@gmail.com>
Signed-off-by: nikkirad <nikkizrad@gmail.com>
@codecov
Copy link

codecov bot commented Jul 13, 2023

Codecov Report

Patch coverage: 40.00% and project coverage change: -0.16% ⚠️

Comparison is base (4ce9da5) 42.40% compared to head (19a5001) 42.25%.
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #74      +/-   ##
==========================================
- Coverage   42.40%   42.25%   -0.16%     
==========================================
  Files           2        2              
  Lines         540      542       +2     
==========================================
  Hits          229      229              
- Misses        311      313       +2     
Files Changed Coverage Δ
sphinxcontrib/chapeldomain/__init__.py 40.49% <40.00%> (-0.16%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

nikkirad added 2 commits July 20, 2023 11:43
Signed-off-by: nikkirad <nikkizrad@gmail.com>
Signed-off-by: nikkirad <nikkizrad@gmail.com>
@nikkirad nikkirad changed the title Generate enum element Documentation Generate enum constant Documentation Jul 24, 2023
@lydia-duncan lydia-duncan self-requested a review July 24, 2023 21:29
Copy link
Member

@lydia-duncan lydia-duncan left a comment

Choose a reason for hiding this comment

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

Sorry, a lot of my comments in here stem from some ignorance of the implementation and what causes what part of our final product. Seeing the generated docs output (or even just a generated .rst file) will help us answer these questions.

@@ -617,7 +620,7 @@ def get_index_text(self, modname, name_cls):
return _('%s() (built-in %s)') % \
(name_cls[0], self.chpl_type_name)
return _('%s() (in module %s)') % (name_cls[0], modname)
elif self.objtype in ('data', 'type', 'enum'):
elif self.objtype in ('data', 'type'):
Copy link
Member

Choose a reason for hiding this comment

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

I think this is here because you can declare enums inside a class as well as outside (see test/classes/bradc/enumInClass.chpl, which appears to work today). So I think it would be good to keep this, or at least write a test case that does so and ensure it works the same before and after your change (and maybe ensure you can still follow links to it).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before the change, it would print in module <module name> even if it was declared inside of something else (i.e. record). Now it prints enum in <wherever the enum is in>. Here's an example of the change:

Before:
Screenshot 2023-07-26 at 12 22 10 PM

After:
Screenshot 2023-07-26 at 12 21 06 PM

Just added a test case that presents this change.

Copy link
Member

Choose a reason for hiding this comment

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

Well that definitely seems like an improvement

@@ -416,6 +417,7 @@ def test_get_attr_like_prefix(self):
('config const n', 'config const '),
('blah blah blah blah blah', 'blah blah blah blah '),
('enum Color', 'enum '),
('enum constant USA', 'enum constant '),
Copy link
Member

Choose a reason for hiding this comment

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

Hmm. Not sure how I feel about this, since enum constant isn't Chapel syntax. It is descriptive, though . . .

Copy link
Member

Choose a reason for hiding this comment

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

My understanding is that all of this is the stuff that gets output to the right of any .. <whatever>::, e.g. .. enumconstant:: enum constant USA, is that correct? If so, I'd be inclined to not output that second part and just rely on the test on line 414, (so we'd generate .. enumconstant:: USA instead, I think?)

Or is this what is used to create those .. enumconstant:: USA pieces in the first place? In which case, it's fine to leave it as is.

(Sorry for not knowing the answer myself)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Your understanding is correct, "enum constant" isn't necessary for the ..enumconstant:: to be outputted. My line of thinking for outputting enumconstant:: enum constant USA is only because of the cohesiveness with the rest of the documentation, simply a design decision that can be changed :)

Copy link
Member

Choose a reason for hiding this comment

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

Then let's bring that up to the rest of the team, or at least Daniel and Ahmad. I don't want to accidentally steer us in a direction the rest of the team doesn't like just because I'm loud :)

('enum constant Pink', 'enum constant ', None, 'Pink', None),
('enum constant December', 'enum constant ', None, 'December', None),
('enum constant Hibiscus', 'enum constant ', None, 'Hibiscus', None),
('enum constant Aquarius', 'enum constant ', None, 'Aquarius', None)
Copy link
Member

Choose a reason for hiding this comment

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

The answer to my question on line 420 may impact this as well?

Signed-off-by: nikkirad <nikkizrad@gmail.com>
@nikkirad
Copy link
Contributor Author

After discussion with the team, the plan is to continue printing "enum constant," and reevaluate in the future when there are more rendered docs examples.

@nikkirad nikkirad merged commit 5521f46 into chapel-lang:main Jul 27, 2023
nikkirad added a commit to chapel-lang/chapel that referenced this pull request Aug 7, 2023
This PR, along with [sphinxcontrib-chapeldomain PR
#74](chapel-lang/sphinxcontrib-chapeldomain#74),
contains changes made to `chpldoc.cpp` to generate documentation for
each enum constant rather than only for the enum. Solution to #5022.

Previously, documentation for enum constants have been either
nonexistent, or written in different ways (such as a table) in order to
be shown. Since this form of documentation is already available for
other types that contain inner content (i.e. records), it is intuitive
for enum constant documentation to exist as well.

These changes allow chpldoc to recognize enum constants (written as
`EnumElement` in the AST) as enum's children. However, only prefix
comments will be recognized and documented. There is intent to allow
suffix comments to be recognized and documented in the future.

third-party/chpl-venv/Makefile and make_doc errors should be resolved
after merging [this
PR](chapel-lang/sphinxcontrib-chapeldomain#74)
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.

2 participants