Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing messes up terminal/venv activation #24589

Open
j4k0xb opened this issue Dec 12, 2024 · 8 comments
Open

Typing messes up terminal/venv activation #24589

j4k0xb opened this issue Dec 12, 2024 · 8 comments
Assignees
Labels
area-terminal bug Issue identified by VS Code Team member as probable bug

Comments

@j4k0xb
Copy link

j4k0xb commented Dec 12, 2024

Type: Bug

Behaviour

The source /tmp/test/venv/bin/activate command is appended to the current terminal input, which messes it up.
This often happens when typing shortly after launching a new terminal.

Steps to reproduce:

  1. python3 -m venv venv
  2. Select Interpreter for this venv
  3. Open terminal with Ctrl+J and quickly type a letter

Output:

a%                                                                                                                                         
❯ asource /tmp/test/venv/bin/activate
zsh: command not found: asource
Peek.2024-12-12.01-15.mp4

Related issue: #23893

Diagnostic data

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

2024-12-12 04:02:31.032 [info] Telemetry level is off
2024-12-12 04:02:31.032 [info] Experiments are disabled, only manually opted experiments are active.
2024-12-12 04:02:31.032 [warning] Dir "/tmp/test/.pixi/envs" is not watchable (directory does not exist)
2024-12-12 04:02:31.032 [info] Python interpreter path: ./venv/bin/python
2024-12-12 04:02:31.053 [info] Starting Environment refresh
2024-12-12 04:02:31.053 [info] Searching for interpreters in posix paths locator
2024-12-12 04:02:31.055 [info] Searching for pyenv environments
2024-12-12 04:02:31.055 [info] Searching for conda environments
2024-12-12 04:02:31.055 [info] Searching for global virtual environments
2024-12-12 04:02:31.055 [info] Searching for custom virtual environments
2024-12-12 04:02:31.084 [info] > pyenv which python
2024-12-12 04:02:31.084 [info] cwd: .
2024-12-12 04:02:31.086 [info] pyenv is not installed
2024-12-12 04:02:31.086 [info] Finished searching for pyenv environments: 32 milliseconds
2024-12-12 04:02:31.086 [info] Finished searching for custom virtual envs: 31 milliseconds
2024-12-12 04:02:31.108 [info] > conda info --json
2024-12-12 04:02:31.138 [info] > hatch env show --json
2024-12-12 04:02:31.138 [info] cwd: .
2024-12-12 04:02:31.150 [info] Finished searching for global virtual envs: 96 milliseconds
2024-12-12 04:02:31.202 [info] Found: /bin/python --> /bin/python3.12
2024-12-12 04:02:31.658 [info] Found: /bin/python3 --> /bin/python3.12
2024-12-12 04:02:31.659 [info] Found: /bin/python3.12 --> /bin/python3.12
2024-12-12 04:02:31.796 [info] > /bin/python -I ~/.vscode/extensions/ms-python.python-2024.22.0-linux-x64/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.22.0-linux-x64/python_files/interpreterInfo.py
2024-12-12 04:02:31.815 [info] Found: /sbin/python --> /sbin/python3.12
2024-12-12 04:02:31.816 [info] Found: /sbin/python3 --> /sbin/python3.12
2024-12-12 04:02:31.817 [info] Found: /sbin/python3.12 --> /sbin/python3.12
2024-12-12 04:02:31.859 [info] > ./venv/bin/python -I ~/.vscode/extensions/ms-python.python-2024.22.0-linux-x64/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.22.0-linux-x64/python_files/interpreterInfo.py
2024-12-12 04:02:32.728 [info] Found: /usr/bin/python --> /usr/bin/python3.12
2024-12-12 04:02:32.731 [info] Found: /usr/bin/python3 --> /usr/bin/python3.12
2024-12-12 04:02:32.731 [info] Found: /usr/bin/python3.12 --> /usr/bin/python3.12
2024-12-12 04:02:32.796 [info] Found: /usr/sbin/python --> /usr/sbin/python3.12
2024-12-12 04:02:32.797 [info] Found: /usr/sbin/python3 --> /usr/sbin/python3.12
2024-12-12 04:02:32.797 [info] Found: /usr/sbin/python3.12 --> /usr/sbin/python3.12
2024-12-12 04:02:32.840 [info] > /sbin/python -I ~/.vscode/extensions/ms-python.python-2024.22.0-linux-x64/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.22.0-linux-x64/python_files/interpreterInfo.py
2024-12-12 04:02:32.879 [info] Finished searching for interpreters in posix paths locator: 1806 milliseconds
2024-12-12 04:02:32.879 [info] > /usr/bin/python -I ~/.vscode/extensions/ms-python.python-2024.22.0-linux-x64/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.22.0-linux-x64/python_files/interpreterInfo.py
2024-12-12 04:02:32.920 [info] > /usr/sbin/python -I ~/.vscode/extensions/ms-python.python-2024.22.0-linux-x64/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2024.22.0-linux-x64/python_files/interpreterInfo.py
2024-12-12 04:02:32.920 [info] Environments refresh paths discovered (event): 1869 milliseconds
2024-12-12 04:02:32.920 [info] Environments refresh paths discovered: 1869 milliseconds
2024-12-12 04:02:32.971 [info] Environments refresh finished (event): 1920 milliseconds
2024-12-12 04:02:32.976 [info] Environment refresh took 1926 milliseconds
2024-12-12 04:02:33.462 [info] Starting Pylance language server.
2024-12-12 04:02:35.081 [info] Send text to terminal: source /tmp/test/venv/bin/activate

