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

Improve error code linkability #15431

Closed
Avasam opened this issue Jun 13, 2023 · 8 comments · Fixed by #15435
Closed

Improve error code linkability #15431

Avasam opened this issue Jun 13, 2023 · 8 comments · Fixed by #15435

Comments

@Avasam
Copy link
Sponsor Contributor

Avasam commented Jun 13, 2023

Documentation

In microsoft/vscode-mypy#58, I'm adding the functionality to link to specific mypy error code documentation. However, there's two issues affecting maintainability:

  • The error codes span 2 pages
  • The anchors are autogenerated from titles

Which leads to having to keep a map of all code-to-url, like this:
https://github.com/microsoft/vscode-mypy/pull/58/files#diff-3c2e579f59d8e749f5527d64f087396907db30414fe139bc91a1ecce9f9613ddR22

I would prefer if it was possible to programmatically link to mypy error codes documentation with only the information given by the mypy/dmypy CLI. Redirection is an acceptable solution to me.

@Avasam
Copy link
Sponsor Contributor Author

Avasam commented Jun 13, 2023

FWIW, if I can get the "Error codes enabled by default" from the mypy CLI, that solves the first point.
The second one should be solvable with custom RST anchors. https://sublime-and-sphinx-guide.readthedocs.io/en/latest/references.html#use-a-custom-anchor

@ikonst
Copy link
Contributor

ikonst commented Jun 13, 2023

Yes, if our error codes pages had custom anchors instead of the autogenerated one, it'd help.

Random thought - perhaps there's a Sphinx extension, or one could be easily built, to redirect anchors (which should be unique within the docs) to the right page / anchor?

ilevkivskyi pushed a commit that referenced this issue Jun 14, 2023
Makes the HTML builder generate a _refs.html file that redirects
(global) refs (when provided as a hash i.e. `_refs.html#some-ref`) to
the appropriate document.

This allows tools (e.g. #15431) to link to well-known refs.
@ilevkivskyi
Copy link
Member

Note btw there is also #7186 I think it is a good idea to add direct short links. I am quite sure we can write a Sphinx extension for this.

@ilevkivskyi
Copy link
Member

OK, so here is the proposed fix #15435

ilevkivskyi added a commit that referenced this issue Jun 14, 2023
Fixes #15431

After this PR one will be able to easily find documentation for given
error code using
`https://mypy.readthedocs.io/en/stable/_refs.html#code-{code as reported
by mypy}`, for example
`https://mypy.readthedocs.io/en/stable/_refs.html#code-attr-defined`.
@Avasam
Copy link
Sponsor Contributor Author

Avasam commented Jun 14, 2023

Note btw there is also #7186 I think it is a good idea to add direct short links. I am quite sure we can write a Sphinx extension for this.

I missed that. This is basically a duplicate. I'm essentially asking for the same thing.

@ilevkivskyi
Copy link
Member

OK, I guess I actually broke the readthedocs build. Everything works locally and in CI because mypy is available there, but likely not available in readthedocs build env. I will submit a follow-up PR to only verify the error code completeness in tests.

@ilevkivskyi
Copy link
Member

#15437 should fix the build.

@ilevkivskyi
Copy link
Member

OK, this is now available in latest: https://mypy.readthedocs.io/en/latest/_refs.html#code-union-attr

hauntsaninja pushed a commit that referenced this issue Jun 24, 2023
Makes the HTML builder generate a _refs.html file that redirects
(global) refs (when provided as a hash i.e. `_refs.html#some-ref`) to
the appropriate document.

This allows tools (e.g. #15431) to link to well-known refs.
hauntsaninja pushed a commit that referenced this issue Jun 24, 2023
Fixes #15431

After this PR one will be able to easily find documentation for given
error code using
`https://mypy.readthedocs.io/en/stable/_refs.html#code-{code as reported
by mypy}`, for example
`https://mypy.readthedocs.io/en/stable/_refs.html#code-attr-defined`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants