Preexec hook for REPL
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 35.9k
- Métriques de merge des PR
- Métriques de PR en attente
Description
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
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par examiner le chemin d’exécution de Python REPL et l’exemple d’intégration du shell dans python_files/pythonrc.py de l’extension Python VS Code liée. Lisez les PR liés gh-144724 et gh-157241 pour comprendre le travail existant et les décisions prises. La tâche est considérée comme terminée lorsqu’un hook de pré-exécution documenté est disponible pour les intégrations REPL et que son comportement est couvert par les tests pertinents.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- cli
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 25/100