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

/editor for VSCode on Windows does not work #2929

Open
EvitanRelta opened this issue Jan 21, 2025 · 0 comments
Open

/editor for VSCode on Windows does not work #2929

EvitanRelta opened this issue Jan 21, 2025 · 0 comments
Labels

Comments

@EvitanRelta
Copy link

EvitanRelta commented Jan 21, 2025

Issue

The problem

On Windows when editor is set to use VSCode, the /editor command fails as below.

$ aider --editor "code --wait"
──────────────────────────────────────────────────────────────────────────────────
Aider v0.72.1
Model: deepseek/deepseek-chat with diff edit format, prompt cache, infinite output
Git repo: .git with 26 files
Repo-map: using 4096 tokens, auto refresh
──────────────────────────────────────────────────────────────────────────────────
> /editor

Unable to complete editor: [WinError 2] The system cannot find the file specified
──────────────────────────────────────────────────────────────────────────────────
>

Cause

The /editor command runs the editor command via subprocess.call(command_parts) at https://github.com/Aider-AI/aider/blob/v0.72.1/aider/editor.py#L133, which on windows, the code command isn't recognised. A simple demo of this is running this script on a Windows machine with VSCode installed:

import subprocess
subprocess.call(["code"])

# $ python test.py
# Traceback (most recent call last):
#   File "C:\path\test.py", line 17, in <module>
#     subprocess.call(["code"])
#   File "C:\path\anaconda3\envs\aider\Lib\subprocess.py", line 389, in call
#     with Popen(*popenargs, **kwargs) as p:
#          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "C:\path\anaconda3\envs\aider\Lib\subprocess.py", line 1026, in __init__
#     self._execute_child(args, executable, preexec_fn, close_fds,
#   File "C:\path\anaconda3\envs\aider\Lib\subprocess.py", line 1538, in _execute_child
#     hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
#                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# FileNotFoundError: [WinError 2] The system cannot find the file specified

Possible explaination

When you install VS Code on windows, it adds code.cmd (a batch file) to your PATH, not a true .exe:

import subprocess
subprocess.call(["where", "code"])

# C:\path\Programs\Microsoft VS Code\bin\code      # No extension
# C:\path\Programs\Microsoft VS Code\bin\code.cmd  # .cmd

Batch files can't be executed directly by Python's subprocess with shell=False (the default). They require cmd.exe to interpret them.

With shell=False (default), subprocess uses the Windows API CreateProcess, which:

  • Only recognizes .exe, .com, or .bat files directly (but .cmd files require explicit handling).
  • Doesn't understand shell-specific features like aliases or batch file execution.

Even if code is in your PATH, CreateProcess fails because it's looking for code.exe (which doesn't exist), not code.cmd.


Solutions

For now, a simple workaround users can do is to use cmd /c code --wait instead of code --wait:

aider --editor "cmd /c code --wait"

And a simple fix would be to run subprocess.call with shell=True. But I'm not sure what consequence shell=True would entail.

subprocess.call(command_parts)
# replace with
subprocess.call(command_parts, shell=True)

I do think /editor should use the current terminal type though. Like if I started aider in Git bash, I'd assume the /editor command would run in Git bash rather than CMD. Perhaps we could use run_cmd_subprocess() in aider/run_cmd.py?

Version and model info

Aider v0.72.1
Model: deepseek/deepseek-chat with diff edit format, prompt cache, infinite output
Git repo: .git with 26 files
Repo-map: using 4096 tokens, auto refresh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants