Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"python.poetryPath.description": "Path to the poetry executable.",
"python.pixiToolPath.description": "Path to the pixi executable.",
"python.EnableREPLSmartSend.description": "Toggle Smart Send for the Python REPL. Smart Send enables sending the smallest runnable block of code to the REPL on Shift+Enter and moves the cursor accordingly.",
"python.REPL.sendToNativeREPL.description": "Toggle to send code to Python REPL instead of the terminal on execution. Turning this on will change the behavior for both Smart Send and Run Selection/Line in the Context Menu.",
"python.REPL.sendToNativeREPL.description": "Toggle to send code to [Python REPL](https://aka.ms/python-native-repl) instead of the terminal on execution. Turning this on will change the behavior for both Smart Send and Run Selection/Line in the Context Menu.",
"python.REPL.provideVariables.description": "Toggle to provide variables for the REPL variable view for the native REPL.",
"python.tensorBoard.logDirectory.description": "Set this setting to your preferred TensorBoard log directory to skip log directory prompt when starting TensorBoard.",
"python.tensorBoard.logDirectory.markdownDeprecationMessage": "Tensorboard support has been moved to the extension [Tensorboard extension](https://marketplace.visualstudio.com/items?itemName=ms-toolsai.tensorboard). Instead use the setting `tensorBoard.logDirectory`.",
Expand Down
49 changes: 34 additions & 15 deletions python_files/pythonrc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import platform
import sys
from enum import Enum

if sys.platform != "win32":
import readline
Expand All @@ -8,6 +9,20 @@
is_wsl = "microsoft-standard-WSL" in platform.release()


class ShellIntegrationSequence(str, Enum):
SOH = "\001"
STX = "\002"
COMMAND_EXECUTED = "\x1b]633;C\x07"
COMMAND_LINE = "\x1b]633;E;"
COMMAND_FINISHED = "\x1b]633;D;"
PROMPT_STARTED = "\x1b]633;A\x07"
COMMAND_START = "\x1b]633;B\x07"
TERMINATOR = "\x07"

def __str__(self):
return self.value


class REPLHooks:
def __init__(self):
self.global_exit = None
Expand Down Expand Up @@ -53,26 +68,30 @@ def __str__(self):
# For non-windows allow recent_command history.
if sys.platform != "win32":
result = "{soh}{command_executed}{command_line}{command_finished}{prompt_started}{stx}{prompt}{soh}{command_start}{stx}".format(
soh="\001",
stx="\002",
command_executed="\x1b]633;C\x07",
command_line="\x1b]633;E;" + str(get_last_command()) + "\x07",
command_finished="\x1b]633;D;" + str(exit_code) + "\x07",
prompt_started="\x1b]633;A\x07",
soh=ShellIntegrationSequence.SOH,
stx=ShellIntegrationSequence.STX,
command_executed=ShellIntegrationSequence.COMMAND_EXECUTED,
command_line=ShellIntegrationSequence.COMMAND_LINE
+ str(get_last_command())
+ ShellIntegrationSequence.TERMINATOR,
command_finished=ShellIntegrationSequence.COMMAND_FINISHED
+ str(exit_code)
+ ShellIntegrationSequence.TERMINATOR,
prompt_started=ShellIntegrationSequence.PROMPT_STARTED,
prompt=original_ps1,
command_start="\x1b]633;B\x07",
command_start=ShellIntegrationSequence.COMMAND_START,
)
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",
command_finished=ShellIntegrationSequence.COMMAND_FINISHED
+ str(exit_code)
+ ShellIntegrationSequence.TERMINATOR,
prompt_started=ShellIntegrationSequence.PROMPT_STARTED,
prompt=original_ps1,
command_start="\x1b]633;B\x07",
command_executed="\x1b]633;C\x07",
command_start=ShellIntegrationSequence.COMMAND_START,
command_executed=ShellIntegrationSequence.COMMAND_EXECUTED,
)

# 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

def __repr__(self):
Expand All @@ -83,6 +102,6 @@ def __repr__(self):
sys.ps1 = PS1()

if sys.platform == "darwin":
print("Cmd click to launch VS Code Native REPL")
print("Cmd click to launch VS Code Native REPL (https://aka.ms/python-native-repl)")
else:
print("Ctrl click to launch VS Code Native REPL")
print("Ctrl click to launch VS Code Native REPL (https://aka.ms/python-native-repl)")
8 changes: 6 additions & 2 deletions python_files/tests/test_shell_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ def test_print_statement_darwin(monkeypatch):
with monkeypatch.context() as m:
m.setattr("builtins.print", Mock())
importlib.reload(sys.modules["pythonrc"])
print.assert_any_call("Cmd click to launch VS Code Native REPL")
print.assert_any_call(
"Cmd click to launch VS Code Native REPL (https://aka.ms/python-native-repl)"
)


if sys.platform == "win32":
Expand All @@ -80,4 +82,6 @@ def test_print_statement_non_darwin(monkeypatch):
with monkeypatch.context() as m:
m.setattr("builtins.print", Mock())
importlib.reload(sys.modules["pythonrc"])
print.assert_any_call("Ctrl click to launch VS Code Native REPL")
print.assert_any_call(
"Ctrl click to launch VS Code Native REPL (https://aka.ms/python-native-repl)"
)
11 changes: 4 additions & 7 deletions src/client/terminals/pythonStartupLinkProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@ export class CustomTerminalLinkProvider implements TerminalLinkProvider<CustomTe
_token: CancellationToken,
): ProviderResult<CustomTerminalLink[]> {
const links: CustomTerminalLink[] = [];
let expectedNativeLink;

if (process.platform === 'darwin') {
expectedNativeLink = 'Cmd click to launch VS Code Native REPL';
} else {
expectedNativeLink = 'Ctrl click to launch VS Code Native REPL';
}
let expectedNativeLink =
process.platform === 'darwin'
? 'Cmd click to launch VS Code Native REPL'
: 'Ctrl click to launch VS Code Native REPL';

if (context.line.includes(expectedNativeLink)) {
links.push({
Expand Down
6 changes: 4 additions & 2 deletions src/test/terminals/shellIntegration/pythonStartup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => {
test('Mac - Verify provideTerminalLinks returns links when context.line contains expectedNativeLink', () => {
const provider = new CustomTerminalLinkProvider();
const context: TerminalLinkContext = {
line: 'Some random string with Cmd click to launch VS Code Native REPL',
line:
'Some random string with Cmd click to launch VS Code Native REPL (https://aka.ms/python-native-repl)',
terminal: {} as Terminal,
};
const token: CancellationToken = {
Expand Down Expand Up @@ -224,7 +225,8 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => {
test('Windows/Linux - Verify provideTerminalLinks returns links when context.line contains expectedNativeLink', () => {
const provider = new CustomTerminalLinkProvider();
const context: TerminalLinkContext = {
line: 'Some random string with Ctrl click to launch VS Code Native REPL',
line:
'Some random string with Ctrl click to launch VS Code Native REPL (https://aka.ms/python-native-repl)',
terminal: {} as Terminal,
};
const token: CancellationToken = {
Expand Down
Loading