Extension version: 2024.22.0
VS Code version: Code 1.96.0 (138f619c86f1199955d53b4166bef66ef252935c, 2024-12-11T02:29:09.626Z)
OS version: Linux x64 6.6.54-2-MANJARO
Modes:

  • Python version (& distribution if applicable, e.g. Anaconda): 3.12.6
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
  • Value of the python.languageServer setting: Pylance
User Settings


languageServer: "Pylance"

Installed Extensions
Extension Name Extension Id Version
.NET Install Tool ms-dotnettools.vscode-dotnet-runtime 2.2.3
Abracadabra, refactor this! nicoespeon.abracadabra 9.4.8
Atom One Dark Theme akamud.vscode-theme-onedark 2.3.0
Auto Rename Tag formulahendry.auto-rename-tag 0.1.10
Auto Restart TypeScript / ESLint Servers neotan.vscode-auto-restart-typescript-eslint-servers 0.0.6
Azure Repos ms-vscode.azure-repos 0.40.0
Bash IDE mads-hartmann.bash-ide-vscode 1.43.0
Better C++ Syntax jeff-hykin.better-cpp-syntax 1.27.1
Better package.json ldd-vs-code.better-package-json 0.2.1
Bookmarks alefragnani.Bookmarks 13.5.0
C/C++ ms-vscode.cpptools 1.22.11
C/C++ Extension Pack ms-vscode.cpptools-extension-pack 1.3.0
C/C++ Snippets hars.CppSnippets 0.0.15
C/C++ Themes ms-vscode.cpptools-themes 2.0.0
C# ms-dotnettools.csharp 2.55.29
C# Dev Kit ms-dotnettools.csdevkit 1.14.14
Clang-Format xaver.clang-format 1.9.0
clangd llvm-vs-code-extensions.vscode-clangd 0.1.33
CMake twxs.cmake 0.0.17
CMake Language Support josetr.cmake-language-support-vscode 0.0.9
CMake Tools ms-vscode.cmake-tools 1.19.52
Code Spell Checker streetsidesoftware.code-spell-checker 4.0.21
CodeLLDB vadimcn.vscode-lldb 1.11.1
Compare Folders moshfeu.compare-folders 0.25.1
Complete JSDoc Tags HookyQR.JSDocTagComplete 0.0.2
Copy GitHub URL mattlott.copy-github-url 0.14.0
copy-json-path nidu.copy-json-path 0.4.0
CSS Formatter aeschli.vscode-css-formatter 1.0.2
deoptexplorer-vscode rbuckton.deoptexplorer-vscode 1.1.2
Dev Containers ms-vscode-remote.remote-containers 0.394.0
Docker ms-azuretools.vscode-docker 1.29.3
EditorConfig for VS Code EditorConfig.EditorConfig 0.16.4
esbuild Problem Matchers connor4312.esbuild-problem-matchers 0.0.3
ESLint dbaeumer.vscode-eslint 3.0.10
Eval and Replace Lebster.eval-and-replace 2.3.0
File Utils sleistner.vscode-fileutils 3.10.3
Flame Chart Visualizer for JavaScript Profiles ms-vscode.vscode-js-profile-flame 1.0.9
Git Graph mhutchie.git-graph 1.30.0
GitHub Actions github.vscode-github-actions 0.27.0
GitHub Codespaces GitHub.codespaces 1.17.3
GitHub Copilot GitHub.copilot 1.250.0
GitHub Copilot Chat GitHub.copilot-chat 0.23.0
GitHub Pull Requests GitHub.vscode-pull-request-github 0.102.0
GitHub Repositories GitHub.remotehub 0.64.0
GitHub Theme GitHub.github-vscode-theme 6.3.5
GitLens — Git supercharged eamodio.gitlens 16.0.5
GN npclaudiu.vscode-gn 1.1.0
Header source switch ryzngard.vscode-header-source 1.3.0
Hex Editor ms-vscode.hexeditor 1.11.1
Hover Converter bedrankara.hoverconverter 0.0.1
IntelliCode Completions VisualStudioExptTeam.vscodeintellicode-completions 2.0.1
IntelliCode for C# Dev Kit ms-dotnettools.vscodeintellicode-csharp 2.2.3
JavaScript Debugger ms-vscode.js-debug 1.96.0
JavaScript Debugger Companion Extension ms-vscode.js-debug-companion 1.1.3
JS Refactoring Assistant p42ai.refactor 3.0.1
Jupyter ms-toolsai.jupyter 2024.11.0
Jupyter Cell Tags ms-toolsai.vscode-jupyter-cell-tags 0.1.9
Jupyter Keymap ms-toolsai.jupyter-keymap 1.1.2
Jupyter Notebook Renderers ms-toolsai.jupyter-renderers 1.0.21
Jupyter Slide Show ms-toolsai.vscode-jupyter-slideshow 0.1.6
Language Support for Java(TM) by Red Hat redhat.java 1.37.0
LaTeX Workshop James-Yu.latex-workshop 10.7.0
Lebab mrmlnc.vscode-lebab 2.6.0
Markdown PDF yzane.markdown-pdf 1.5.0
markdownlint DavidAnson.vscode-markdownlint 0.57.0
node-snippets chris-noring.node-snippets 1.3.3
Paste JSON as Code quicktype.quicktype 23.0.170
Patch Extensions j4k0xb.patch-extensions 0.0.1
Peggy Language PeggyJS.peggy-language 3.0.2
PlatformIO IDE platformio.platformio-ide 3.3.3
Prettier - Code formatter esbenp.prettier-vscode 11.0.0
Pylance ms-python.vscode-pylance 2024.12.1
Python ms-python.python 2024.22.0
Python Debugger ms-python.debugpy 2024.14.0
Quokka.js WallabyJs.quokka-vscode 1.0.675
Rainbow CSV mechatroner.rainbow-csv 3.13.0
Remote - SSH ms-vscode-remote.remote-ssh 0.116.0
Remote - SSH: Editing Configuration Files ms-vscode-remote.remote-ssh-edit 0.87.0
Remote - Tunnels ms-vscode.remote-server 1.5.2
Remote Development ms-vscode-remote.vscode-remote-extensionpack 0.26.0
Remote Explorer ms-vscode.remote-explorer 0.4.3
Remote Repositories ms-vscode.remote-repositories 0.42.0
Ruff charliermarsh.ruff 2024.56.0
rust-analyzer rust-lang.rust-analyzer 0.3.2212
ShellCheck timonwong.shellcheck 0.37.1
Smalise LoyieKing.smalise 0.0.12
SQLite Viewer qwtel.sqlite-viewer 0.9.5
SQLTools mtxr.sqltools 0.28.3
SQLTools PostgreSQL/Cockroach Driver mtxr.sqltools-driver-pg 0.5.4
Stylelint stylelint.vscode-stylelint 1.4.0
Surround yatki.vscode-surround 1.5.0
SVG jock.svg 1.5.4
swapdiff shalimski.swapdiff 0.2.2
Table Visualizer for JavaScript Profiles ms-vscode.vscode-js-profile-table 1.0.10
Tailwind CSS IntelliSense bradlc.vscode-tailwindcss 0.12.16
Template String Converter j4k0xb.template-string-converter 0.1.0
Text Marker (Highlighter) ryu1kn.text-marker 1.11.0
Thunder Client rangav.vscode-thunder-client 2.32.10
Todo Tree Gruntfuggly.todo-tree 0.0.226
TOML Language Support be5invis.toml 0.6.0
TsAutoReturnType ebrithil30.vscode-ts-auto-return-type 1.1.0
Turbo Console Log ChakrounAnas.turbo-console-log 2.10.5
Twoslash Query Comments Orta.vscode-twoslash-queries 1.4.0
TypeScript Importer pmneo.tsimporter 2.0.1
Unity visualstudiotoolsforunity.vstuc 1.0.5
V8 Torque Language Support v8-torque.vscode-torque 1.0.3
v8-bytecode-highlight j4k0xb.v8-bytecode-highlight 0.2.0
Vencord Companion Vendicated.vencord-companion 0.1.3
Visual Studio Code Commitizen Support KnisterPeter.vscode-commitizen 1.1.0
Vitest vitest.explorer 1.8.3
vscode-base64 adamhartford.vscode-base64 0.1.0
vscode-icons vscode-icons-team.vscode-icons 12.9.0
vscode-position jtr.vscode-position 1.1.2
WebAssembly dtsvet.vscode-wasm 1.4.1
Wolf traBpUkciP.wolf 0.4.3
Workspace Storage Cleanup mehyaa.workspace-storage-cleanup 1.6.5
x86 and x86_64 Assembly 13xforever.language-x86-64-assembly 3.1.4
YAML redhat.vscode-yaml 1.15.0
undefined wmaurer.change-case 1.0.0
System Info
Item Value
CPUs Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz (12 x 2600)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
webnn: disabled_off
Load (avg) 2, 1, 1
Memory (System) 15.49GB (4.77GB free)
Process Argv
Screen Reader no
VM 0%
DESKTOP_SESSION plasma
XDG_CURRENT_DESKTOP KDE
XDG_SESSION_DESKTOP KDE
XDG_SESSION_TYPE x11
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Dec 12, 2024
@j4k0xb j4k0xb changed the title source command race condition Typing messes up terminal/venv activation Dec 12, 2024
@karthiknadig
Copy link
Member

