-
-
Notifications
You must be signed in to change notification settings - Fork 684
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
🐛 Fix shell completions for the fish shell #1069
base: master
Are you sure you want to change the base?
Conversation
5e44213
to
eda9ccb
Compare
eda9ccb
to
b22f193
Compare
Thanks for the detailed report and PR! I'll look into this 🙏 |
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.
Hi @goraje,
Thanks so much for this PR and the detailed report! The issue is clear and it does look like a regression for the fish shell.
In the PR #877, I should have added some more tests to check this behaviour for different shells. I've now gone in and added these tests to your PR: I've created a (minimal) version of docs_src.commands.help.tutorial001
that has Rich tags in its subcommand descriptions, and ran completion tests in the new file test_completion_complete_rich.py
to double check that the Rich formatting isn't there. These tests seem to be succeeding just fine on this PR. I double checked on master
, and there the test_completion_complete_subcommand_fish
fails because of the tab substitution you mentioned.
I saw that you also added tests to double check the functionality of the _sanitize_help_text
function. I think that's great - I've just gone ahead and pulled that into its own separate test file for clarity.
So far the behaviour and code look fine to me, but I'll yet perform a final detailed review of all the code changes and will comment here again when I do so.
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.
This looks good to me, leaving this for a final review by Tiangolo. Thanks again, @goraje!
Thank you for looking into that :) I completely agree that the tests didn’t quite belong but I didn’t feel confident enough to modify the project’s structure by adding a test module on my own so thank you for fixing that for me :) |
As described in this discussion #1068, recent changes aimed at sanitizing the help text from rich tags during autocompletion generation (#877) have caused problems with proper generation of autocompletions for fish shell, when rich is installed in the environment. The main culprit most likely being the
rich.Console.print
method that converts the tabs into spaces which results in malformed autocompletes. I propose a different approach to sanitizing the help text, one that allows to perform the removal of tags before the output offormat_completion
gets returned, thus allowing to generate a rich tag-free help text, while still being able to pass it to a formatting-preserving output viaclick.echo
intyper.completion
(basically reverting this part of the source to the way it was before the #877 changes).An example of the current behaviour while using
rich.Console.print
invoked intyper.rich_utils.print_with_rich
:with an example app of the following structure: