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

Revise the client/server protocol #178

Closed
edreamleo opened this issue Jul 22, 2021 · 2 comments · Fixed by #191
Closed

Revise the client/server protocol #178

edreamleo opened this issue Jul 22, 2021 · 2 comments · Fixed by #191
Assignees
Labels
bug Something isn't working protocol

Comments

@edreamleo
Copy link
Collaborator

edreamleo commented Jul 22, 2021

See Leo PR: #2095.

Background

This problem appeared while working on #173. Imo, the problem can not be fixed in leoserver.py. The client/server protocol must be changed.

At present, server.get_all_leo_commands returns a lists of dictionaries, each of the form:

{
  "label": command_name,
  "func":  func_name,
  "detail": doc,
}

However, for @command or @button scripts, the func_name will be the name of a callback function, which in effect is an anonymous function! The horrendous details are in sc.registerAllCommands (in mod_scripting.py) and also in the AtButtonCallback class, instances of which are (iirc) essentially fancy callbacks.

Proposal

  1. server.get_all_leo_commands should return dictionaries without a "func" key.
  2. The client should be able request execution of commands by the name of the command, not the name of the function that executes the command.
  3. The server should continue to support the execution of methods in Leo.

Discussion

ekr-server-protocol branch contains the new version of leoserver.py. See PR #2095.

The leoInteg minibuffer already shows command names, not function names, so very little in leoInteg will have to change.

Summary

server.get_all_leo_commands will supply only command names. The names of anonymous callback functions are useless!

See the docstring of server._do_message for the new protocol.

@edreamleo edreamleo added bug Something isn't working protocol labels Jul 22, 2021
@tbpassin
Copy link

This is similar to a capability I came up with in a non-Leo program. A whole lot of commands are triggered by pushbuttons. The child window that has the buttons is almost entirely independent, except for having a reference to the dispatcher located in its parent window. When a button is pressed in the child window, its callback sends back to the dispatcher a string which is the lookup name for the real method. The dispatcher has a lookup table - a dict, of course, being Python - to dispatch the actual method.

Neither the parent nor the child need to know anything about how the other one implements any of the details. They only need to know how to send/receive the right string. It works great for my application, it should work just as well for Leo.

@edreamleo edreamleo changed the title The client/server protocol should use only command names, never function names Revise the client/server protocol Jul 23, 2021
boltex added a commit that referenced this issue Jul 23, 2021
Also calls it by the name itself and with a '-' prefix.
Fixes #173 , Fixes #178
@boltex boltex mentioned this issue Jul 23, 2021
@boltex
Copy link
Owner

boltex commented Jul 24, 2021

Done in dev :)
Thanks to both @tbpassin & @edreamleo for their insights and support!!

@boltex boltex mentioned this issue Aug 16, 2021
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working protocol
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants