-
Notifications
You must be signed in to change notification settings - Fork 216
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
base: develop
Are you sure you want to change the base?
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. |
This is a proposal for #630. It comes down to:
pylsp_signatures_to_markdown
hook which takes a list of strings (signatures) and returns a single (markdown) stringsignatures_to_markdown
toformat_docstring
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 install
pylsp-ruff-signature
:to see much more readable function signatures in hover and in completion documentation, for example:
pylsp-ruff-signature
pylsp-ruff-signature