We can’t avoid running activation scripts in cases where VS Code is not launched from an activated environment. The best thing to do here is turn off activation and launch VS Code from an activated environment.

Here is how:

  1. Navigate to your project from an external terminal
  2. Activate your environment
  3. run code .

This will star VS Code itself in an activated environment and there is no need for us to activate it later.

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Dec 12, 2024
@j4k0xb
Copy link
Author

j4k0xb commented Dec 12, 2024

I don't mind if it's running activation scripts, but is it possible that it won't interfere with the terminal input?

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Dec 12, 2024
@karthiknadig
Copy link
Member

The support for that requires "Shell Integration" feature to be on. With that it can work a little bit better, and hopefully we can do this better as the feature improves:
Image

@j4k0xb
Copy link
Author

j4k0xb commented Dec 12, 2024

Unfortunately it has the same behavior with shell integration enabled

@anthonykim1 anthonykim1 self-assigned this Dec 12, 2024
@anthonykim1 anthonykim1 added area-terminal and removed triage-needed Needs assignment to the proper sub-team labels Dec 12, 2024
@anthonykim1
Copy link

anthonykim1 commented Dec 12, 2024

It looks like timeout https://github.com/microsoft/vscode-python/blob/main/src/client/common/terminal/service.ts#L100 is not "long enough" to wait for executeCommand.

