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

formatters_reformat_selection: handle case that nothing was selected #422

Merged
merged 1 commit into from
May 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions code/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ def formatters_reformat_last(formatters: str) -> str:
def formatters_reformat_selection(formatters: str) -> str:
"""Reformats the current selection."""
selected = edit.selected_text()
if not selected:
print("Asked to reformat selection, but nothing selected!")
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't have a warning system to use for this kind of thing? If not then obv out of scope here but might be a useful thing to make at some point

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

there is Python's logging.warning() but @knausj85 seemed to prefer print()?

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with logging.warning - my suggestion on another PR was to open an issue so we remember switch to logging.warning more broadly if its useful to folks.

I previously hadn't really bothered since I run with zero output unless explicitly debugging something.

return
unformatted = re.sub(r"[^a-zA-Z0-9]+", " ", selected).lower()
# TODO: Separate out camelcase & studleycase vars

Expand Down