Skip to content

Add Open in Editor support for template paths#2198

Open
federicobond wants to merge 8 commits intodjango-commons:mainfrom
federicobond:open-in-editor
Open

Add Open in Editor support for template paths#2198
federicobond wants to merge 8 commits intodjango-commons:mainfrom
federicobond:open-in-editor

Conversation

@federicobond
Copy link
Copy Markdown
Member

@federicobond federicobond commented Sep 13, 2025

Description

This adds a setting to configure an Open in editor URL when you click on a template path. Makes it easier to jump directly to the template and edit. Can develop it further and/or add tests if there is interest in the feature.

Captura de pantalla 2025-09-13 a la(s) 23 04 38

Checklist:

  • I have added the relevant tests for this change.
  • I have added an item to the Pending section of docs/changes.rst.

Comment thread docs/configuration.rst Outdated
Copy link
Copy Markdown
Member

@tim-schilling tim-schilling left a comment

Choose a reason for hiding this comment

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

I wonder if it's possible to detect that the project is running in vscode and we could avoid the setting altogether?

@tim-schilling
Copy link
Copy Markdown
Member

Ah, that's a good reference. I like the idea of having a magic-ish value/constant to specify rather than asking them to write in a lambda for a setting.

@federicobond federicobond force-pushed the open-in-editor branch 3 times, most recently from 99f0190 to 418e706 Compare October 7, 2025 04:28
@federicobond
Copy link
Copy Markdown
Member Author

@tim-schilling updated to use a constant to specify the editor URL format.

Test failures appear unrelated.

Comment thread debug_toolbar/utils.py
Comment thread debug_toolbar/panels/templates/panel.py Outdated
Comment thread docs/configuration.rst Outdated
Copy link
Copy Markdown
Member

@tim-schilling tim-schilling left a comment

Choose a reason for hiding this comment

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

This is looking good. Marking it as Request Changes to ask for the tests. I think tests that cover get_editor_url and the new get_stats() of TemplatesPanel would be great.

The other stretch thing would be to add is a reference to the new setting in the TemplatesPanel documentation.

@federicobond
Copy link
Copy Markdown
Member Author

I just added the requested tests and updated the docs format.

I would prefer to hold off with documenting this as something that's mostly useful for the requests panel because I believe it's going to be useful in other places too (like stacktraces).

Comment thread tests/test_utils.py
Comment thread tests/panels/test_template.py Outdated
@tim-schilling
Copy link
Copy Markdown
Member

That's fair about mentioning the editor setting the templates panel documentation. I think we do want to have this mentioned in the changes.rst file so folks get alerted to the change in the next release.

@federicobond
Copy link
Copy Markdown
Member Author

Done!

Copy link
Copy Markdown
Member

@tim-schilling tim-schilling left a comment

Choose a reason for hiding this comment

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

I'm good with these changes. I'd like @matthiask to agree (I don't want to merge a new feature unilaterally). He's out on holiday currently, so it may be a few weeks.

@tim-schilling
Copy link
Copy Markdown
Member

Thank you @federicobond for your patience and perseverance!

@federicobond
Copy link
Copy Markdown
Member Author

Rebased against latest main.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Dec 4, 2025

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  debug_toolbar
  utils.py
  debug_toolbar/panels/templates
  panel.py 201-202
Project Total  

This report was generated by python-coverage-comment-action

Copy link
Copy Markdown
Member

@codingjoe codingjoe left a comment

Choose a reason for hiding this comment

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

@federicobond may I be so bold as to propose a slimmer solution?
Instead of hardcoding all the different URIs for all the different tool, why not just give the option to provide a URI as a setting?

If not, this should at least be the fallback. So if the URI is not in the dictionary, whatever string was provided is interpreted as a custom URI template.

Comment thread debug_toolbar/utils.py
Comment on lines +440 to +442
if template is None:
return None
return template.format(file=file, line=line)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if template is None:
return None
return template.format(file=file, line=line)
if template:
return template.format(file=file, line=line)

Comment thread debug_toolbar/utils.py


def get_editor_url(file: str, line: int = 1) -> str | None:
formats = {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This would be a great application for the all new template strings.

Comment thread debug_toolbar/settings.py
"debug_toolbar.panels.profiling.ProfilingPanel",
"debug_toolbar.panels.redirects.RedirectsPanel",
},
"EDITOR": "vscode",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think there should be a default. I'd rather have the feature disabled by default.

@tim-schilling
Copy link
Copy Markdown
Member

@codingjoe I think we're going to have a difference of opinion here. #2198 (comment)

@codingjoe
Copy link
Copy Markdown
Member

@codingjoe I think we're going to have a difference of opinion here. #2198 (comment)

Yes, I saw that, which is why I proposed both at the end. Joining ease of use with flexibility for the obscure. It also doesn't require a lambda; the setting can remain a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants