Make odoc references in documentation comments navigable - #2139
Open
N1ark wants to merge 5 commits into
Open
Conversation
N1ark
force-pushed
the
resolve-doc-links
branch
from
August 11, 2026 22:30
7053dc0 to
3554018
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #436.
Implement
textDocument/documentLinkanddocumentLink/resolve, which report the links an odoc comment contains, so editors underline them and cmd-click opens them:In the above example,
t,Foo,https://ocaml.organdhttps://ocaml.org/manualare all clickable! Same if you hover the function and click in the markdown docs. Cross-references are resolved lazily. Cross-module and stdlib references work wherever go-to-definition does, i.e. once the project is built;{!Stdlib.List.map}opens the compiler'slist.ml.This is best reviewed commit by commit; all increments build and all tests pass at each step.
The PR is bigger than I initially planned. If it's easier for you I'm happy to split it into ~3 PRs, following the structure given by the commits here!
Implementation Details
The system for handling odoc references is in
Odoc_reference. From there, we callMerlin_analysis.Locate.from_stringrather thanQuery_protocol.Locate, as we need to select exactly in what environment we're looking for the reference. The environment is obtained fromTypedtree, which is not ideal, but e.g.Locatealso uses it, so I felt like it was probably ok, for such a light usage.All functions in
Doc_to_mdhave a new?resolveparameter, to resolve references to hyperlinks. The change is a bit churny, sorry about that. If you have a better idea to avoid it let me know :)Also had to tweak
Uri.to_string, it used to percent-encode sub-delimiters in queries and fragments, so a URL likehttps://x.dev/s?q=a&n=1was escaped ashttps://x.dev/s?q%3Da%26n%3D1, which is wrong.Note
I acknowledge this PR was mostly written by an LLM. I took care of directing it, and reviewing the changes along with cleaning up parts of the code and comment.