python / python/cpython

Preexec hook for REPL

Đang mở
#122,622 4 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

topic-repl type-feature
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

Feature or enhancement

Proposal:

Background

In VS Code we override PS1 to enable shell integration, this currently gives VS Code understanding of where the commands are and what they are. This provides a few features:

Command decorations with visualization of exit/error status:

image

Command navigation (cmd/ctrl+up/down):

image

Run recent (ctrl+alt+r):

image

To give an example of what's possible with shell integration, here's our experimental VS Code-native PowerShell intellisense:

image

And multi-line sticky scroll:

image

Request

Something we needed to work around for Python was the lack of a pre-execution hook, we would normally print \x1b[633;C\a at the end of a command just before it's run such that VS Code knows where that marker is. Currently we have to stick that at the start of the command input though which can degrade the experience, especially when VS Code attempts to figure out that command has been run manually.

To visualization of the problem, see the A, B, C, D markers in our python REPL:

image

Compare this to PowerShell which positions them correctly:

image

Shell integration script included in VS Code's python extension: https://github.com/microsoft/vscode-python/blob/main/python_files/pythonrc.py

I'm not a Python dev so I'm not sure what such an API would look like, but we essentially need a hook to run arbitrary code immediately before the REPL runs the command, something like this:

class MyPreexec:
    def __str__(self):
      return "preexec"

sys.preexec = MyPreexec()

cc @anthonykim1 @brettcannon

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs
  • gh-144724
  • gh-157241

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách xem xét đường dẫn thực thi Python REPL và ví dụ tích hợp shell trong python_files/pythonrc.py của tiện ích mở rộng Python cho VS Code được liên kết. Đọc các PR được liên kết gh-144724 và gh-157241 để hiểu công việc hiện có và các quyết định đã đưa ra. Được xem là hoàn thành khi có một pre-execution hook được ghi rõ tài liệu cho các tích hợp REPL và hành vi của nó được bao phủ bởi các test liên quan.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
cli
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.