From 423a26156d6912a45ac1f7a53c87d4a5ae246ac0 Mon Sep 17 00:00:00 2001 From: johneffo Date: Sat, 13 Aug 2022 16:09:20 +0100 Subject: [PATCH 01/43] split command client to applicactions --- apps/vscode/command_client/command_client.py | 75 ++++++++------------ apps/vscode/command_client/visual_studio.py | 17 +++++ apps/vscode/command_client/vs_code.py | 28 ++++++++ 3 files changed, 75 insertions(+), 45 deletions(-) create mode 100644 apps/vscode/command_client/visual_studio.py create mode 100644 apps/vscode/command_client/vs_code.py diff --git a/apps/vscode/command_client/command_client.py b/apps/vscode/command_client/command_client.py index a8dd9fcd6c..e28b9edec7 100644 --- a/apps/vscode/command_client/command_client.py +++ b/apps/vscode/command_client/command_client.py @@ -1,5 +1,6 @@ import json import os +import string import time from dataclasses import dataclass from pathlib import Path @@ -13,10 +14,10 @@ # to remove it STALE_TIMEOUT_MS = 60_000 -# The amount of time to wait for VSCode to perform a command, in seconds +# The amount of time to wait for client application to perform a command, in seconds VSCODE_COMMAND_TIMEOUT_SECONDS = 3.0 -# When doing exponential back off waiting for vscode to perform a command, how +# When doing exponential back off waiting for client application to perform a command, how # long to sleep the first time MINIMUM_SLEEP_TIME_SECONDS = 0.0005 @@ -33,6 +34,7 @@ ctx.matches = r""" app: vscode +app: visual_studio """ mac_ctx.matches = r""" os: mac @@ -48,17 +50,8 @@ class NotSet: def __repr__(self): return "" - -def run_vscode_command_by_command_palette(command_id: str): - """Execute command via command palette. Preserves the clipboard.""" - actions.user.command_palette() - actions.user.paste(command_id) - actions.key("enter") - - def write_json_exclusive(path: Path, body: Any): """Writes jsonified object to file, failing if the file already exists - Args: path (Path): The path of the file to write body (Any): The object to convert to json and write @@ -88,11 +81,9 @@ def to_dict(self): def write_request(request: Request, path: Path): """Converts the given request to json and writes it to the file, failing if the file already exists unless it is stale in which case it replaces it - Args: request (Request): The request to serialize path (Path): The path to write to - Raises: Exception: If another process has an active request file """ @@ -123,23 +114,20 @@ def handle_existing_request_file(path): robust_unlink(path) -def run_vscode_command( +def run_command( command_id: str, *args: str, wait_for_finish: bool = False, return_command_output: bool = False, ): - """Runs a VSCode command, using command server if available - + """Runs a command, using command server if available Args: command_id (str): The ID of the VSCode command to run wait_for_finish (bool, optional): Whether to wait for the command to finish before returning. Defaults to False. return_command_output (bool, optional): Whether to return the output of the command. Defaults to False. - Raises: Exception: If there is an issue with the file-based communication, or VSCode raises an exception - Returns: Object: The response from the command, if requested. """ @@ -153,7 +141,7 @@ def run_vscode_command( if args or return_command_output: raise Exception("Must use command-server extension for advanced commands") print("Communication dir not found; falling back to command palette") - run_vscode_command_by_command_palette(command_id) + actions.user.command_client_fallback(command_id) return request_path = communication_dir_path / "request.json" @@ -180,9 +168,9 @@ def run_vscode_command( print("WARNING: Found old response file") robust_unlink(response_path) - # Then, perform keystroke telling VSCode to execute the command in the - # request file. Because only the active VSCode instance will accept - # keypresses, we can be sure that the active VSCode instance will be the + # Then, perform keystroke telling client application to execute the command in the + # request file. Because only the active client application instance will accept + # keypresses, we can be sure that the active client application instance will be the # one to execute the command. actions.user.trigger_command_server_command_execution() @@ -210,7 +198,6 @@ def run_vscode_command( def get_communication_dir_path(): """Returns directory that is used by command-server for communication - Returns: Path: The path to the communication dir """ @@ -221,13 +208,12 @@ def get_communication_dir_path(): if hasattr(os, "getuid"): suffix = f"-{os.getuid()}" - return Path(gettempdir()) / f"vscode-command-server{suffix}" + return Path(gettempdir()) / f"{actions.user.directory()}{suffix}" def robust_unlink(path: Path): """Unlink the given file if it exists, and if we're on windows and it is currently in use, just rename it - Args: path (Path): The path to unlink """ @@ -251,13 +237,10 @@ def robust_unlink(path: Path): def read_json_with_timeout(path: str) -> Any: """Repeatedly tries to read a json object from the given path, waiting until there is a trailing new line indicating that the write is complete - Args: path (str): The path to read from - Raises: Exception: If we timeout waiting for a response - Returns: Any: The json-decoded contents of the file """ @@ -292,14 +275,14 @@ class Actions: def vscode(command_id: str): """Execute command via vscode command server, if available, or fallback to command palette.""" - run_vscode_command(command_id) + run_command(command_id) def vscode_and_wait(command_id: str): """Execute command via vscode command server, if available, and wait for command to finish. If command server not available, uses command palette and doesn't guarantee that it will wait for command to finish.""" - run_vscode_command(command_id, wait_for_finish=True) + run_command(command_id, wait_for_finish=True) def vscode_with_plugin( command_id: str, @@ -310,7 +293,7 @@ def vscode_with_plugin( arg5: Any = NotSet, ): """Execute command via vscode command server.""" - run_vscode_command( + run_command( command_id, arg1, arg2, @@ -328,7 +311,7 @@ def vscode_with_plugin_and_wait( arg5: Any = NotSet, ): """Execute command via vscode command server and wait for command to finish.""" - run_vscode_command( + run_command( command_id, arg1, arg2, @@ -347,7 +330,7 @@ def vscode_get( arg5: Any = NotSet, ) -> Any: """Execute command via vscode command server and return command output.""" - return run_vscode_command( + return run_command( command_id, arg1, arg2, @@ -357,18 +340,29 @@ def vscode_get( return_command_output=True, ) + def directory() -> string: + """Return the final directory of the command server""" + def trigger_command_server_command_execution(): """Issue keystroke to trigger command server to execute command that was written to the file. For internal use only""" actions.key("ctrl-shift-f17") + def live_pre_phrase_signal() -> bool: + """Used by application contexts emit_pre_phrase_signal to emit a pre phrase signal""" + get_signal_path("prePhrase").touch() + return True + def emit_pre_phrase_signal() -> bool: """Touches a file to indicate that a phrase is about to begin execution""" - + def did_emit_pre_phrase_signal() -> bool: """Indicates whether the pre-phrase signal was emitted at the start of this phrase""" return did_emit_pre_phrase_signal + def command_client_fallback(command_id: str): + """The stratagy to use when no command server directory is located for the the application""" + @mac_ctx.action_class("user") class MacUserActions: @@ -384,6 +378,7 @@ def trigger_command_server_command_execution(): @global_ctx.action_class("user") class GlobalUserActions: + def emit_pre_phrase_signal() -> bool: # NB: We explicitly define a noop version of this action in the global # context here so that it doesn't do anything before phrases if you're not @@ -391,14 +386,6 @@ def emit_pre_phrase_signal() -> bool: return False -@ctx.action_class("user") -class UserActions: - def emit_pre_phrase_signal() -> bool: - get_signal_path("prePhrase").touch() - - return True - - class MissingCommunicationDir(Exception): pass @@ -406,10 +393,8 @@ class MissingCommunicationDir(Exception): def get_signal_path(name: str) -> Path: """ Get the path to a signal in the signal subdirectory. - Args: name (str): The name of the signal - Returns: Path: The signal path """ @@ -439,4 +424,4 @@ def post_phrase(_: Any): speech_system.register("pre:phrase", pre_phrase) -speech_system.register("post:phrase", post_phrase) +speech_system.register("post:phrase", post_phrase) \ No newline at end of file diff --git a/apps/vscode/command_client/visual_studio.py b/apps/vscode/command_client/visual_studio.py new file mode 100644 index 0000000000..64c91df882 --- /dev/null +++ b/apps/vscode/command_client/visual_studio.py @@ -0,0 +1,17 @@ +import string +from talon import Context, actions + +visual_studio_ctx= Context() + +visual_studio_ctx.matches = r""" +app: visual_studio +""" + +@visual_studio_ctx.action_class("user") +class VisualStudioActions: + def directory() -> string: + return "visual-studio-commandServer" + + def emit_pre_phrase_signal() -> bool: + print("****Visual studio pre-phrase***") + return actions.user.live_pre_phrase_signal() \ No newline at end of file diff --git a/apps/vscode/command_client/vs_code.py b/apps/vscode/command_client/vs_code.py new file mode 100644 index 0000000000..330b0e5c4d --- /dev/null +++ b/apps/vscode/command_client/vs_code.py @@ -0,0 +1,28 @@ +import string +from talon import Context, actions + +vs_code_ctx = Context() + +vs_code_ctx.matches = r""" +app: vscode +""" + +@vs_code_ctx.action_class("user") +class VsCodeAction: + def directory() -> string: + return "vscode-command-server" + + def emit_pre_phrase_signal() -> bool: + return actions.user.live_pre_phrase_signal() + + def command_client_fallback(command_id: str): + """Execute command via command palette. Preserves the clipboard.""" + actions.user.command_palette() + actions.user.paste(command_id) + actions.key("enter") + + def vscode(command_id: str): + """Execute command via vscode command server, if available, or fallback + to command palette.""" + actions.user.post_command(command_id) + From df2e5237f15401e318e5dbeecdd009e8767df79e Mon Sep 17 00:00:00 2001 From: johneffo Date: Sat, 13 Aug 2022 17:02:00 +0100 Subject: [PATCH 02/43] Remove trailing white space --- apps/vscode/command_client/command_client.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/vscode/command_client/command_client.py b/apps/vscode/command_client/command_client.py index e28b9edec7..df29d153e8 100644 --- a/apps/vscode/command_client/command_client.py +++ b/apps/vscode/command_client/command_client.py @@ -233,7 +233,6 @@ def robust_unlink(path: Path): else: raise e - def read_json_with_timeout(path: str) -> Any: """Repeatedly tries to read a json object from the given path, waiting until there is a trailing new line indicating that the write is complete @@ -385,7 +384,6 @@ def emit_pre_phrase_signal() -> bool: # in vscode. return False - class MissingCommunicationDir(Exception): pass From a345741c112d02109ce458cc86ede14ca4d1fe41 Mon Sep 17 00:00:00 2001 From: johneffo Date: Sat, 13 Aug 2022 17:02:19 +0100 Subject: [PATCH 03/43] More white space --- apps/vscode/command_client/vs_code.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/vscode/command_client/vs_code.py b/apps/vscode/command_client/vs_code.py index 330b0e5c4d..10cf14915c 100644 --- a/apps/vscode/command_client/vs_code.py +++ b/apps/vscode/command_client/vs_code.py @@ -24,5 +24,4 @@ def command_client_fallback(command_id: str): def vscode(command_id: str): """Execute command via vscode command server, if available, or fallback to command palette.""" - actions.user.post_command(command_id) - + actions.user.post_command(command_id) \ No newline at end of file From 9304e229a5e40ecd75c8bb407bfd414a8fdca847 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 13 Aug 2022 16:27:05 +0000 Subject: [PATCH 04/43] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- apps/vscode/command_client/command_client.py | 18 +++++----- apps/vscode/command_client/visual_studio.py | 14 ++++---- apps/vscode/command_client/vs_code.py | 36 +++++++++++--------- 3 files changed, 37 insertions(+), 31 deletions(-) diff --git a/apps/vscode/command_client/command_client.py b/apps/vscode/command_client/command_client.py index df29d153e8..05d2a068b9 100644 --- a/apps/vscode/command_client/command_client.py +++ b/apps/vscode/command_client/command_client.py @@ -50,6 +50,7 @@ class NotSet: def __repr__(self): return "" + def write_json_exclusive(path: Path, body: Any): """Writes jsonified object to file, failing if the file already exists Args: @@ -233,6 +234,7 @@ def robust_unlink(path: Path): else: raise e + def read_json_with_timeout(path: str) -> Any: """Repeatedly tries to read a json object from the given path, waiting until there is a trailing new line indicating that the write is complete @@ -341,26 +343,26 @@ def vscode_get( def directory() -> string: """Return the final directory of the command server""" - + def trigger_command_server_command_execution(): """Issue keystroke to trigger command server to execute command that was written to the file. For internal use only""" actions.key("ctrl-shift-f17") def live_pre_phrase_signal() -> bool: - """Used by application contexts emit_pre_phrase_signal to emit a pre phrase signal""" - get_signal_path("prePhrase").touch() - return True + """Used by application contexts emit_pre_phrase_signal to emit a pre phrase signal""" + get_signal_path("prePhrase").touch() + return True def emit_pre_phrase_signal() -> bool: """Touches a file to indicate that a phrase is about to begin execution""" - + def did_emit_pre_phrase_signal() -> bool: """Indicates whether the pre-phrase signal was emitted at the start of this phrase""" return did_emit_pre_phrase_signal def command_client_fallback(command_id: str): - """The stratagy to use when no command server directory is located for the the application""" + """The stratagy to use when no command server directory is located for the the application""" @mac_ctx.action_class("user") @@ -377,13 +379,13 @@ def trigger_command_server_command_execution(): @global_ctx.action_class("user") class GlobalUserActions: - def emit_pre_phrase_signal() -> bool: # NB: We explicitly define a noop version of this action in the global # context here so that it doesn't do anything before phrases if you're not # in vscode. return False + class MissingCommunicationDir(Exception): pass @@ -422,4 +424,4 @@ def post_phrase(_: Any): speech_system.register("pre:phrase", pre_phrase) -speech_system.register("post:phrase", post_phrase) \ No newline at end of file +speech_system.register("post:phrase", post_phrase) diff --git a/apps/vscode/command_client/visual_studio.py b/apps/vscode/command_client/visual_studio.py index 64c91df882..09046010e7 100644 --- a/apps/vscode/command_client/visual_studio.py +++ b/apps/vscode/command_client/visual_studio.py @@ -1,17 +1,19 @@ import string + from talon import Context, actions -visual_studio_ctx= Context() +visual_studio_ctx = Context() visual_studio_ctx.matches = r""" app: visual_studio """ + @visual_studio_ctx.action_class("user") class VisualStudioActions: - def directory() -> string: - return "visual-studio-commandServer" + def directory() -> string: + return "visual-studio-commandServer" - def emit_pre_phrase_signal() -> bool: - print("****Visual studio pre-phrase***") - return actions.user.live_pre_phrase_signal() \ No newline at end of file + def emit_pre_phrase_signal() -> bool: + print("****Visual studio pre-phrase***") + return actions.user.live_pre_phrase_signal() diff --git a/apps/vscode/command_client/vs_code.py b/apps/vscode/command_client/vs_code.py index 10cf14915c..2bbb79d212 100644 --- a/apps/vscode/command_client/vs_code.py +++ b/apps/vscode/command_client/vs_code.py @@ -1,5 +1,6 @@ import string -from talon import Context, actions + +from talon import Context, actions vs_code_ctx = Context() @@ -7,21 +8,22 @@ app: vscode """ + @vs_code_ctx.action_class("user") class VsCodeAction: - def directory() -> string: - return "vscode-command-server" - - def emit_pre_phrase_signal() -> bool: - return actions.user.live_pre_phrase_signal() - - def command_client_fallback(command_id: str): - """Execute command via command palette. Preserves the clipboard.""" - actions.user.command_palette() - actions.user.paste(command_id) - actions.key("enter") - - def vscode(command_id: str): - """Execute command via vscode command server, if available, or fallback - to command palette.""" - actions.user.post_command(command_id) \ No newline at end of file + def directory() -> string: + return "vscode-command-server" + + def emit_pre_phrase_signal() -> bool: + return actions.user.live_pre_phrase_signal() + + def command_client_fallback(command_id: str): + """Execute command via command palette. Preserves the clipboard.""" + actions.user.command_palette() + actions.user.paste(command_id) + actions.key("enter") + + def vscode(command_id: str): + """Execute command via vscode command server, if available, or fallback + to command palette.""" + actions.user.post_command(command_id) From 09ef97eb3376139ee324a3250d0287fdc0190a0c Mon Sep 17 00:00:00 2001 From: johneffo Date: Fri, 19 Aug 2022 19:04:29 +0100 Subject: [PATCH 05/43] Address CR comments --- apps/vscode/command_client/command_client.py | 33 +++++++++++-------- .../command_client/command_client_tag.py | 21 ++++++++++++ apps/vscode/command_client/visual_studio.py | 11 ++++--- apps/vscode/command_client/vs_code.py | 14 ++++---- 4 files changed, 53 insertions(+), 26 deletions(-) create mode 100644 apps/vscode/command_client/command_client_tag.py diff --git a/apps/vscode/command_client/command_client.py b/apps/vscode/command_client/command_client.py index 05d2a068b9..01a350b2c0 100644 --- a/apps/vscode/command_client/command_client.py +++ b/apps/vscode/command_client/command_client.py @@ -33,8 +33,7 @@ linux_ctx = Context() ctx.matches = r""" -app: vscode -app: visual_studio +tag: command_client """ mac_ctx.matches = r""" os: mac @@ -53,6 +52,7 @@ def __repr__(self): def write_json_exclusive(path: Path, body: Any): """Writes jsonified object to file, failing if the file already exists + Args: path (Path): The path of the file to write body (Any): The object to convert to json and write @@ -126,9 +126,11 @@ def run_command( command_id (str): The ID of the VSCode command to run wait_for_finish (bool, optional): Whether to wait for the command to finish before returning. Defaults to False. return_command_output (bool, optional): Whether to return the output of the command. Defaults to False. + Raises: Exception: If there is an issue with the file-based communication, or VSCode raises an exception + Returns: Object: The response from the command, if requested. """ @@ -199,6 +201,7 @@ def run_command( def get_communication_dir_path(): """Returns directory that is used by command-server for communication + Returns: Path: The path to the communication dir """ @@ -209,12 +212,13 @@ def get_communication_dir_path(): if hasattr(os, "getuid"): suffix = f"-{os.getuid()}" - return Path(gettempdir()) / f"{actions.user.directory()}{suffix}" + return Path(gettempdir()) / f"{actions.user.command_server_directory()}{suffix}" def robust_unlink(path: Path): """Unlink the given file if it exists, and if we're on windows and it is currently in use, just rename it + Args: path (Path): The path to unlink """ @@ -238,10 +242,13 @@ def robust_unlink(path: Path): def read_json_with_timeout(path: str) -> Any: """Repeatedly tries to read a json object from the given path, waiting until there is a trailing new line indicating that the write is complete + Args: path (str): The path to read from + Raises: Exception: If we timeout waiting for a response + Returns: Any: The json-decoded contents of the file """ @@ -341,7 +348,7 @@ def vscode_get( return_command_output=True, ) - def directory() -> string: + def command_server_directory() -> string: """Return the final directory of the command server""" def trigger_command_server_command_execution(): @@ -349,20 +356,12 @@ def trigger_command_server_command_execution(): was written to the file. For internal use only""" actions.key("ctrl-shift-f17") - def live_pre_phrase_signal() -> bool: - """Used by application contexts emit_pre_phrase_signal to emit a pre phrase signal""" - get_signal_path("prePhrase").touch() - return True - - def emit_pre_phrase_signal() -> bool: - """Touches a file to indicate that a phrase is about to begin execution""" - def did_emit_pre_phrase_signal() -> bool: """Indicates whether the pre-phrase signal was emitted at the start of this phrase""" return did_emit_pre_phrase_signal def command_client_fallback(command_id: str): - """The stratagy to use when no command server directory is located for the the application""" + """The strategy to use when no command server directory is located for the the application""" @mac_ctx.action_class("user") @@ -386,6 +385,14 @@ def emit_pre_phrase_signal() -> bool: return False +@ctx.action_class("user") +class UserActions: + def emit_pre_phrase_signal() -> bool: + get_signal_path("prePhrase").touch() + + return True + + class MissingCommunicationDir(Exception): pass diff --git a/apps/vscode/command_client/command_client_tag.py b/apps/vscode/command_client/command_client_tag.py new file mode 100644 index 0000000000..669c81a438 --- /dev/null +++ b/apps/vscode/command_client/command_client_tag.py @@ -0,0 +1,21 @@ +import string +from talon import Module + +mod = Module() + +mod.tag("command_client", desc="For applications which implement File based RPC with Talon") + + +@mod.action_class +class Actions: + def command_server_directory() -> string: + """The dirctory which contains the files required for communication between the application and Talon. + This is the only function which absolutly must be implemented for any application using the command-client.""" + + def emit_pre_phrase_signal() -> bool: + """The command client can touch a signal file at the start of a phrase, function has a default implementation + which does this, if your implementation does not require this signal file be touched simply return false.""" + + def command_client_fallback(command_id: str): + """Execute an alternative stratagy for issuing the command, if non exists just implemnt + there is not need to implement, the fall back is to do nothing.""" \ No newline at end of file diff --git a/apps/vscode/command_client/visual_studio.py b/apps/vscode/command_client/visual_studio.py index 09046010e7..63c21afcf2 100644 --- a/apps/vscode/command_client/visual_studio.py +++ b/apps/vscode/command_client/visual_studio.py @@ -2,18 +2,19 @@ from talon import Context, actions -visual_studio_ctx = Context() +ctx = Context() -visual_studio_ctx.matches = r""" +ctx.matches = r""" app: visual_studio """ +ctx.tags = ["user.command_client"] -@visual_studio_ctx.action_class("user") + +@ctx.action_class("user") class VisualStudioActions: - def directory() -> string: + def command_server_directory() -> string: return "visual-studio-commandServer" def emit_pre_phrase_signal() -> bool: - print("****Visual studio pre-phrase***") return actions.user.live_pre_phrase_signal() diff --git a/apps/vscode/command_client/vs_code.py b/apps/vscode/command_client/vs_code.py index 2bbb79d212..c1c3b02b9f 100644 --- a/apps/vscode/command_client/vs_code.py +++ b/apps/vscode/command_client/vs_code.py @@ -2,16 +2,17 @@ from talon import Context, actions -vs_code_ctx = Context() +ctx = Context() -vs_code_ctx.matches = r""" +ctx.matches = r""" app: vscode """ +ctx.tags = ["user.command_client"] -@vs_code_ctx.action_class("user") +@ctx.action_class("user") class VsCodeAction: - def directory() -> string: + def command_server_directory() -> string: return "vscode-command-server" def emit_pre_phrase_signal() -> bool: @@ -23,7 +24,4 @@ def command_client_fallback(command_id: str): actions.user.paste(command_id) actions.key("enter") - def vscode(command_id: str): - """Execute command via vscode command server, if available, or fallback - to command palette.""" - actions.user.post_command(command_id) + \ No newline at end of file From 613281d945298c27da577e52ebd71b8569092da4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 19 Aug 2022 18:05:30 +0000 Subject: [PATCH 06/43] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- apps/vscode/command_client/command_client.py | 6 +++--- apps/vscode/command_client/command_client_tag.py | 13 ++++++++----- apps/vscode/command_client/vs_code.py | 2 -- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/apps/vscode/command_client/command_client.py b/apps/vscode/command_client/command_client.py index 01a350b2c0..af3a6ae4fe 100644 --- a/apps/vscode/command_client/command_client.py +++ b/apps/vscode/command_client/command_client.py @@ -52,7 +52,7 @@ def __repr__(self): def write_json_exclusive(path: Path, body: Any): """Writes jsonified object to file, failing if the file already exists - + Args: path (Path): The path of the file to write body (Any): The object to convert to json and write @@ -242,10 +242,10 @@ def robust_unlink(path: Path): def read_json_with_timeout(path: str) -> Any: """Repeatedly tries to read a json object from the given path, waiting until there is a trailing new line indicating that the write is complete - + Args: path (str): The path to read from - + Raises: Exception: If we timeout waiting for a response diff --git a/apps/vscode/command_client/command_client_tag.py b/apps/vscode/command_client/command_client_tag.py index 669c81a438..8903ecc5c7 100644 --- a/apps/vscode/command_client/command_client_tag.py +++ b/apps/vscode/command_client/command_client_tag.py @@ -1,21 +1,24 @@ import string + from talon import Module mod = Module() -mod.tag("command_client", desc="For applications which implement File based RPC with Talon") +mod.tag( + "command_client", desc="For applications which implement File based RPC with Talon" +) @mod.action_class class Actions: def command_server_directory() -> string: - """The dirctory which contains the files required for communication between the application and Talon. + """The dirctory which contains the files required for communication between the application and Talon. This is the only function which absolutly must be implemented for any application using the command-client.""" def emit_pre_phrase_signal() -> bool: - """The command client can touch a signal file at the start of a phrase, function has a default implementation - which does this, if your implementation does not require this signal file be touched simply return false.""" + """The command client can touch a signal file at the start of a phrase, function has a default implementation + which does this, if your implementation does not require this signal file be touched simply return false.""" def command_client_fallback(command_id: str): """Execute an alternative stratagy for issuing the command, if non exists just implemnt - there is not need to implement, the fall back is to do nothing.""" \ No newline at end of file + there is not need to implement, the fall back is to do nothing.""" diff --git a/apps/vscode/command_client/vs_code.py b/apps/vscode/command_client/vs_code.py index c1c3b02b9f..524f6d1fc9 100644 --- a/apps/vscode/command_client/vs_code.py +++ b/apps/vscode/command_client/vs_code.py @@ -23,5 +23,3 @@ def command_client_fallback(command_id: str): actions.user.command_palette() actions.user.paste(command_id) actions.key("enter") - - \ No newline at end of file From 2f5c7268e7c21f31c035d4c9fcbf2d53195bd533 Mon Sep 17 00:00:00 2001 From: johneffo Date: Sat, 20 Aug 2022 07:30:32 +0100 Subject: [PATCH 07/43] Remove error producing pre-phrase-signal --- apps/vscode/command_client/visual_studio.py | 3 --- apps/vscode/command_client/vs_code.py | 3 --- 2 files changed, 6 deletions(-) diff --git a/apps/vscode/command_client/visual_studio.py b/apps/vscode/command_client/visual_studio.py index 63c21afcf2..cdcc5052b2 100644 --- a/apps/vscode/command_client/visual_studio.py +++ b/apps/vscode/command_client/visual_studio.py @@ -15,6 +15,3 @@ class VisualStudioActions: def command_server_directory() -> string: return "visual-studio-commandServer" - - def emit_pre_phrase_signal() -> bool: - return actions.user.live_pre_phrase_signal() diff --git a/apps/vscode/command_client/vs_code.py b/apps/vscode/command_client/vs_code.py index 524f6d1fc9..58dd2d4d75 100644 --- a/apps/vscode/command_client/vs_code.py +++ b/apps/vscode/command_client/vs_code.py @@ -15,9 +15,6 @@ class VsCodeAction: def command_server_directory() -> string: return "vscode-command-server" - def emit_pre_phrase_signal() -> bool: - return actions.user.live_pre_phrase_signal() - def command_client_fallback(command_id: str): """Execute command via command palette. Preserves the clipboard.""" actions.user.command_palette() From dbb689387f13bc1da243af40688c2038dbbf627f Mon Sep 17 00:00:00 2001 From: johneffo Date: Sun, 21 Aug 2022 23:03:01 +0100 Subject: [PATCH 08/43] Make VSCode Shim --- code/formatters.py | 2 +- misc/formatters.talon | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/code/formatters.py b/code/formatters.py index f0858c2933..60fa27d85c 100644 --- a/code/formatters.py +++ b/code/formatters.py @@ -142,7 +142,7 @@ def every_word(word_func): "dotted": formatters_dict["DOT_SEPARATED"], "dub string": formatters_dict["DOUBLE_QUOTED_STRING"], "dunder": formatters_dict["DOUBLE_UNDERSCORE"], - "hammer": formatters_dict["PUBLIC_CAMEL_CASE"], + "candle": formatters_dict["PUBLIC_CAMEL_CASE"], "kebab": formatters_dict["DASH_SEPARATED"], "packed": formatters_dict["DOUBLE_COLON_SEPARATED"], "padded": formatters_dict["SPACE_SURROUNDED_STRING"], diff --git a/misc/formatters.talon b/misc/formatters.talon index fcf681a328..20cf9b3804 100644 --- a/misc/formatters.talon +++ b/misc/formatters.talon @@ -15,3 +15,6 @@ select that: user.select_last_phrase() before that: user.before_last_phrase() nope that | scratch that: user.clear_last_phrase() nope that was : user.formatters_reformat_last(formatters) + + +formatters_reformat_selectio \ No newline at end of file From 211802a9f848eb25782011147bd46906339252c1 Mon Sep 17 00:00:00 2001 From: johneffo Date: Sun, 21 Aug 2022 23:03:31 +0100 Subject: [PATCH 09/43] Add Shim --- apps/vscode/command_client/command_client.py | 37 ++++--- apps/vscode/command_client/vs_code.py | 22 ---- apps/vscode/command_client/vscode.py | 101 +++++++++++++++++++ 3 files changed, 118 insertions(+), 42 deletions(-) delete mode 100644 apps/vscode/command_client/vs_code.py create mode 100644 apps/vscode/command_client/vscode.py diff --git a/apps/vscode/command_client/command_client.py b/apps/vscode/command_client/command_client.py index af3a6ae4fe..aa4cdf52ad 100644 --- a/apps/vscode/command_client/command_client.py +++ b/apps/vscode/command_client/command_client.py @@ -49,6 +49,8 @@ class NotSet: def __repr__(self): return "" +class NoFileServerException(Exception): + pass def write_json_exclusive(path: Path, body: Any): """Writes jsonified object to file, failing if the file already exists @@ -123,17 +125,18 @@ def run_command( ): """Runs a command, using command server if available Args: - command_id (str): The ID of the VSCode command to run + command_id (str): The ID of the command to run wait_for_finish (bool, optional): Whether to wait for the command to finish before returning. Defaults to False. return_command_output (bool, optional): Whether to return the output of the command. Defaults to False. Raises: Exception: If there is an issue with the file-based communication, or - VSCode raises an exception + application raises an exception Returns: Object: The response from the command, if requested. """ + print("++++++++++++++++++++++Bedger") # NB: This is a hack to work around the fact that talon doesn't support # variable argument lists args = [x for x in args if x is not NotSet] @@ -143,10 +146,8 @@ def run_command( if not communication_dir_path.exists(): if args or return_command_output: raise Exception("Must use command-server extension for advanced commands") - print("Communication dir not found; falling back to command palette") - actions.user.command_client_fallback(command_id) - return - + raise NoFileServerException("Communication dir not found; falling back to command palette") + request_path = communication_dir_path / "request.json" response_path = communication_dir_path / "response.json" @@ -280,19 +281,19 @@ def read_json_with_timeout(path: str) -> Any: @mod.action_class class Actions: - def vscode(command_id: str): - """Execute command via vscode command server, if available, or fallback + def run_command(command_id: str): + """Execute command via application command server, if available, or fallback to command palette.""" run_command(command_id) - def vscode_and_wait(command_id: str): - """Execute command via vscode command server, if available, and wait + def run_command_and_wait(command_id: str): + """Execute command via application command server, if available, and wait for command to finish. If command server not available, uses command palette and doesn't guarantee that it will wait for command to finish.""" run_command(command_id, wait_for_finish=True) - def vscode_with_plugin( + def run_command_with_plugin( command_id: str, arg1: Any = NotSet, arg2: Any = NotSet, @@ -300,7 +301,7 @@ def vscode_with_plugin( arg4: Any = NotSet, arg5: Any = NotSet, ): - """Execute command via vscode command server.""" + """Execute command via application command server.""" run_command( command_id, arg1, @@ -310,7 +311,7 @@ def vscode_with_plugin( arg5, ) - def vscode_with_plugin_and_wait( + def run_command_with_plugin_and_wait( command_id: str, arg1: Any = NotSet, arg2: Any = NotSet, @@ -318,7 +319,7 @@ def vscode_with_plugin_and_wait( arg4: Any = NotSet, arg5: Any = NotSet, ): - """Execute command via vscode command server and wait for command to finish.""" + """Execute command via application command server and wait for command to finish.""" run_command( command_id, arg1, @@ -329,7 +330,7 @@ def vscode_with_plugin_and_wait( wait_for_finish=True, ) - def vscode_get( + def run_command_get( command_id: str, arg1: Any = NotSet, arg2: Any = NotSet, @@ -337,7 +338,7 @@ def vscode_get( arg4: Any = NotSet, arg5: Any = NotSet, ) -> Any: - """Execute command via vscode command server and return command output.""" + """Execute command via application command server and return command output.""" return run_command( command_id, arg1, @@ -360,10 +361,6 @@ def did_emit_pre_phrase_signal() -> bool: """Indicates whether the pre-phrase signal was emitted at the start of this phrase""" return did_emit_pre_phrase_signal - def command_client_fallback(command_id: str): - """The strategy to use when no command server directory is located for the the application""" - - @mac_ctx.action_class("user") class MacUserActions: def trigger_command_server_command_execution(): diff --git a/apps/vscode/command_client/vs_code.py b/apps/vscode/command_client/vs_code.py deleted file mode 100644 index 58dd2d4d75..0000000000 --- a/apps/vscode/command_client/vs_code.py +++ /dev/null @@ -1,22 +0,0 @@ -import string - -from talon import Context, actions - -ctx = Context() - -ctx.matches = r""" -app: vscode -""" -ctx.tags = ["user.command_client"] - - -@ctx.action_class("user") -class VsCodeAction: - def command_server_directory() -> string: - return "vscode-command-server" - - def command_client_fallback(command_id: str): - """Execute command via command palette. Preserves the clipboard.""" - actions.user.command_palette() - actions.user.paste(command_id) - actions.key("enter") diff --git a/apps/vscode/command_client/vscode.py b/apps/vscode/command_client/vscode.py new file mode 100644 index 0000000000..110a45fe71 --- /dev/null +++ b/apps/vscode/command_client/vscode.py @@ -0,0 +1,101 @@ +from pickle import FALSE +import string +from typing import Any +from .command_client import NotSet, NoFileServerException +from talon import Context, actions, Module + +ctx = Context() + +ctx.matches = r""" +app: vscode +""" +ctx.tags = ["user.command_client"] +mod = Module() + + +def command_client_fallback(command_id: str): + """Execute command via command palette. Preserves the clipboard.""" + actions.user.command_palette() + actions.user.paste(command_id) + actions.key("enter") + print("Command issues via command palette for better performance install the VSCode extension for Talon") + + +@ctx.action_class("user") +class VsCodeAction: + def command_server_directory() -> string: + return "vscode-command-server" + +@mod.action_class +class Actions: + def vscode(command_id: str): + """Execute command via vscode command server, if available, or fallback + to command palette.""" + try: + actions.user.run_command(command_id) + except NoFileServerException: + command_client_fallback(command_id) + + def vscode_and_wait(command_id: str): + """Execute command via vscode command server, if available, and wait + for command to finish. If command server not available, uses command + palette and doesn't guarantee that it will wait for command to + finish.""" + try: + actions.user.run_command_and_wait(command_id) + except NoFileServerException: + command_client_fallback(command_id) + + def vscode_with_plugin( + command_id: str, + arg1: Any = NotSet, + arg2: Any = NotSet, + arg3: Any = NotSet, + arg4: Any = NotSet, + arg5: Any = NotSet, + ): + """Execute command via vscode command server.""" + actions.user.run_command( + command_id, + arg1, + arg2, + arg3, + arg4, + arg5, + ) + + def vscode_with_plugin_and_wait( + command_id: str, + arg1: Any = NotSet, + arg2: Any = NotSet, + arg3: Any = NotSet, + arg4: Any = NotSet, + arg5: Any = NotSet, + ): + """Execute command via vscode command server and wait for command to finish.""" + actions.user.run_command_with_plugin_and_wait( + command_id, + arg1, + arg2, + arg3, + arg4, + arg5 + ) + + def vscode_get( + command_id: str, + arg1: Any = NotSet, + arg2: Any = NotSet, + arg3: Any = NotSet, + arg4: Any = NotSet, + arg5: Any = NotSet, + ) -> Any: + """Execute command via vscode command server and return command output.""" + return actions.user.run_command_get( + command_id, + arg1, + arg2, + arg3, + arg4, + arg5 + ) From a7c1c52f7c7c9b9be27124b6d30badcc82f4eeca Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 21 Aug 2022 22:04:39 +0000 Subject: [PATCH 10/43] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- apps/vscode/command_client/command_client.py | 11 +++-- apps/vscode/command_client/vscode.py | 45 +++++++++----------- misc/formatters.talon | 2 +- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/apps/vscode/command_client/command_client.py b/apps/vscode/command_client/command_client.py index aa4cdf52ad..50a7039c5f 100644 --- a/apps/vscode/command_client/command_client.py +++ b/apps/vscode/command_client/command_client.py @@ -49,8 +49,10 @@ class NotSet: def __repr__(self): return "" + class NoFileServerException(Exception): - pass + pass + def write_json_exclusive(path: Path, body: Any): """Writes jsonified object to file, failing if the file already exists @@ -146,8 +148,10 @@ def run_command( if not communication_dir_path.exists(): if args or return_command_output: raise Exception("Must use command-server extension for advanced commands") - raise NoFileServerException("Communication dir not found; falling back to command palette") - + raise NoFileServerException( + "Communication dir not found; falling back to command palette" + ) + request_path = communication_dir_path / "request.json" response_path = communication_dir_path / "response.json" @@ -361,6 +365,7 @@ def did_emit_pre_phrase_signal() -> bool: """Indicates whether the pre-phrase signal was emitted at the start of this phrase""" return did_emit_pre_phrase_signal + @mac_ctx.action_class("user") class MacUserActions: def trigger_command_server_command_execution(): diff --git a/apps/vscode/command_client/vscode.py b/apps/vscode/command_client/vscode.py index 110a45fe71..166e67bbc1 100644 --- a/apps/vscode/command_client/vscode.py +++ b/apps/vscode/command_client/vscode.py @@ -1,8 +1,10 @@ -from pickle import FALSE import string +from pickle import FALSE from typing import Any -from .command_client import NotSet, NoFileServerException -from talon import Context, actions, Module + +from talon import Context, Module, actions + +from .command_client import NoFileServerException, NotSet ctx = Context() @@ -14,11 +16,13 @@ def command_client_fallback(command_id: str): - """Execute command via command palette. Preserves the clipboard.""" - actions.user.command_palette() - actions.user.paste(command_id) - actions.key("enter") - print("Command issues via command palette for better performance install the VSCode extension for Talon") + """Execute command via command palette. Preserves the clipboard.""" + actions.user.command_palette() + actions.user.paste(command_id) + actions.key("enter") + print( + "Command issues via command palette for better performance install the VSCode extension for Talon" + ) @ctx.action_class("user") @@ -26,15 +30,16 @@ class VsCodeAction: def command_server_directory() -> string: return "vscode-command-server" + @mod.action_class class Actions: def vscode(command_id: str): """Execute command via vscode command server, if available, or fallback to command palette.""" try: - actions.user.run_command(command_id) + actions.user.run_command(command_id) except NoFileServerException: - command_client_fallback(command_id) + command_client_fallback(command_id) def vscode_and_wait(command_id: str): """Execute command via vscode command server, if available, and wait @@ -42,9 +47,9 @@ def vscode_and_wait(command_id: str): palette and doesn't guarantee that it will wait for command to finish.""" try: - actions.user.run_command_and_wait(command_id) + actions.user.run_command_and_wait(command_id) except NoFileServerException: - command_client_fallback(command_id) + command_client_fallback(command_id) def vscode_with_plugin( command_id: str, @@ -74,12 +79,7 @@ def vscode_with_plugin_and_wait( ): """Execute command via vscode command server and wait for command to finish.""" actions.user.run_command_with_plugin_and_wait( - command_id, - arg1, - arg2, - arg3, - arg4, - arg5 + command_id, arg1, arg2, arg3, arg4, arg5 ) def vscode_get( @@ -91,11 +91,4 @@ def vscode_get( arg5: Any = NotSet, ) -> Any: """Execute command via vscode command server and return command output.""" - return actions.user.run_command_get( - command_id, - arg1, - arg2, - arg3, - arg4, - arg5 - ) + return actions.user.run_command_get(command_id, arg1, arg2, arg3, arg4, arg5) diff --git a/misc/formatters.talon b/misc/formatters.talon index 20cf9b3804..802a8491c1 100644 --- a/misc/formatters.talon +++ b/misc/formatters.talon @@ -17,4 +17,4 @@ nope that | scratch that: user.clear_last_phrase() nope that was : user.formatters_reformat_last(formatters) -formatters_reformat_selectio \ No newline at end of file +formatters_reformat_selectio From 01bc65df654ba4889f9060a892b4b4990b405f79 Mon Sep 17 00:00:00 2001 From: johneffo Date: Mon, 22 Aug 2022 18:22:59 +0100 Subject: [PATCH 11/43] Remove unneeded function from tag --- apps/vscode/command_client/command_client_tag.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/apps/vscode/command_client/command_client_tag.py b/apps/vscode/command_client/command_client_tag.py index 8903ecc5c7..2d4504c426 100644 --- a/apps/vscode/command_client/command_client_tag.py +++ b/apps/vscode/command_client/command_client_tag.py @@ -18,7 +18,3 @@ def command_server_directory() -> string: def emit_pre_phrase_signal() -> bool: """The command client can touch a signal file at the start of a phrase, function has a default implementation which does this, if your implementation does not require this signal file be touched simply return false.""" - - def command_client_fallback(command_id: str): - """Execute an alternative stratagy for issuing the command, if non exists just implemnt - there is not need to implement, the fall back is to do nothing.""" From ce14610a22288d0ea72e2d5fb7958736f6df051b Mon Sep 17 00:00:00 2001 From: johneffo Date: Mon, 22 Aug 2022 18:25:45 +0100 Subject: [PATCH 12/43] Add comment to vscode --- apps/vscode/command_client/vscode.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/vscode/command_client/vscode.py b/apps/vscode/command_client/vscode.py index 166e67bbc1..e2d374283b 100644 --- a/apps/vscode/command_client/vscode.py +++ b/apps/vscode/command_client/vscode.py @@ -30,7 +30,8 @@ class VsCodeAction: def command_server_directory() -> string: return "vscode-command-server" - +# These commands are shims, to provide backwards compatibility, they may be removed in the fuuture. +# Prefer the run_command... version in command_client. @mod.action_class class Actions: def vscode(command_id: str): From 4c9c482f645d651a71de923a6e66a047531b342d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 22 Aug 2022 17:25:51 +0000 Subject: [PATCH 13/43] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- apps/vscode/command_client/vscode.py | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/vscode/command_client/vscode.py b/apps/vscode/command_client/vscode.py index e2d374283b..08f22b3c74 100644 --- a/apps/vscode/command_client/vscode.py +++ b/apps/vscode/command_client/vscode.py @@ -30,6 +30,7 @@ class VsCodeAction: def command_server_directory() -> string: return "vscode-command-server" + # These commands are shims, to provide backwards compatibility, they may be removed in the fuuture. # Prefer the run_command... version in command_client. @mod.action_class From 27aa1f3364180f1d1ade191059aa32f7d63f1b64 Mon Sep 17 00:00:00 2001 From: Michael Arntzenius Date: Wed, 24 Aug 2022 19:47:33 +0100 Subject: [PATCH 14/43] fix up some types & docs --- apps/vscode/command_client/command_client.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/vscode/command_client/command_client.py b/apps/vscode/command_client/command_client.py index 50a7039c5f..314da7fd72 100644 --- a/apps/vscode/command_client/command_client.py +++ b/apps/vscode/command_client/command_client.py @@ -121,13 +121,14 @@ def handle_existing_request_file(path): def run_command( command_id: str, - *args: str, + *args, wait_for_finish: bool = False, return_command_output: bool = False, ): """Runs a command, using command server if available Args: - command_id (str): The ID of the command to run + command_id (str): The ID of the command to run. + args: The arguments to the command. wait_for_finish (bool, optional): Whether to wait for the command to finish before returning. Defaults to False. return_command_output (bool, optional): Whether to return the output of the command. Defaults to False. From 640af19c8b4ecad0d8ac1f28ef2f4e664021c898 Mon Sep 17 00:00:00 2001 From: Michael Arntzenius Date: Wed, 24 Aug 2022 19:54:27 +0100 Subject: [PATCH 15/43] implement emit_pre_phrase_signal on module instead of in global context --- apps/vscode/command_client/command_client.py | 11 ----------- apps/vscode/command_client/command_client_tag.py | 7 +++++-- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/apps/vscode/command_client/command_client.py b/apps/vscode/command_client/command_client.py index 314da7fd72..54f58d2004 100644 --- a/apps/vscode/command_client/command_client.py +++ b/apps/vscode/command_client/command_client.py @@ -27,7 +27,6 @@ mod = Module() -global_ctx = Context() ctx = Context() mac_ctx = Context() linux_ctx = Context() @@ -379,15 +378,6 @@ def trigger_command_server_command_execution(): actions.key("ctrl-shift-alt-p") -@global_ctx.action_class("user") -class GlobalUserActions: - def emit_pre_phrase_signal() -> bool: - # NB: We explicitly define a noop version of this action in the global - # context here so that it doesn't do anything before phrases if you're not - # in vscode. - return False - - @ctx.action_class("user") class UserActions: def emit_pre_phrase_signal() -> bool: @@ -422,7 +412,6 @@ def get_signal_path(name: str) -> Path: def pre_phrase(_: Any): try: global did_emit_pre_phrase_signal - did_emit_pre_phrase_signal = actions.user.emit_pre_phrase_signal() except MissingCommunicationDir: pass diff --git a/apps/vscode/command_client/command_client_tag.py b/apps/vscode/command_client/command_client_tag.py index 2d4504c426..45f3743c5a 100644 --- a/apps/vscode/command_client/command_client_tag.py +++ b/apps/vscode/command_client/command_client_tag.py @@ -16,5 +16,8 @@ def command_server_directory() -> string: This is the only function which absolutly must be implemented for any application using the command-client.""" def emit_pre_phrase_signal() -> bool: - """The command client can touch a signal file at the start of a phrase, function has a default implementation - which does this, if your implementation does not require this signal file be touched simply return false.""" + """The command client can touch a signal file at the start of a phrase. If your + implementation does not require this, override emit_pre_phrase_signal to + return False.""" + # Unless we're in a command client app, we do nothing. + return False From c2fbf3274be3e6112dd26e9fa7e2699e4ecb9500 Mon Sep 17 00:00:00 2001 From: Michael Arntzenius Date: Wed, 24 Aug 2022 19:54:42 +0100 Subject: [PATCH 16/43] typo --- apps/vscode/command_client/command_client_tag.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/vscode/command_client/command_client_tag.py b/apps/vscode/command_client/command_client_tag.py index 45f3743c5a..a521cc3482 100644 --- a/apps/vscode/command_client/command_client_tag.py +++ b/apps/vscode/command_client/command_client_tag.py @@ -13,7 +13,7 @@ class Actions: def command_server_directory() -> string: """The dirctory which contains the files required for communication between the application and Talon. - This is the only function which absolutly must be implemented for any application using the command-client.""" + This is the only function which absolutely must be implemented for any application using the command-client.""" def emit_pre_phrase_signal() -> bool: """The command client can touch a signal file at the start of a phrase. If your From 295f84326017053ea55a000d5a0123043ddf3c48 Mon Sep 17 00:00:00 2001 From: Michael Arntzenius Date: Wed, 24 Aug 2022 20:01:59 +0100 Subject: [PATCH 17/43] restore some lines, remove unnecessary print --- apps/vscode/command_client/command_client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/vscode/command_client/command_client.py b/apps/vscode/command_client/command_client.py index 54f58d2004..5851e15e12 100644 --- a/apps/vscode/command_client/command_client.py +++ b/apps/vscode/command_client/command_client.py @@ -138,7 +138,6 @@ def run_command( Returns: Object: The response from the command, if requested. """ - print("++++++++++++++++++++++Bedger") # NB: This is a hack to work around the fact that talon doesn't support # variable argument lists args = [x for x in args if x is not NotSet] @@ -393,8 +392,10 @@ class MissingCommunicationDir(Exception): def get_signal_path(name: str) -> Path: """ Get the path to a signal in the signal subdirectory. + Args: name (str): The name of the signal + Returns: Path: The signal path """ From c41f8421dcda36010c466fa68821f44d96c5ac65 Mon Sep 17 00:00:00 2001 From: Michael Arntzenius Date: Wed, 24 Aug 2022 20:11:03 +0100 Subject: [PATCH 18/43] remove unwanted changes --- code/formatters.py | 2 +- misc/formatters.talon | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/code/formatters.py b/code/formatters.py index 60fa27d85c..f0858c2933 100644 --- a/code/formatters.py +++ b/code/formatters.py @@ -142,7 +142,7 @@ def every_word(word_func): "dotted": formatters_dict["DOT_SEPARATED"], "dub string": formatters_dict["DOUBLE_QUOTED_STRING"], "dunder": formatters_dict["DOUBLE_UNDERSCORE"], - "candle": formatters_dict["PUBLIC_CAMEL_CASE"], + "hammer": formatters_dict["PUBLIC_CAMEL_CASE"], "kebab": formatters_dict["DASH_SEPARATED"], "packed": formatters_dict["DOUBLE_COLON_SEPARATED"], "padded": formatters_dict["SPACE_SURROUNDED_STRING"], diff --git a/misc/formatters.talon b/misc/formatters.talon index 802a8491c1..fcf681a328 100644 --- a/misc/formatters.talon +++ b/misc/formatters.talon @@ -15,6 +15,3 @@ select that: user.select_last_phrase() before that: user.before_last_phrase() nope that | scratch that: user.clear_last_phrase() nope that was : user.formatters_reformat_last(formatters) - - -formatters_reformat_selectio From 7717e824a0ae289c24dfe246f0e2b0771055b02c Mon Sep 17 00:00:00 2001 From: johneffo Date: Thu, 25 Aug 2022 18:55:53 +0100 Subject: [PATCH 19/43] Remove duplicated code --- apps/vscode/command_client/vscode.py | 35 +++++++++++++--------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/apps/vscode/command_client/vscode.py b/apps/vscode/command_client/vscode.py index 08f22b3c74..23674dc953 100644 --- a/apps/vscode/command_client/vscode.py +++ b/apps/vscode/command_client/vscode.py @@ -4,7 +4,7 @@ from talon import Context, Module, actions -from .command_client import NoFileServerException, NotSet +from .command_client import NoFileServerException, NotSet, run_command ctx = Context() @@ -15,14 +15,17 @@ mod = Module() -def command_client_fallback(command_id: str): - """Execute command via command palette. Preserves the clipboard.""" - actions.user.command_palette() - actions.user.paste(command_id) - actions.key("enter") - print( - "Command issues via command palette for better performance install the VSCode extension for Talon" - ) +def command_server_or_client_fallback(command_id: str, wait: bool): + """Execute command via command server and us command pallete if directory not present.""" + try: + run_command(command_id, wait_for_finish = wait) + except NoFileServerException: + actions.user.command_palette() + actions.user.paste(command_id) + actions.key("enter") + print( + "Command issues via command palette for better performance install the VSCode extension for Talon" + ) @ctx.action_class("user") @@ -38,20 +41,14 @@ class Actions: def vscode(command_id: str): """Execute command via vscode command server, if available, or fallback to command palette.""" - try: - actions.user.run_command(command_id) - except NoFileServerException: - command_client_fallback(command_id) + command_server_or_client_fallback(command_id, False) def vscode_and_wait(command_id: str): """Execute command via vscode command server, if available, and wait for command to finish. If command server not available, uses command palette and doesn't guarantee that it will wait for command to finish.""" - try: - actions.user.run_command_and_wait(command_id) - except NoFileServerException: - command_client_fallback(command_id) + command_server_or_client_fallback(command_id, True) def vscode_with_plugin( command_id: str, @@ -80,7 +77,7 @@ def vscode_with_plugin_and_wait( arg5: Any = NotSet, ): """Execute command via vscode command server and wait for command to finish.""" - actions.user.run_command_with_plugin_and_wait( + actions.user.run_rpc_command_and_wait( command_id, arg1, arg2, arg3, arg4, arg5 ) @@ -93,4 +90,4 @@ def vscode_get( arg5: Any = NotSet, ) -> Any: """Execute command via vscode command server and return command output.""" - return actions.user.run_command_get(command_id, arg1, arg2, arg3, arg4, arg5) + return actions.user.run_rpc_command_get(command_id, arg1, arg2, arg3, arg4, arg5) From 340b70770659377aeda673e913c94b58e726bd3b Mon Sep 17 00:00:00 2001 From: johneffo Date: Thu, 25 Aug 2022 18:56:45 +0100 Subject: [PATCH 20/43] Remove run_command and rename --- apps/vscode/command_client/command_client.py | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/apps/vscode/command_client/command_client.py b/apps/vscode/command_client/command_client.py index 5851e15e12..09429929cd 100644 --- a/apps/vscode/command_client/command_client.py +++ b/apps/vscode/command_client/command_client.py @@ -284,19 +284,7 @@ def read_json_with_timeout(path: str) -> Any: @mod.action_class class Actions: - def run_command(command_id: str): - """Execute command via application command server, if available, or fallback - to command palette.""" - run_command(command_id) - - def run_command_and_wait(command_id: str): - """Execute command via application command server, if available, and wait - for command to finish. If command server not available, uses command - palette and doesn't guarantee that it will wait for command to - finish.""" - run_command(command_id, wait_for_finish=True) - - def run_command_with_plugin( + def run_rpc_command( command_id: str, arg1: Any = NotSet, arg2: Any = NotSet, @@ -314,7 +302,7 @@ def run_command_with_plugin( arg5, ) - def run_command_with_plugin_and_wait( + def run_rpc_command_and_wait( command_id: str, arg1: Any = NotSet, arg2: Any = NotSet, @@ -333,7 +321,7 @@ def run_command_with_plugin_and_wait( wait_for_finish=True, ) - def run_command_get( + def run_rpc_command_get( command_id: str, arg1: Any = NotSet, arg2: Any = NotSet, From 2d83c9ded59a21a8be67ef76b9d831daa32b6122 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 25 Aug 2022 18:00:16 +0000 Subject: [PATCH 21/43] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- apps/vscode/command_client/vscode.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/apps/vscode/command_client/vscode.py b/apps/vscode/command_client/vscode.py index 23674dc953..b71f295747 100644 --- a/apps/vscode/command_client/vscode.py +++ b/apps/vscode/command_client/vscode.py @@ -18,14 +18,14 @@ def command_server_or_client_fallback(command_id: str, wait: bool): """Execute command via command server and us command pallete if directory not present.""" try: - run_command(command_id, wait_for_finish = wait) + run_command(command_id, wait_for_finish=wait) except NoFileServerException: - actions.user.command_palette() - actions.user.paste(command_id) - actions.key("enter") - print( - "Command issues via command palette for better performance install the VSCode extension for Talon" - ) + actions.user.command_palette() + actions.user.paste(command_id) + actions.key("enter") + print( + "Command issues via command palette for better performance install the VSCode extension for Talon" + ) @ctx.action_class("user") @@ -77,9 +77,7 @@ def vscode_with_plugin_and_wait( arg5: Any = NotSet, ): """Execute command via vscode command server and wait for command to finish.""" - actions.user.run_rpc_command_and_wait( - command_id, arg1, arg2, arg3, arg4, arg5 - ) + actions.user.run_rpc_command_and_wait(command_id, arg1, arg2, arg3, arg4, arg5) def vscode_get( command_id: str, @@ -90,4 +88,6 @@ def vscode_get( arg5: Any = NotSet, ) -> Any: """Execute command via vscode command server and return command output.""" - return actions.user.run_rpc_command_get(command_id, arg1, arg2, arg3, arg4, arg5) + return actions.user.run_rpc_command_get( + command_id, arg1, arg2, arg3, arg4, arg5 + ) From 4badb6ca46d46ce2ff8048fb31a41fa6de56845a Mon Sep 17 00:00:00 2001 From: johneffo Date: Sun, 28 Aug 2022 08:10:29 +0100 Subject: [PATCH 22/43] Remove string from mong language --- apps/vscode/command_client/command_client.py | 2 +- apps/vscode/command_client/command_client_tag.py | 3 +-- apps/vscode/command_client/visual_studio.py | 4 ++-- apps/vscode/command_client/vscode.py | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/apps/vscode/command_client/command_client.py b/apps/vscode/command_client/command_client.py index 09429929cd..b0e2e890b2 100644 --- a/apps/vscode/command_client/command_client.py +++ b/apps/vscode/command_client/command_client.py @@ -340,7 +340,7 @@ def run_rpc_command_get( return_command_output=True, ) - def command_server_directory() -> string: + def command_server_directory() -> str: """Return the final directory of the command server""" def trigger_command_server_command_execution(): diff --git a/apps/vscode/command_client/command_client_tag.py b/apps/vscode/command_client/command_client_tag.py index a521cc3482..1f83fb931a 100644 --- a/apps/vscode/command_client/command_client_tag.py +++ b/apps/vscode/command_client/command_client_tag.py @@ -1,4 +1,3 @@ -import string from talon import Module @@ -11,7 +10,7 @@ @mod.action_class class Actions: - def command_server_directory() -> string: + def command_server_directory() -> str: """The dirctory which contains the files required for communication between the application and Talon. This is the only function which absolutely must be implemented for any application using the command-client.""" diff --git a/apps/vscode/command_client/visual_studio.py b/apps/vscode/command_client/visual_studio.py index cdcc5052b2..64a1c0ce01 100644 --- a/apps/vscode/command_client/visual_studio.py +++ b/apps/vscode/command_client/visual_studio.py @@ -1,4 +1,4 @@ -import string + from talon import Context, actions @@ -13,5 +13,5 @@ @ctx.action_class("user") class VisualStudioActions: - def command_server_directory() -> string: + def command_server_directory() -> str: return "visual-studio-commandServer" diff --git a/apps/vscode/command_client/vscode.py b/apps/vscode/command_client/vscode.py index b71f295747..cfb8db6801 100644 --- a/apps/vscode/command_client/vscode.py +++ b/apps/vscode/command_client/vscode.py @@ -30,7 +30,7 @@ def command_server_or_client_fallback(command_id: str, wait: bool): @ctx.action_class("user") class VsCodeAction: - def command_server_directory() -> string: + def command_server_directory() -> str: return "vscode-command-server" From eb5254b5ab0f49607e2634efaa75ac85bd3dfb26 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 28 Aug 2022 07:12:09 +0000 Subject: [PATCH 23/43] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- apps/vscode/command_client/command_client_tag.py | 1 - apps/vscode/command_client/visual_studio.py | 2 -- 2 files changed, 3 deletions(-) diff --git a/apps/vscode/command_client/command_client_tag.py b/apps/vscode/command_client/command_client_tag.py index 1f83fb931a..ab055653b9 100644 --- a/apps/vscode/command_client/command_client_tag.py +++ b/apps/vscode/command_client/command_client_tag.py @@ -1,4 +1,3 @@ - from talon import Module mod = Module() diff --git a/apps/vscode/command_client/visual_studio.py b/apps/vscode/command_client/visual_studio.py index 64a1c0ce01..4fff1acdf5 100644 --- a/apps/vscode/command_client/visual_studio.py +++ b/apps/vscode/command_client/visual_studio.py @@ -1,5 +1,3 @@ - - from talon import Context, actions ctx = Context() From 00343b484c95c9ca369a16438b43a13f9f37cc71 Mon Sep 17 00:00:00 2001 From: johneffo Date: Sun, 28 Aug 2022 08:33:17 +0100 Subject: [PATCH 24/43] Remove string import left --- apps/vscode/command_client/command_client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/vscode/command_client/command_client.py b/apps/vscode/command_client/command_client.py index b0e2e890b2..364f68d1af 100644 --- a/apps/vscode/command_client/command_client.py +++ b/apps/vscode/command_client/command_client.py @@ -1,6 +1,5 @@ import json import os -import string import time from dataclasses import dataclass from pathlib import Path From 34ae8e9830b84e1d1730401977d4bc5cbc092fe6 Mon Sep 17 00:00:00 2001 From: johneffo Date: Thu, 1 Sep 2022 19:58:17 +0100 Subject: [PATCH 25/43] double check missing newlines --- apps/vscode/command_client/command_client.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/vscode/command_client/command_client.py b/apps/vscode/command_client/command_client.py index 364f68d1af..21219ba34a 100644 --- a/apps/vscode/command_client/command_client.py +++ b/apps/vscode/command_client/command_client.py @@ -84,9 +84,11 @@ def to_dict(self): def write_request(request: Request, path: Path): """Converts the given request to json and writes it to the file, failing if the file already exists unless it is stale in which case it replaces it + Args: request (Request): The request to serialize path (Path): The path to write to + Raises: Exception: If another process has an active request file """ From 9fdac7e049816e400c148499760cc241daa32516 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 1 Sep 2022 18:58:46 +0000 Subject: [PATCH 26/43] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- apps/vscode/command_client/command_client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/vscode/command_client/command_client.py b/apps/vscode/command_client/command_client.py index 21219ba34a..5683c7555d 100644 --- a/apps/vscode/command_client/command_client.py +++ b/apps/vscode/command_client/command_client.py @@ -84,11 +84,11 @@ def to_dict(self): def write_request(request: Request, path: Path): """Converts the given request to json and writes it to the file, failing if the file already exists unless it is stale in which case it replaces it - + Args: request (Request): The request to serialize path (Path): The path to write to - + Raises: Exception: If another process has an active request file """ From 8cb444462fd580c8c03263f0bc3e71ee984d57cf Mon Sep 17 00:00:00 2001 From: johneffo Date: Thu, 1 Sep 2022 20:00:36 +0100 Subject: [PATCH 27/43] Remove string --- apps/vscode/command_client/command_client.py | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/vscode/command_client/command_client.py b/apps/vscode/command_client/command_client.py index 21219ba34a..26857d4218 100644 --- a/apps/vscode/command_client/command_client.py +++ b/apps/vscode/command_client/command_client.py @@ -126,6 +126,7 @@ def run_command( return_command_output: bool = False, ): """Runs a command, using command server if available + Args: command_id (str): The ID of the command to run. args: The arguments to the command. From 052240381a0bc4f8eb3058e89f0e12733eb27707 Mon Sep 17 00:00:00 2001 From: johneffo Date: Thu, 1 Sep 2022 20:01:09 +0100 Subject: [PATCH 28/43] Remove string --- apps/vscode/command_client/vscode.py | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/vscode/command_client/vscode.py b/apps/vscode/command_client/vscode.py index cfb8db6801..1a6e3d0b41 100644 --- a/apps/vscode/command_client/vscode.py +++ b/apps/vscode/command_client/vscode.py @@ -1,4 +1,3 @@ -import string from pickle import FALSE from typing import Any From 40d8ee0e970c404b837bfd88db77eef581663782 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 1 Sep 2022 19:01:23 +0000 Subject: [PATCH 29/43] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- apps/vscode/command_client/command_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/vscode/command_client/command_client.py b/apps/vscode/command_client/command_client.py index 6de1b3cbab..bab96c4f8b 100644 --- a/apps/vscode/command_client/command_client.py +++ b/apps/vscode/command_client/command_client.py @@ -126,7 +126,7 @@ def run_command( return_command_output: bool = False, ): """Runs a command, using command server if available - + Args: command_id (str): The ID of the command to run. args: The arguments to the command. From 4d7609f662f6a3836e529f3e6379fed343ba480b Mon Sep 17 00:00:00 2001 From: johneffo Date: Thu, 1 Sep 2022 20:06:39 +0100 Subject: [PATCH 30/43] Alter missing directory error msg --- apps/vscode/command_client/command_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/vscode/command_client/command_client.py b/apps/vscode/command_client/command_client.py index bab96c4f8b..21eb3486d2 100644 --- a/apps/vscode/command_client/command_client.py +++ b/apps/vscode/command_client/command_client.py @@ -150,7 +150,7 @@ def run_command( if args or return_command_output: raise Exception("Must use command-server extension for advanced commands") raise NoFileServerException( - "Communication dir not found; falling back to command palette" + "Communication directory not found" ) request_path = communication_dir_path / "request.json" From 054e81fa7738643a811c5ebba4f654fda0bc9b79 Mon Sep 17 00:00:00 2001 From: johneffo Date: Thu, 1 Sep 2022 20:11:42 +0100 Subject: [PATCH 31/43] Rename time out --- apps/vscode/command_client/command_client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/vscode/command_client/command_client.py b/apps/vscode/command_client/command_client.py index 21eb3486d2..deecf1b5c6 100644 --- a/apps/vscode/command_client/command_client.py +++ b/apps/vscode/command_client/command_client.py @@ -14,7 +14,7 @@ STALE_TIMEOUT_MS = 60_000 # The amount of time to wait for client application to perform a command, in seconds -VSCODE_COMMAND_TIMEOUT_SECONDS = 3.0 +RPC_COMMAND_TIMEOUT_SECONDS = 3.0 # When doing exponential back off waiting for client application to perform a command, how # long to sleep the first time @@ -258,7 +258,7 @@ def read_json_with_timeout(path: str) -> Any: Returns: Any: The json-decoded contents of the file """ - timeout_time = time.perf_counter() + VSCODE_COMMAND_TIMEOUT_SECONDS + timeout_time = time.perf_counter() + RPC_COMMAND_TIMEOUT_SECONDS sleep_time = MINIMUM_SLEEP_TIME_SECONDS while True: try: From c5eb3abfba8428dfa9f69fe40fa1b7ae33728eca Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 1 Sep 2022 19:13:38 +0000 Subject: [PATCH 32/43] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- apps/vscode/command_client/command_client.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/vscode/command_client/command_client.py b/apps/vscode/command_client/command_client.py index deecf1b5c6..7ad6799072 100644 --- a/apps/vscode/command_client/command_client.py +++ b/apps/vscode/command_client/command_client.py @@ -149,9 +149,7 @@ def run_command( if not communication_dir_path.exists(): if args or return_command_output: raise Exception("Must use command-server extension for advanced commands") - raise NoFileServerException( - "Communication directory not found" - ) + raise NoFileServerException("Communication directory not found") request_path = communication_dir_path / "request.json" response_path = communication_dir_path / "response.json" From a8a1409214645d57cbb6e8179eab4bf712be8e59 Mon Sep 17 00:00:00 2001 From: johneffo Date: Sun, 4 Sep 2022 11:23:55 +0100 Subject: [PATCH 33/43] Remove client from comment --- apps/vscode/command_client/command_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/vscode/command_client/command_client.py b/apps/vscode/command_client/command_client.py index 7ad6799072..4d99af74d3 100644 --- a/apps/vscode/command_client/command_client.py +++ b/apps/vscode/command_client/command_client.py @@ -13,7 +13,7 @@ # to remove it STALE_TIMEOUT_MS = 60_000 -# The amount of time to wait for client application to perform a command, in seconds +# The amount of time to wait for application to perform a command, in seconds RPC_COMMAND_TIMEOUT_SECONDS = 3.0 # When doing exponential back off waiting for client application to perform a command, how From 5b0d283245fa8bfb292e031e63b6ff190d0a0352 Mon Sep 17 00:00:00 2001 From: johneffo Date: Sun, 4 Sep 2022 11:28:08 +0100 Subject: [PATCH 34/43] Moved comment --- apps/vscode/command_client/vscode.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/vscode/command_client/vscode.py b/apps/vscode/command_client/vscode.py index 1a6e3d0b41..8eb2851ff2 100644 --- a/apps/vscode/command_client/vscode.py +++ b/apps/vscode/command_client/vscode.py @@ -33,8 +33,7 @@ def command_server_directory() -> str: return "vscode-command-server" -# These commands are shims, to provide backwards compatibility, they may be removed in the fuuture. -# Prefer the run_command... version in command_client. + @mod.action_class class Actions: def vscode(command_id: str): @@ -49,6 +48,8 @@ def vscode_and_wait(command_id: str): finish.""" command_server_or_client_fallback(command_id, True) +# These commands are shims, to provide backwards compatibility, they may be removed in the fuuture. +# Prefer the run_command... version in command_client. def vscode_with_plugin( command_id: str, arg1: Any = NotSet, From 347c9b36cc4e8a945d5113f20e0b1f83b31553d2 Mon Sep 17 00:00:00 2001 From: johneffo Date: Sun, 4 Sep 2022 11:29:30 +0100 Subject: [PATCH 35/43] Removed 'final' from comment --- apps/vscode/command_client/command_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/vscode/command_client/command_client.py b/apps/vscode/command_client/command_client.py index 4d99af74d3..6af3a28724 100644 --- a/apps/vscode/command_client/command_client.py +++ b/apps/vscode/command_client/command_client.py @@ -341,7 +341,7 @@ def run_rpc_command_get( ) def command_server_directory() -> str: - """Return the final directory of the command server""" + """Return the directory of the command server""" def trigger_command_server_command_execution(): """Issue keystroke to trigger command server to execute command that From 571abcec5302ce147ce7e2affed31d5ef552b0d5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 4 Sep 2022 10:34:50 +0000 Subject: [PATCH 36/43] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- apps/vscode/command_client/vscode.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/apps/vscode/command_client/vscode.py b/apps/vscode/command_client/vscode.py index 8eb2851ff2..ef6d3646d3 100644 --- a/apps/vscode/command_client/vscode.py +++ b/apps/vscode/command_client/vscode.py @@ -33,7 +33,6 @@ def command_server_directory() -> str: return "vscode-command-server" - @mod.action_class class Actions: def vscode(command_id: str): @@ -48,8 +47,8 @@ def vscode_and_wait(command_id: str): finish.""" command_server_or_client_fallback(command_id, True) -# These commands are shims, to provide backwards compatibility, they may be removed in the fuuture. -# Prefer the run_command... version in command_client. + # These commands are shims, to provide backwards compatibility, they may be removed in the fuuture. + # Prefer the run_command... version in command_client. def vscode_with_plugin( command_id: str, arg1: Any = NotSet, From b9719f5dd62efbd22745491f0a161fcc45577d02 Mon Sep 17 00:00:00 2001 From: johneffo Date: Sun, 4 Sep 2022 11:38:24 +0100 Subject: [PATCH 37/43] remove comment pre phrase from tag --- apps/vscode/command_client/command_client_tag.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/apps/vscode/command_client/command_client_tag.py b/apps/vscode/command_client/command_client_tag.py index ab055653b9..79c3fec2c4 100644 --- a/apps/vscode/command_client/command_client_tag.py +++ b/apps/vscode/command_client/command_client_tag.py @@ -13,9 +13,3 @@ def command_server_directory() -> str: """The dirctory which contains the files required for communication between the application and Talon. This is the only function which absolutely must be implemented for any application using the command-client.""" - def emit_pre_phrase_signal() -> bool: - """The command client can touch a signal file at the start of a phrase. If your - implementation does not require this, override emit_pre_phrase_signal to - return False.""" - # Unless we're in a command client app, we do nothing. - return False From 13e7d705dae625267aade73ef2f31a8ea5e69055 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 4 Sep 2022 10:38:26 +0000 Subject: [PATCH 38/43] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- apps/vscode/command_client/command_client_tag.py | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/vscode/command_client/command_client_tag.py b/apps/vscode/command_client/command_client_tag.py index 79c3fec2c4..3dd729ee28 100644 --- a/apps/vscode/command_client/command_client_tag.py +++ b/apps/vscode/command_client/command_client_tag.py @@ -12,4 +12,3 @@ class Actions: def command_server_directory() -> str: """The dirctory which contains the files required for communication between the application and Talon. This is the only function which absolutely must be implemented for any application using the command-client.""" - From f831999f9fbb306d42e78a5b4128edd24525102d Mon Sep 17 00:00:00 2001 From: johneffo Date: Sun, 4 Sep 2022 11:42:12 +0100 Subject: [PATCH 39/43] command server => rpc --- apps/vscode/command_client/command_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/vscode/command_client/command_client.py b/apps/vscode/command_client/command_client.py index 6af3a28724..e916bb4eb8 100644 --- a/apps/vscode/command_client/command_client.py +++ b/apps/vscode/command_client/command_client.py @@ -292,7 +292,7 @@ def run_rpc_command( arg4: Any = NotSet, arg5: Any = NotSet, ): - """Execute command via application command server.""" + """Execute command via RPC.""" run_command( command_id, arg1, From 29afd9a7fb6d09f28ebadd45e7dceea6824390dc Mon Sep 17 00:00:00 2001 From: Michael Arntzenius Date: Sun, 4 Sep 2022 22:37:47 +0100 Subject: [PATCH 40/43] fix emit_pre_phrase_signal --- apps/vscode/command_client/command_client.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/vscode/command_client/command_client.py b/apps/vscode/command_client/command_client.py index e916bb4eb8..99c04d8efd 100644 --- a/apps/vscode/command_client/command_client.py +++ b/apps/vscode/command_client/command_client.py @@ -348,8 +348,17 @@ def trigger_command_server_command_execution(): was written to the file. For internal use only""" actions.key("ctrl-shift-f17") + def emit_pre_phrase_signal() -> bool: + """ + If in an application supporting the command client, returns True + and touches a file to indicate that a phrase is beginning execution. + Otherwise does nothing and returns False. + """ + return False + def did_emit_pre_phrase_signal() -> bool: """Indicates whether the pre-phrase signal was emitted at the start of this phrase""" + # TODO: is this action actually used anywhere? it appears not to be. return did_emit_pre_phrase_signal @@ -367,9 +376,8 @@ def trigger_command_server_command_execution(): @ctx.action_class("user") class UserActions: - def emit_pre_phrase_signal() -> bool: + def emit_pre_phrase_signal(): get_signal_path("prePhrase").touch() - return True From 173ebefdd0560b5dddc8bcf2f213eb2c638191ea Mon Sep 17 00:00:00 2001 From: Michael Arntzenius Date: Sun, 4 Sep 2022 23:04:52 +0100 Subject: [PATCH 41/43] fix "tag: command_client" --- apps/vscode/command_client/command_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/vscode/command_client/command_client.py b/apps/vscode/command_client/command_client.py index 99c04d8efd..e8977f6733 100644 --- a/apps/vscode/command_client/command_client.py +++ b/apps/vscode/command_client/command_client.py @@ -31,7 +31,7 @@ linux_ctx = Context() ctx.matches = r""" -tag: command_client +tag: user.command_client """ mac_ctx.matches = r""" os: mac From d7e89b18d745463c0efa28efc9eda3af519cf976 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Tue, 6 Sep 2022 15:43:55 +0100 Subject: [PATCH 42/43] Fixes --- apps/vscode/command_client/command_client.py | 11 ++++++----- apps/vscode/command_client/command_client_tag.py | 12 +++++++++--- apps/vscode/command_client/visual_studio.py | 2 +- apps/vscode/command_client/vscode.py | 6 +++--- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/apps/vscode/command_client/command_client.py b/apps/vscode/command_client/command_client.py index e8977f6733..299a7258f7 100644 --- a/apps/vscode/command_client/command_client.py +++ b/apps/vscode/command_client/command_client.py @@ -16,7 +16,7 @@ # The amount of time to wait for application to perform a command, in seconds RPC_COMMAND_TIMEOUT_SECONDS = 3.0 -# When doing exponential back off waiting for client application to perform a command, how +# When doing exponential back off waiting for application to perform a command, how # long to sleep the first time MINIMUM_SLEEP_TIME_SECONDS = 0.0005 @@ -175,9 +175,9 @@ def run_command( print("WARNING: Found old response file") robust_unlink(response_path) - # Then, perform keystroke telling client application to execute the command in the - # request file. Because only the active client application instance will accept - # keypresses, we can be sure that the active client application instance will be the + # Then, perform keystroke telling application to execute the command in the + # request file. Because only the active application instance will accept + # keypresses, we can be sure that the active application instance will be the # one to execute the command. actions.user.trigger_command_server_command_execution() @@ -358,7 +358,7 @@ def emit_pre_phrase_signal() -> bool: def did_emit_pre_phrase_signal() -> bool: """Indicates whether the pre-phrase signal was emitted at the start of this phrase""" - # TODO: is this action actually used anywhere? it appears not to be. + # NB: This action is used by cursorless; please don't delete it :) return did_emit_pre_phrase_signal @@ -409,6 +409,7 @@ def get_signal_path(name: str) -> Path: def pre_phrase(_: Any): try: global did_emit_pre_phrase_signal + did_emit_pre_phrase_signal = actions.user.emit_pre_phrase_signal() except MissingCommunicationDir: pass diff --git a/apps/vscode/command_client/command_client_tag.py b/apps/vscode/command_client/command_client_tag.py index 3dd729ee28..28e6d533f0 100644 --- a/apps/vscode/command_client/command_client_tag.py +++ b/apps/vscode/command_client/command_client_tag.py @@ -3,12 +3,18 @@ mod = Module() mod.tag( - "command_client", desc="For applications which implement File based RPC with Talon" + "command_client", desc="For applications which implement file-based RPC with Talon" ) @mod.action_class class Actions: def command_server_directory() -> str: - """The dirctory which contains the files required for communication between the application and Talon. - This is the only function which absolutely must be implemented for any application using the command-client.""" + """ + The dirctory which contains the files required for communication between + the application and Talon. This is the only function which absolutely + must be implemented for any application using the command-client. Each + application that supports file-based RPC should use its own directory + name. Note that this action should only return a name; the parent + directory is determined by the core command client code. + """ diff --git a/apps/vscode/command_client/visual_studio.py b/apps/vscode/command_client/visual_studio.py index 4fff1acdf5..91e008984d 100644 --- a/apps/vscode/command_client/visual_studio.py +++ b/apps/vscode/command_client/visual_studio.py @@ -1,4 +1,4 @@ -from talon import Context, actions +from talon import Context ctx = Context() diff --git a/apps/vscode/command_client/vscode.py b/apps/vscode/command_client/vscode.py index ef6d3646d3..85b7f63e36 100644 --- a/apps/vscode/command_client/vscode.py +++ b/apps/vscode/command_client/vscode.py @@ -15,7 +15,7 @@ def command_server_or_client_fallback(command_id: str, wait: bool): - """Execute command via command server and us command pallete if directory not present.""" + """Execute command via command server, falling back to command palette if directory not present.""" try: run_command(command_id, wait_for_finish=wait) except NoFileServerException: @@ -23,7 +23,7 @@ def command_server_or_client_fallback(command_id: str, wait: bool): actions.user.paste(command_id) actions.key("enter") print( - "Command issues via command palette for better performance install the VSCode extension for Talon" + "Command server directory not found; falling back to command palette. For better performance, install the VSCode extension for Talon: https://marketplace.visualstudio.com/items?itemName=pokey.talon" ) @@ -58,7 +58,7 @@ def vscode_with_plugin( arg5: Any = NotSet, ): """Execute command via vscode command server.""" - actions.user.run_command( + actions.user.run_rpc_command( command_id, arg1, arg2, From 3d1e01613da066798866c5a4504d6d92a241c4ac Mon Sep 17 00:00:00 2001 From: Michael Arntzenius Date: Tue, 6 Sep 2022 15:52:02 +0100 Subject: [PATCH 43/43] Update apps/vscode/command_client/visual_studio.py Co-authored-by: Pokey Rule <755842+pokey@users.noreply.github.com> --- apps/vscode/command_client/visual_studio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/vscode/command_client/visual_studio.py b/apps/vscode/command_client/visual_studio.py index 91e008984d..f614d3c34e 100644 --- a/apps/vscode/command_client/visual_studio.py +++ b/apps/vscode/command_client/visual_studio.py @@ -12,4 +12,4 @@ @ctx.action_class("user") class VisualStudioActions: def command_server_directory() -> str: - return "visual-studio-commandServer" + return "visual-studio-command-server"