Commit Graph

8 Commits

Author SHA1 Message Date
Tomoki Imai dba0a4c990
Fix the wrong Content-Length in python-server.py for non-ascii characters. (#24480)
Resolves: https://github.com/microsoft/vscode-python/issues/24479

`python-server.py` currently uses `sys.stdin.read` for reading the
input, and it receives the length in `str` (utf-8 string).
ref: https://docs.python.org/3/library/sys.html

On the other "Content-Length" is the size in **bytes**, therefore we
should not pass `content_length` to `sys.stdin.read`. For example,
`print("こんにちは世界")`'s length is 16 in str, but 30 in bytes.

```
>>> len('print("こんにちは世界")')
16
>>> len('print("こんにちは世界")'.encode())
30
```

This PR have two changes.
1. Replace `sys.stdin.read(content_length)` with
`sys.stdin.buffer.read(content_length).decode()`.
2. Make `_send_message` calculate "Content-Length" from bytes, not str.

By these changes, original issue
https://github.com/microsoft/vscode-python/issues/24479 can be resolved.


![image](https://github.com/user-attachments/assets/20e72a26-d4ad-4e16-9c5b-ed41055c95d9)
2024-11-26 16:00:54 +00:00
Karthik Nadig 5cec0e0461
Revert "ruff 0.8.0 fixes" (#24489)
Reverts microsoft/vscode-python#24488
2024-11-25 21:00:10 +00:00
Joar Wandborg 98fea6ec58
ruff 0.8.0 fixes (#24488)
- Ruff 0.8.0 was released on November 22nd
([changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md#080))
- [Lint action installs latest version of
`ruff`](9059aeae65/.github/actions/lint/action.yml (L46))
2024-11-25 17:02:10 +00:00
T-256 97b46109cc
Make `python_server.py` compatible to Python 3.7 (#24252)
```
2024-10-05 15:12:00.813 [error]   File "c:\Users\User\.vscode\extensions\ms-python.python-2024.16.0-win32-x64\python_files\python_server.py", line 162
    while line := STDIN.readline().strip():
                ^
SyntaxError: invalid syntax

2024-10-05 15:12:00.816 [error] Python server exited with code 1
2024-10-05 15:14:46.427 [error] Error getting response from REPL server: [k [Error]: Connection is closed.
	at pe (c:\Users\User\.vscode\extensions\ms-python.python-2024.16.0-win32-x64\out\client\extension.js:2:2053423)
	at Object.sendRequest (c:\Users\User\.vscode\extensions\ms-python.python-2024.16.0-win32-x64\out\client\extension.js:2:2055781)
	at g.executeCode (c:\Users\User\.vscode\extensions\ms-python.python-2024.16.0-win32-x64\out\client\extension.js:2:799948)
	at g.execute (c:\Users\User\.vscode\extensions\ms-python.python-2024.16.0-win32-x64\out\client\extension.js:2:799770)
	at u.value (c:\Users\User\.vscode\extensions\ms-python.python-2024.16.0-win32-x64\out\client\extension.js:2:829806)
	at i.executeHandler (c:\Users\User\.vscode\extensions\ms-python.python-2024.16.0-win32-x64\out\client\extension.js:2:805190)
	at bb.$executeCells (file:///c:/Users/User/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:155:24084)
	at Zb.S (file:///c:/Users/User/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:31:113896)
	at Zb.Q (file:///c:/Users/User/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:31:113676)
	at Zb.M (file:///c:/Users/User/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:31:112765)
	at Zb.L (file:///c:/Users/User/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:31:111870)
	at gh.value (file:///c:/Users/User/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:31:110667)
	at T.B (file:///c:/Users/User/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:29:732)
	at T.fire (file:///c:/Users/User/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:29:950)
	at no.fire (file:///c:/Users/User/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:31:9399)
	at gh.value (file:///c:/Users/User/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:174:13273)
	at T.B (file:///c:/Users/User/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:29:732)
	at T.fire (file:///c:/Users/User/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:29:950)
	at no.fire (file:///c:/Users/User/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:31:9399)
	at MessagePortMain.<anonymous> (file:///c:/Users/User/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:174:11562)
	at MessagePortMain.emit (node:events:519:28)
	at MessagePortMain._internalPort.emit (node:electron/js2c/utility_init:2:2619)] {
  code: 1
}
```
2024-10-14 10:42:24 -07:00
Anthony Kim a60f228ab7
Correctly display native REPL execution status (#23797)
Resolves: https://github.com/microsoft/vscode-python/issues/23739
2024-07-18 19:45:13 -04:00
Brett Cannon 462b9bf2cb
Enable explicit Ruff check rules (#23741)
Co-authored-by: Rafał <23004737+rafrafek@users.noreply.github.com>
2024-07-09 13:01:15 -07:00
Anthony Kim 75cc52b0d9
Allow execute on enter and Intellisense for native REPL with notebook UI (#23442)
"Smartly" allow execute on enter for the
https://github.com/microsoft/vscode-python/pull/23235 experiment.
User should be able to execute when they press enter on text input box
of interactive window trigger from Python extension, whereas we would
"wait" and allow insertion of new line after detecting user's Python
command is not complete.

When the user finally types enter again on a blank line, we should just
proceed to execute whatever code, regardless of whether it is
complete/valid or not to replicate Python's original interactive REPL
behavior.

Basically creating Python command and registering that for keybinding of
'Enter'.
This would conditionally call interactive.execute which would then
eventually call our execute handler contributed from Python n
extension's REPL controller, or go ahead and insert,pass in Enter to the
text input box to allow user to type "complete" code.



This PR only intends to implement/add changes regarding execute on enter
logic, adding Intellisense support, and also adding things into
disposables so they can be properly disposed. Trying to also add setting
to allow toggling on/off to send Python command to Terminal or IW REPL
if the user is in experiment.


Handling of interrupt for windows should be on separate PR.
Test will be added later as separate PR.

---------

Co-authored-by: Courtney Webster <60238438+cwebster-99@users.noreply.github.com>
Co-authored-by: Karthik Nadig <kanadig@microsoft.com>
2024-05-24 00:01:26 -07:00
Anthony Kim 6997f7b167
Add Interactive REPL Experiment (#23235)
Allow users to use Interactive Window UI with Python custom REPL
controller instead of iPykernel.
Closes #23175
Closes #23174 
Closes https://github.com/microsoft/vscode-python/issues/23029
Majority of: #23332 

Context menu under Python for running Python REPL code using IW UI
should only appear when user's ```pythonRunREPL``` experiment is
enabled.
2024-05-15 19:09:14 -07:00