-
Notifications
You must be signed in to change notification settings - Fork 94
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
Stable anchors in links to implementation. #993
Conversation
8073c59
to
4c022d1
Compare
Thanks @Julow for the review! I've added one "nontrivial" commit: it seems that functor parameter do have a Uid in the |
4766011
to
37bc8de
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left a few remarks but otherwise this looks ready to be merged :)
src/loader/implementation.ml
Outdated
in | ||
defs @ poses | ||
|
||
let string_of_full_name_ty : Odoc_model.Paths.Identifier.full_name_ty -> string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have strings for the different kinds and they are different: https://github.com/ocaml/odoc/blob/master/src/document/url.ml#L109, https://github.com/ocaml/odoc/blob/master/src/xref2/ref_tools.ml#L60 and https://github.com/ocaml/odoc/blob/master/src/model/reference.ml#L33.
It would be weird to see different strings for the same things in the generated doc and in future uses of the new full_name
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I addressed that in 7804bc0 if you want to have a look!
Basically, I removed full_name
(in any case, it did not included enough information to generate unique anchors), and reused the Odoc_document.Url.Anchor.kind
.
f5fd9ae
to
7804bc0
Compare
I added support for having anchors to constructors, but they will only get one when ocaml/ocaml#12508 is merged (more specifically, ocaml/ocaml@6c1fa73). |
fdb99d9
to
23ec596
Compare
I know I suggested the |
src/loader/implementation.ml
Outdated
| DefJmp of Shape.Uid.t | ||
|
||
module Analysis = struct | ||
let ( @ ) = List.rev_append |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the redefinition of @
to be semantically different from the usual @
! It's confusing.
Also I'm not sure that we care too much about the ordering of things do we? There are a bunch of List.rev
s below that can be removed if we don't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can turn the "lift" into a "fold" and carry an accumulator around, that would be the best option.
Yes, the order does not matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turned the traverse into a fold with an accumulator in 9361f0a. Hopefully it's better like that, with less list concatenations!
These should only be referred to by elements on that same source page. This is in contrast with the `SourceLocation identifier, which uses an anchor found using the Shapes API, and can refer across source pages. This commit introduces the constructor but it is currently unused.
This fixes the problem of having anchors that are too dependent on compiler internals by naming the anchor after the position in the source of the particular value.
This is a general function that is intended to be used for naming specific identifiers uniquely.
Signed-off-by: Paul-Elliot <[email protected]> Co-authored-by: Paul-Elliot <[email protected]>
"Implementation loading" and "shape resolution" go to their own module. Cleaned up some test Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
They get an entry in the `uid_to_loc` table, so we need to add them to the `loc_to_ident` table as well for semantic anchor to work. Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
Co-authored-by: Jules Aguillon <[email protected]> Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
The anchors are different, since source code anchors needs the full path, but at least the qualification is similar. Replaces `full_name` which did not included enough information to disambiguate functor parameters. Signed-off-by: Paul-Elliot <[email protected]>
This will allow to have correct anchors to constructors, as soon as they are added to the `uid_to_loc` table. Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
for more self-explanatoriness Signed-off-by: Paul-Elliot <[email protected]>
Now that anchors are semantic, they should not depend on the OCaml version.
Also simplify the interfaces of the loader a bit.
23ec596
to
0121576
Compare
src/odoc/odoc_link.ml
Outdated
|> handle_warnings ~input_warnings ~warnings_options | ||
>>= fun (m, warnings) -> | ||
Odoc_file.save_unit output ~warnings (m, shape); | ||
let m = {m with Odoc_model.Lang.Compilation_unit.shape = None} in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't it make more sense to modify the compilation unit record only in the link_unit
function?
When a record is modified in many place, I find it difficult to have an idea of which field will go into the file...
Moreover, it would be nice to add a small comment, just in case it is not clear later (shapes are not used after the link phase
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was aiming for 'as close as possible to the save function' - the comment is a good idea.
I tested and yes, the "same" file with windows and unix ending won't have the same locations. (One could argue that it's not really the same file...) We cannot use filename/line number/pos_bol since the anchor might not be unique, due to line directives. |
Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
6a2ba13
to
652931c
Compare
So that adding some content at the end of the file does not modify anchors that are above. Signed-off-by: Paul-Elliot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot has changed in a small amount of time making the review difficult.
But I think this is ready to merge!
src/odoc/odoc_link.ml
Outdated
the compiler and load it in odoc x.y compiled with a different | ||
version of the compiler. This is an important use case for | ||
voodoo. *) | ||
let m = { m with Odoc_model.Lang.Compilation_unit.shape = None } in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And uid_to_id
as well ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh yes, I had originally thought that wouldn't be needed but you're right, we do need to sort that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hrm, I'm rather more nervous about putting an empty map in there than a None. Might need some more options...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, fixed, I think!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks nice :)
src/odoc/odoc_link.ml
Outdated
save an odocl file with odoc x.y compiled with one version of | ||
the compiler and load it in odoc x.y compiled with a different | ||
version of the compiler. This is an important use case for | ||
voodoo. *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think these assumptions are true. Perhaps just say that we avoid adding more constraint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reworded it.
src/loader/odoc_loader.ml
Outdated
@@ -45,24 +42,44 @@ exception Not_an_interface | |||
|
|||
exception Make_root_error of string | |||
|
|||
#if OCAML_VERSION >= (4, 14, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this cppo contamination is not needed, this function could be moved to Implementation
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a nice idea, yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Does the compiler keep actual locations as well? Not looked, but presumably Merlin uses actual locations (insensitive to In general, the key thing for being LF/CRLF compatible is to ensure that the No measurement can ever span a new line. So |
OK, I think any other issues with this are minor and can be fixed up in follow-up PRs. In it goes! |
Instead of relying on internals of the compiler to generate anchors in source code rendering, this PR makes "semantic" anchors; thus improving stability between OCaml versions/changes in the implementation.
It is done in the following way:
local_elt_7165
Ident.t
to id,Uid.t
)module-Reference.value-render_resolved
.loc_to_id
that we combine with theuid_to_loc
table to have auid_to_id
table, and store this table in.odoc
files.Note: This PR is extracted from https://github.com/jonludlam/odoc/tree/source-locations-3, leaving the "Global jump" part aside. It contains some refactoring.