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

External hotkey commands: tagging, linting and checking sync #1498

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Niloth-p
Copy link
Collaborator

What does this PR do, and why?

  • Identify external hotkey commands with a suffix (readline shortcuts and terminal shortcuts)
  • Lint for the usage of external commands in the codebase. They're not intended for direct use or modification.
  • Check sync of readline shortcuts with urwid_readline's keymap.

External discussion & connections

How did you test this?

  • Manually - Behavioral changes
  • Manually - Visual changes
  • Adapting existing automated tests
  • Adding automated tests for new behavior (or missing tests)
  • Existing automated tests should already cover this (only a refactor of tested code)

Self-review checklist for each commit

  • It is a minimal coherent idea
  • It has a commit summary following the documented style (title & body)
  • It has a commit summary describing the motivation and reasoning for the change
  • It individually passes linting and tests
  • It contains test additions for any new behavior
  • It flows clearly from a previous branch commit, and/or prepares for the next commit

Visual changes

Our shortcuts missing in Readline's keymap:
Screenshot from 2024-05-12 22-45-46
On successful linting:
Screenshot from 2024-05-12 22-46-30
Linting errors:
Screenshot from 2024-05-12 22-47-02

@zulipbot
Copy link
Member

Hello @zulip/server-hotkeys members, this pull request was labeled with the "area: hotkeys" label, so you may want to check it out!

@zormit zormit assigned zormit and unassigned zormit May 14, 2024
@zormit zormit self-requested a review May 24, 2024 14:45
@zormit
Copy link

zormit commented May 29, 2024

FWIW, I had put myself as a reviewer here earlier, but I'll wait for a peer review by @rsashank before looking at this one in more detail.

Briefly looking at it (and maybe this has been discussed, I didn't look far), I'm wondering whether the "suffix-based" approach is sustainable, or whether it maybe makes sense to extend the KeyBinding dictionary by a field?

@zormit zormit removed their request for review May 29, 2024 15:00
("NEXT_LINE", ["Down", "Ctrl n"]),
("SEND_MESSAGE", ["Ctrl d", "Meta Enter"]),
Copy link
Member

Choose a reason for hiding this comment

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

What's the motivation behind this change?

Copy link

@zormit zormit Jun 3, 2024

Choose a reason for hiding this comment

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

I'd have the same question :) (just reposting this, because it's now my turn to review)

Copy link

Choose a reason for hiding this comment

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

Also, partially answering it myself. The commit message gives it away: The change seems to aim to

not use readline hotkeys [in tests]

but I'm not sure why. Is it because we can not rely on the existence of readline shortcuts due to upstream changes? That seems reasonable to me. In general, it could be helpful to add the motivation for the goal to the commit message :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I forgot to get back regarding this, @zormit, my apologies.
Sashank and I had talked about this, so I hadn't added an answer here for his initial question.

Yes, you're spot on.
Thank you for the pointer. You've worded it pretty well, I did not think of it in those terms.

Comment on lines +65 to +97
for file_path in ZULIPTERMINAL.rglob("*.py"):
if file_path in EXCLUDED_FILES:
continue
with file_path.open() as f:
contents = f.read()
regex_matches = re.finditer(regex_pattern, contents)
suffix_matches = re.finditer(suffix, contents)
count_matches = sum(1 for _ in regex_matches) + sum(
1 for _ in suffix_matches
)
if count_matches > 0:
print(
f"{file_path.name} contains {count_matches} mentions of {command_type} commands."
)
error_flag = 1
if error_flag == 1:
print(
f"{command_type} commands are not intended for direct use or modification."
)
print(
f"Please refer to {KEYS_FILE_NAME} for identifying the {command_type} commands."
)
print("Rerun this command after removing the usage of external commands.")
sys.exit(error_flag)
Copy link
Member

Choose a reason for hiding this comment

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

Could we adjust this approach to include the line number at which it was found along with the file name?

@rsashank
Copy link
Member

I manually tested this and reviewed the code - added 2 comments. Maybe making the commit summaries a bit more descriptive, but other than that, LGTM :)

Tests updated to not use urwid_readline hotkeys,
to avoid reliance on external libraries for hotkey commands.
Identify external commands using the added suffix.

Search for both the suffix variable and the actual suffix.
@Niloth-p Niloth-p force-pushed the category/1498-lint-and-sync-readline/pr branch from bb6c9f3 to 03f36cc Compare June 13, 2024 07:19
@Niloth-p Niloth-p force-pushed the category/1498-lint-and-sync-readline/pr branch from 03f36cc to 0495e29 Compare June 13, 2024 08:30
Copy link
Collaborator Author

@Niloth-p Niloth-p left a comment

Choose a reason for hiding this comment

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

I've rebased this and updated the commit message of the 1st commit.

But, it appears the approach / direction to take would vary quite a lot from the current implementation. And as zormit pointed out, the priority in relation to other issues needs to be addressed before we proceed with discussing / implementing alternate approaches.

("NEXT_LINE", ["Down", "Ctrl n"]),
("SEND_MESSAGE", ["Ctrl d", "Meta Enter"]),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I forgot to get back regarding this, @zormit, my apologies.
Sashank and I had talked about this, so I hadn't added an answer here for his initial question.

Yes, you're spot on.
Thank you for the pointer. You've worded it pretty well, I did not think of it in those terms.

@Niloth-p Niloth-p added the further discussion required Discuss this on #zulip-terminal on chat.zulip.org label Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: hotkeys further discussion required Discuss this on #zulip-terminal on chat.zulip.org PR needs mentor review PR needs review PR requires feedback to proceed size: XL [Automatic label added by zulipbot]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants