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

Add start_line and end_line information in linkcode #9625

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

u1735067
Copy link

Subject: Add start_line and end_line information in linkcode

Feature or Bugfix

  • Feature

Purpose

  • Allow the linkcode extension to add a line anchor in the generated link

Detail

  • Add 2 info keys for linkcode_resolve: start_line and end_line (None by default)
  • Use the viewcode-find-source event first to find the lines informations (to be used with sphinx-autoapi for example)
    • If it failed, optionally (linkcode_line_try_import setting) use the same import method as in sphinx.ext.viewcode
      (sphinx.pycode.ModuleAnalyzer) to find the line informations (same warning)
  • Documentation updated (not sure this is correct though)

Relates

@u1735067 u1735067 force-pushed the linkcode_lines branch 2 times, most recently from a3542e1 to 275d232 Compare September 11, 2021 00:46
sphinx/ext/linkcode.py Outdated Show resolved Hide resolved
@AA-Turner AA-Turner changed the base branch from 5.x to master October 16, 2022 15:25
@AA-Turner AA-Turner added this to the some future version milestone Apr 29, 2023
return "https://somesite/sourcerepo/%s.py" % filename
line_anchor = ""
if info['start_line'] >= 0:
line_anchor = "#L%s" % info['start_line']
Copy link
Contributor

Choose a reason for hiding this comment

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

Any plans to add the end_line to the line anchor? It seems that the format #L10-L23 is supported by a few web-based code viewers (checked: GitHub, GitLab, Gitea, Debsources).

@jayaddison jayaddison added the type:enhancement enhance or introduce a new feature label Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement enhance or introduce a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

autolinkcode extension
3 participants