-
Notifications
You must be signed in to change notification settings - Fork 219
Allow to format signatures in docstrings #631
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
Conversation
Any thoughts @ccordoba12 ? It would be amazing to get it in to allow downstreams to customize. |
A gentle ping :) |
as these are not supported by pluggy
## 📝 Summary - formats signatures using ruff so that they are easier to read - depends on python-lsp/python-lsp-server#631 ## 🔍 Description of Changes Adds `pylsp_signatures_to_markdown` hook, re-using existing `ruff` formatting utility. | Before | After | |--|--| |  |  | Note: this does not help with `pd.read_csv`; I am not sure why it is not hitting this code path, but notably it happens on the completion items which do not have a docstring either. ## 📋 Checklist - [x] I have read the [contributor guidelines](https://github.com/marimo-team/marimo/blob/main/CONTRIBUTING.md). - [ ] For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on [Discord](https://marimo.io/discord?ref=pr), or the community [discussions](https://github.com/marimo-team/marimo/discussions) (Please provide a link if applicable). - [ ] I have added tests for the changes made. - [x] I have run the code and verified that it works as expected. ## 📜 Reviewers @mscolnick
Sorry for the delay in replying @krassowski. For now I only have one question for you: instead of using a hook for this ( The problem with your current approach is that only users that know that they need to install I know that would add a new dependency in either Ruff or Black, but I'm ok with that. I'd prefer Black because it's pure Python, but we could look for Ruff being on PATH and use it first if found. Another option would be to create a new package (similar to |
I think there are two cons:
If you are ok with having this in I think we could even get away with having |
Right, I didn't thought about it.
Sure, no problem about it if that'd benefit more users.
That'd be inconsistent to users because with no ruff/black they'd get different results than without them and it'd be hard for them to understand why. So, I'd say let's go with black and leave ruff as optional. In that case, the UX would be practically indistinguishable since both give pretty much the same result. |
Just in case, gave a check to the implementation and current approach (using Jupyterlab + this PR + Regarding the implementation approach to follow, the idea then is to include |
Nop, it's to implement the functionality of that plugin directly in
Yep, although I think that's a bit overkill.
Right. |
@ccordoba12 @dalthviz when you get a chance this is ready for another round of review - as per the request above I removed the hook and implemented the functionality directly, adding a |
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.
Thank you @krassowski for the updates here! I checked locally the changes here and seems like things are working as expected 👍
Left a comment regarding adding ruff
as an optional dependency and another regarding the TODO about the removesuffix
/removeprefix
functions and Python 3.8 but besides that this LGTM so leaving it approved.
@@ -19,6 +19,7 @@ dependencies = [ | |||
"pluggy>=1.0.0", | |||
"python-lsp-jsonrpc>=1.1.0,<2.0.0", | |||
"ujson>=3.0.0", | |||
"black" |
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.
Should ruff
be added as an optional dependecy below?
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 so. The functionality to format signatures will be provided by Black and it'll be very similar to the one given by Ruff.
pylsp/_utils.py
Outdated
if formatter.is_installed: | ||
try: | ||
return ( | ||
# TODO: replace with str.removeprefix and str.removesuffix |
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.
Should an issue be created to track this TODO @ccordoba12 ?
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.
No, I think we should simply bump our Python version to 3.9 in another PR so we don't need those functions here.
Could you take care of 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.
I opened #650
c93a9af
to
8ed0fa9
Compare
This is a proposal for #630. Initially this PR proposed adding
pylsp_signatures_to_markdown
hook, but currently it modifies theformat_docstring
directly without use of the hook.Using a list → str approach allows the hook to modify how alternative signatures are displayed.
There are no user-facing changes out of the box, however users can now installpylsp-ruff-signature
Users see much more readable function signatures in hover and in completion documentation, for example:
pylsp-ruff-signature
pylsp-ruff-signature