Preexec hook for REPL
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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:
Command navigation (cmd/ctrl+up/down):
Run recent (ctrl+alt+r):
To give an example of what's possible with shell integration, here's our experimental VS Code-native PowerShell intellisense:
And multi-line sticky scroll:
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:
Compare this to PowerShell which positions them correctly:
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, den Ausführungspfad der Python REPL und das Beispiel zur Shell-Integration in python_files/pythonrc.py aus der verknüpften VS Code Python extension zu überprüfen. Lies die verknüpften PRs gh-144724 und gh-157241, um die bestehende Arbeit und die getroffenen Entscheidungen zu verstehen. Als abgeschlossen gilt die Aufgabe, wenn ein dokumentierter Pre-Execution-Hook für REPL-Integrationen verfügbar ist und sein Verhalten durch relevante Tests abgedeckt wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- cli
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100