-
Notifications
You must be signed in to change notification settings - Fork 96
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
@hidden would be a useful tag to have on items #578
Comments
Hi @jonludlam, I am an Outreachy intern looking at being a potential contributor to this project. I have successfully cloned the repository and got it up and running using this link. I was trying to take on some issues on v3.ocaml.org-server repo and managed to raise a PR - (170) but I just noticed that the repository is not listed on the Outreachy website. Can you please throw some light on this issue for me to start working on it? |
Hi @desirekaleba - OK, this'll be a challenging item I think! First of all I suggest you look here to see how we can currently hide items with the use of 'stop comments'. The idea of this issue is that we want an additional way of hiding items from the docs by using an OCaml attribute. Attributes are explained in the manual here but it might be useful to give an example here: type t = int [@@hidden] here we've declarated a type (**/**)
type t = int
(**/**) The first place to look for this is the place where we currently decide whether items are hidden or not, and that is in the file ident_env.cppo.ml in the two functions Once you've figured that out, the next step is to add in a check to see if the item has an attribute I've tried to give enough here to be able to completely address the issue, but I don't really expect you to be able to do it without asking further questions. So give it a go, see how far you get, and let us know when you get stuck! |
I should mention that there are a bunch of |
Thank you for all these details, @jonludlam. I am currently giving it a shot and I will be updating you. |
Hi @jonludlam, I took some time to go through the cppo and the ident_env.cppo.ml file. This has given me an understanding of what we really want to achieve and how can that be achieved. Below are a few points I can talk about so far:
If I am wrong so far, I would like to have some light on what I don't get yet. But I have just noticed that I need to brush up on my Ocaml skills in order to proceed with this issue. I will keep updating you on what progress I have made on this. |
Right so far! Can you see how and why the value of |
@jonludlam, I have been going through most of the topics including but not limited to if_statements_loops_and_recursion, lists, data_types_and_matching, etc. to help me understand how and why the value of List.map (fun decl -> `Type (decl.typ_id, hide_item))
decls @ extract_signature_tree_items hide_item rest What I don't really get here is `Type (decl.typ_id, hide_item) Is it a way of creating our type item(eg: modules, module types, values, etc.)? |
I also found this part which I think is checking for the presence of Some ("/*", _) -> extract_signature_tree_items (not hide_item) rest |
OK, let me explain a little further. This is more detail than you really need, but might help you to understand what's going on here. Each element in a signature has a unique identifier assigned by the compiler - essentially a pair of the name of the element and a number, which is required because the name is not unique enough by itself. You can actually see this: Given a file 'test.mli' containing the following: type t
val f : t You can run the compiler on this and ask it to show you how understands this code by running
We have here 2 'signature_items' - a These idents are not quite detailed enough for odoc - odoc wants to be able to link from uses of type to the definition, so instead of having The two functions you're currently looking at are part of the process of creating this map. They go over the list of items declared in a signature or structure and construct a list of the idents of the items declared in it. So given our signature above in
In fact, the reason you're looking at this function is it's actually the most convenient place to decide whether an identifier is hidden or not (currently via the stop comments,
Now, with this in mind, let's take a look at the code snippet you posted: | { sig_desc = Tsig_type (_, decls); _} :: rest ->
List.map (fun decl -> `Type (decl.typ_id, hide_item))
decls @ extract_signature_tree_items hide_item rest Now, OCaml allows mutually recursive type declarations, so something like: type t = Foo of u
and u = Bar of t and the way this is represented in the compiler is a single
whereas the value doesn't:
So in fact each List.map (fun decl -> `Type (decl.typ_id, hide_item)) decls This part goes over each declaration in the list of decls and constructs the value ... @ extract_signature_tree_items hide_item rest The | { sig_desc = Tsig_value {val_id; _}; _ } :: rest->
[`Value (val_id, hide_item)] @ extract_signature_tree_items hide_item rest Values aren't represented as list so we just have a single [ `Type("t/81",false); `Value("f/82",false) ] This list will then be used to construct the identifiers for our type and value elsewhere in the code, but we don't need to worry about that. What you'll be needing to do is to see if the attribute type t [@@hidden]
val f : t [@@hidden] then
so both of our |
@jonludlam, thank you for the above details. This has given me a clear understanding of what's happening. Answering the question, the way to detect the `Type (decl.typ_id, not hide_item) For example, If our type t [@@hidden] This should give us [ `Type("t/81",true) ] Note: This is applicable only when our signature item is represented as a list. If the signature item is not represented as a list, We will have to destructure the { sig_desc = Tsig_value {val_id; val_attributes; _}; _ } |
I think you are on the right track! As an inspiration, documentation comments are stored as attributes too in the Tast, meaning there's many places where attributes are inspected like this: let doc = Doc_attr.attached_no_tag label_container cd.cd_attributes in
That's right :) but the hidden value shouldn't be obtained from |
@Julow, Thank you for this. I think I will soon clear this out. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. The main purpose of this is to keep the issue tracker focused to what is actively being worked on, so that the amount and variety of open yet inactive issues does not overwhelm contributors. An issue closed as stale is not rejected — further discussion is welcome in its closed state, and it can be resurrected at any time. odoc maintainers regularly check issues that were closed as stale in the past, to see if the time is right to reopen and work on them again. PRs addressing issues closed as stale are as welcome as PRs for open issues. They will be given the same review attention, and any other help. |
Hi @jonludlam! I know this issue has gone stale, but I found this thread/issue super interesting so I took a look at it. Specifically, I think I've gotten the desired behaviour when it comes to the Tsig_val case (code below):
This code occurs in the function Furthermore, I'm also about to start working on the Tsig_modtype case and was wondering if you could shed some light on the desired behaviour:
I suppose the entire module should be hidden, correct? However in this example:
only the type t part should be hidden, but not the entire module? And the following example
should instead hide what comes after the module? Thank you so much! |
@ccatherinee In your code, you can use Your first example is a syntax error, so there's nothing to worry about. Your third example attaches the OCaml has a syntax for "standalone" attributes: |
Hi @Julow - thank you so much for the detailed response. Just to clarify, does this mean my understanding of
is correct (ie only the type t part should be hidden, but not the entire module) or do these sentences
mean that
is a syntax error and we can only have
Furthermore, does
mean all remaining code in the file or just code in that module which comes after the standalone attribute? Thank you so much for your time! |
I'm slightly surprised that we're going for: type t [@@hidden] rather than: (** @hidden *)
type t which would be more consistent with things like: (** @inline *)
include Foo Sorry to ask about this late in the day. Although, if we did decide to do this instead, I suspect adjusting the implementation to do so wouldn't need to change much. |
I'm flummoxed. I can't see why I turned this from a tag (originally here: #571 (comment), and in the title of this issue!) into an attribute. The only annoying thing about an not using an attribute is that we'll have to change odoc-parser to do this... :-/ |
@jonludlam Which is implemented by @3Rafal and waiting for your approval and merge: ocaml-doc/odoc-parser#16 |
Turns out using an attribute is rather a lot more annoying than an attribute as we haven't parsed any comments at the point we're hiding items. |
Rather than putting the item between
(**/**)
comments - it's easier for ppxes.The text was updated successfully, but these errors were encountered: