From dad848053bc78b295882dfdb54a52743e5188cc6 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 5 Jan 2024 14:07:19 -0500 Subject: [PATCH 01/10] allow run recent command --- pythonFiles/pythonrc.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/pythonFiles/pythonrc.py b/pythonFiles/pythonrc.py index 616a59e21203..40a8d3854c55 100644 --- a/pythonFiles/pythonrc.py +++ b/pythonFiles/pythonrc.py @@ -1,4 +1,5 @@ import sys +import readline original_ps1 = ">>> " @@ -25,6 +26,12 @@ def my_excepthook(self, type, value, traceback): self.original_excepthook(type, value, traceback) +def get_last_command(): + # Get the last history item + last_command = readline.get_history_item(readline.get_current_history_length()) + return last_command + + class ps1: hooks = repl_hooks() sys.excepthook = hooks.my_excepthook @@ -39,14 +46,15 @@ def __str__(self): exit_code = 0 # Guide following official VS Code doc for shell integration sequence: - # result = "{command_finished}{prompt_started}{prompt}{command_start}{command_executed}".format( - # command_finished="\x1b]633;D;" + str(exit_code) + "\x07", - # prompt_started="\x1b]633;A\x07", - # prompt=original_ps1, - # command_start="\x1b]633;B\x07", - # command_executed="\x1b]633;C\x07", - # ) - result = f"{chr(27)}]633;D;{exit_code}{chr(7)}{chr(27)}]633;A{chr(7)}{original_ps1}{chr(27)}]633;B{chr(7)}{chr(27)}]633;C{chr(7)}" + result = "{command_finished}{prompt_started}{prompt}{command_start}{command_executed}{command_line}".format( + command_finished="\x1b]633;D;" + str(exit_code) + "\x07", + prompt_started="\x1b]633;A\x07", + prompt=original_ps1, + command_start="\x1b]633;B\x07", + command_executed="\x1b]633;C\x07", + command_line="\x1b]633;E;" + str(get_last_command()) + "\x07", + ) + # result = f"{chr(27)}]633;D;{exit_code}{chr(7)}{chr(27)}]633;A{chr(7)}{original_ps1}{chr(27)}]633;B{chr(7)}{chr(27)}]633;C{chr(7)}" return result From a090bae42e8445d4d8e579b23cc67f915987d830 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 9 Jan 2024 11:57:59 -0800 Subject: [PATCH 02/10] fix si test --- pythonFiles/tests/test_shell_integration.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pythonFiles/tests/test_shell_integration.py b/pythonFiles/tests/test_shell_integration.py index 06bb42499c58..9a23f4540155 100644 --- a/pythonFiles/tests/test_shell_integration.py +++ b/pythonFiles/tests/test_shell_integration.py @@ -10,7 +10,10 @@ def test_decoration_success(): ps1.hooks.failure_flag = False result = str(ps1) - assert result == "\x1b]633;D;0\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07" + assert ( + result + == "\x1b]633;D;0\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07\x1b]633;E;None\x07" + ) def test_decoration_failure(): @@ -20,7 +23,10 @@ def test_decoration_failure(): ps1.hooks.failure_flag = True result = str(ps1) - assert result == "\x1b]633;D;1\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07" + assert ( + result + == "\x1b]633;D;1\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07\x1b]633;E;None\x07" + ) def test_displayhook_call(): From 02d4e40a600b2f6bb0033b1a449d72600c96b432 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 9 Jan 2024 13:14:28 -0800 Subject: [PATCH 03/10] try fixing module error --- pythonFiles/pythonrc.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pythonFiles/pythonrc.py b/pythonFiles/pythonrc.py index 40a8d3854c55..92290e1bf1a6 100644 --- a/pythonFiles/pythonrc.py +++ b/pythonFiles/pythonrc.py @@ -1,4 +1,8 @@ import sys + +import os + +sys.path.insert(0, os.getcwd()) import readline original_ps1 = ">>> " From cabe3fdffe794d4c4beed036f0cc9f9ac4d145dc Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 9 Jan 2024 15:31:39 -0800 Subject: [PATCH 04/10] attempt by adding ext_root --- pythonFiles/pythonrc.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pythonFiles/pythonrc.py b/pythonFiles/pythonrc.py index 92290e1bf1a6..beefea34c5d0 100644 --- a/pythonFiles/pythonrc.py +++ b/pythonFiles/pythonrc.py @@ -2,7 +2,9 @@ import os -sys.path.insert(0, os.getcwd()) +# sys.path.insert(0, os.getcwd()) +EXTENSION_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +os.path.join(EXTENSION_ROOT, "pythonFiles", "lib", "python") import readline original_ps1 = ">>> " From daa9277e0ad7081d7d01e4113e62f2b0f68cc599 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 9 Jan 2024 16:19:26 -0800 Subject: [PATCH 05/10] try pyreadline3 --- pythonFiles/pythonrc.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pythonFiles/pythonrc.py b/pythonFiles/pythonrc.py index beefea34c5d0..69ad79eb5539 100644 --- a/pythonFiles/pythonrc.py +++ b/pythonFiles/pythonrc.py @@ -3,9 +3,13 @@ import os # sys.path.insert(0, os.getcwd()) -EXTENSION_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -os.path.join(EXTENSION_ROOT, "pythonFiles", "lib", "python") -import readline +# EXTENSION_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +# os.path.join(EXTENSION_ROOT, "pythonFiles", "lib", "python") +# import readline + +from pyreadline3 import Readline + +readline = Readline() original_ps1 = ">>> " From 016b285711e0ae1f15ad6ba94e066c9d0248ecec Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 10 Jan 2024 09:10:04 -0800 Subject: [PATCH 06/10] revert back to readline --- pythonFiles/pythonrc.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pythonFiles/pythonrc.py b/pythonFiles/pythonrc.py index 69ad79eb5539..180d498e5082 100644 --- a/pythonFiles/pythonrc.py +++ b/pythonFiles/pythonrc.py @@ -1,15 +1,16 @@ import sys -import os +# import os # sys.path.insert(0, os.getcwd()) # EXTENSION_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # os.path.join(EXTENSION_ROOT, "pythonFiles", "lib", "python") -# import readline +import readline -from pyreadline3 import Readline +# from pyreadline3 import Readline -readline = Readline() + +# readline = Readline() original_ps1 = ">>> " From 29a03fe2ed4a3c23c9afc9e4d8f204cd7e7bc86d Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 18 Jan 2024 20:29:42 -0800 Subject: [PATCH 07/10] allow recent history for non windows --- pythonFiles/pythonrc.py | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/pythonFiles/pythonrc.py b/pythonFiles/pythonrc.py index 180d498e5082..17679972ab04 100644 --- a/pythonFiles/pythonrc.py +++ b/pythonFiles/pythonrc.py @@ -5,7 +5,8 @@ # sys.path.insert(0, os.getcwd()) # EXTENSION_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # os.path.join(EXTENSION_ROOT, "pythonFiles", "lib", "python") -import readline +if sys.platform != "win32": + import readline # from pyreadline3 import Readline @@ -39,7 +40,11 @@ def my_excepthook(self, type, value, traceback): def get_last_command(): # Get the last history item - last_command = readline.get_history_item(readline.get_current_history_length()) + last_command = "" + if sys.platform != "win32": + last_command = readline.get_history_item(readline.get_current_history_length()) + else: + last_command = "" return last_command @@ -57,14 +62,26 @@ def __str__(self): exit_code = 0 # Guide following official VS Code doc for shell integration sequence: - result = "{command_finished}{prompt_started}{prompt}{command_start}{command_executed}{command_line}".format( - command_finished="\x1b]633;D;" + str(exit_code) + "\x07", - prompt_started="\x1b]633;A\x07", - prompt=original_ps1, - command_start="\x1b]633;B\x07", - command_executed="\x1b]633;C\x07", - command_line="\x1b]633;E;" + str(get_last_command()) + "\x07", - ) + result = "" + # For non-windows allow recent_command history. + if sys.platform != "win32": + result = "{command_finished}{prompt_started}{prompt}{command_start}{command_executed}{command_line}".format( + command_finished="\x1b]633;D;" + str(exit_code) + "\x07", + prompt_started="\x1b]633;A\x07", + prompt=original_ps1, + command_start="\x1b]633;B\x07", + command_executed="\x1b]633;C\x07", + command_line="\x1b]633;E;" + str(get_last_command()) + "\x07", + ) + else: + result = "{command_finished}{prompt_started}{prompt}{command_start}{command_executed}".format( + command_finished="\x1b]633;D;" + str(exit_code) + "\x07", + prompt_started="\x1b]633;A\x07", + prompt=original_ps1, + command_start="\x1b]633;B\x07", + command_executed="\x1b]633;C\x07", + ) + # result = f"{chr(27)}]633;D;{exit_code}{chr(7)}{chr(27)}]633;A{chr(7)}{original_ps1}{chr(27)}]633;B{chr(7)}{chr(27)}]633;C{chr(7)}" return result From ff5c4cb221f8ab1a250c26a5d0af4b95fd20301a Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 18 Jan 2024 22:00:34 -0800 Subject: [PATCH 08/10] only run for windows --- pythonFiles/tests/test_shell_integration.py | 25 ++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/pythonFiles/tests/test_shell_integration.py b/pythonFiles/tests/test_shell_integration.py index 9a23f4540155..896df416eced 100644 --- a/pythonFiles/tests/test_shell_integration.py +++ b/pythonFiles/tests/test_shell_integration.py @@ -1,6 +1,6 @@ import importlib +import sys from unittest.mock import Mock - import pythonrc @@ -10,10 +10,13 @@ def test_decoration_success(): ps1.hooks.failure_flag = False result = str(ps1) - assert ( - result - == "\x1b]633;D;0\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07\x1b]633;E;None\x07" - ) + if sys.platform != "win32": + assert ( + result + == "\x1b]633;D;0\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07\x1b]633;E;None\x07" + ) + else: + pass def test_decoration_failure(): @@ -22,11 +25,13 @@ def test_decoration_failure(): ps1.hooks.failure_flag = True result = str(ps1) - - assert ( - result - == "\x1b]633;D;1\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07\x1b]633;E;None\x07" - ) + if sys.platform != "win32": + assert ( + result + == "\x1b]633;D;1\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07\x1b]633;E;None\x07" + ) + else: + pass def test_displayhook_call(): From 40fc3906518b01da37c02c88feef10952279ba93 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 19 Jan 2024 13:28:32 -0800 Subject: [PATCH 09/10] update test-electron to latest --- package-lock.json | 14 +++++++------- package.json | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index a6a9cf40a760..fa163b5857b6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -65,7 +65,7 @@ "@types/xml2js": "^0.4.2", "@typescript-eslint/eslint-plugin": "^3.7.0", "@typescript-eslint/parser": "^3.7.0", - "@vscode/test-electron": "^2.3.4", + "@vscode/test-electron": "^2.3.8", "@vscode/vsce": "^2.18.0", "bent": "^7.3.12", "chai": "^4.1.2", @@ -1875,9 +1875,9 @@ } }, "node_modules/@vscode/test-electron": { - "version": "2.3.4", - "resolved": "https://registry.npmjs.org/@vscode/test-electron/-/test-electron-2.3.4.tgz", - "integrity": "sha512-eWzIqXMhvlcoXfEFNWrVu/yYT5w6De+WZXR/bafUQhAp8+8GkQo95Oe14phwiRUPv8L+geAKl/QM2+PoT3YW3g==", + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/@vscode/test-electron/-/test-electron-2.3.8.tgz", + "integrity": "sha512-b4aZZsBKtMGdDljAsOPObnAi7+VWIaYl3ylCz1jTs+oV6BZ4TNHcVNC3xUn0azPeszBmwSBDQYfFESIaUQnrOg==", "dev": true, "dependencies": { "http-proxy-agent": "^4.0.1", @@ -16764,9 +16764,9 @@ } }, "@vscode/test-electron": { - "version": "2.3.4", - "resolved": "https://registry.npmjs.org/@vscode/test-electron/-/test-electron-2.3.4.tgz", - "integrity": "sha512-eWzIqXMhvlcoXfEFNWrVu/yYT5w6De+WZXR/bafUQhAp8+8GkQo95Oe14phwiRUPv8L+geAKl/QM2+PoT3YW3g==", + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/@vscode/test-electron/-/test-electron-2.3.8.tgz", + "integrity": "sha512-b4aZZsBKtMGdDljAsOPObnAi7+VWIaYl3ylCz1jTs+oV6BZ4TNHcVNC3xUn0azPeszBmwSBDQYfFESIaUQnrOg==", "dev": true, "requires": { "http-proxy-agent": "^4.0.1", diff --git a/package.json b/package.json index 1976a7076f7e..9552cff8c9c1 100644 --- a/package.json +++ b/package.json @@ -1619,7 +1619,7 @@ "@types/xml2js": "^0.4.2", "@typescript-eslint/eslint-plugin": "^3.7.0", "@typescript-eslint/parser": "^3.7.0", - "@vscode/test-electron": "^2.3.4", + "@vscode/test-electron": "^2.3.8", "@vscode/vsce": "^2.18.0", "bent": "^7.3.12", "chai": "^4.1.2", @@ -1661,13 +1661,13 @@ "typescript": "4.5.5", "uuid": "^8.3.2", "webpack": "^5.76.0", - "worker-loader": "^3.0.8", "webpack-bundle-analyzer": "^4.5.0", "webpack-cli": "^4.9.2", "webpack-fix-default-import-plugin": "^1.0.3", "webpack-merge": "^5.8.0", "webpack-node-externals": "^3.0.0", "webpack-require-from": "^1.8.6", + "worker-loader": "^3.0.8", "yargs": "^15.3.1" } } From f0113e915bba689b7edb1ce912ba1e3b9ee651b9 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 19 Jan 2024 13:40:40 -0800 Subject: [PATCH 10/10] remove comment --- pythonFiles/pythonrc.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/pythonFiles/pythonrc.py b/pythonFiles/pythonrc.py index 17679972ab04..1cb72b0ec344 100644 --- a/pythonFiles/pythonrc.py +++ b/pythonFiles/pythonrc.py @@ -1,18 +1,8 @@ import sys -# import os - -# sys.path.insert(0, os.getcwd()) -# EXTENSION_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -# os.path.join(EXTENSION_ROOT, "pythonFiles", "lib", "python") if sys.platform != "win32": import readline -# from pyreadline3 import Readline - - -# readline = Readline() - original_ps1 = ">>> " @@ -43,8 +33,7 @@ def get_last_command(): last_command = "" if sys.platform != "win32": last_command = readline.get_history_item(readline.get_current_history_length()) - else: - last_command = "" + return last_command