If @j4k0xb check your Python output after setting your log level to "trace"
You will see something along the lines of "send text...source /tmp/test/venv/bin/activate..." instead of "executeCommand...source /tmp/test/venv/bin/activate..."

We may have to do improve to more frequently use executeCommand such as via caching shell integration state from previous session. Or figure out different way to completely wait for activate command before allowing user input in terminal.

Using pwsh 6 or 7 instead of the default windows pwsh provided by Microsoft can really help with executeCommand, shell integration related.

@j4k0xb I assume you will notice the duplicate commands wont really happen after the very first run in terminal. Is that correct?

@anthonykim1 anthonykim1 added the bug Issue identified by VS Code Team member as probable bug label Dec 12, 2024
@j4k0xb
Copy link
Author

j4k0xb commented Dec 12, 2024

check your Python output after setting your log level to "trace"
You will see something along the lines of "send text...source /tmp/test/venv/bin/activate..." instead of "executeCommand...source /tmp/test/venv/bin/activate..."

yes

I assume you will notice the duplicate commands wont really happen after the very first run in terminal. Is that correct?

I only encountered this issue during the first activation in a terminal

@anthonykim1
Copy link

Thanks for the info
@j4k0xb Can you switch to using pwsh 6 or pwsh 7 instead of the windows powershell provided by default in your Windows OS and see if you can still repro the problem?

@j4k0xb
Copy link
Author

j4k0xb commented Dec 12, 2024

instead of the windows powershell provided by default in your Windows OS

(I don't use Windows or PowerShell)
but can repro with bash, sh, zsh in Linux
pwsh 7 behaves a bit different as it only inserts the command but doesn't execute it (have to press enter):

Peek.2024-12-12.19-55.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-terminal bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

3 participants