mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 16:54:59 +00:00
refactor: Simplify editor discovery and command handling logic
This commit is contained in:
parent
5b13105d58
commit
d65e3f73df
2 changed files with 4 additions and 14 deletions
|
@ -104,18 +104,13 @@ def discover_editor(editor_override=None):
|
||||||
default_editor = DEFAULT_EDITOR_OS_X
|
default_editor = DEFAULT_EDITOR_OS_X
|
||||||
else:
|
else:
|
||||||
default_editor = DEFAULT_EDITOR_NIX
|
default_editor = DEFAULT_EDITOR_NIX
|
||||||
|
|
||||||
if editor_override:
|
if editor_override:
|
||||||
editor = editor_override
|
editor = editor_override
|
||||||
else:
|
else:
|
||||||
editor = get_environment_editor(default_editor)
|
editor = get_environment_editor(default_editor)
|
||||||
try:
|
|
||||||
if system == "Windows":
|
|
||||||
return shlex.split(editor, posix=False)
|
|
||||||
else:
|
|
||||||
return shlex.split(editor)
|
|
||||||
except ValueError as e:
|
|
||||||
raise RuntimeError(f"Invalid editor command format '{editor}': {e}")
|
|
||||||
|
|
||||||
|
return editor
|
||||||
|
|
||||||
def pipe_editor(input_data="", suffix=None, editor=None):
|
def pipe_editor(input_data="", suffix=None, editor=None):
|
||||||
"""
|
"""
|
||||||
|
@ -133,9 +128,8 @@ def pipe_editor(input_data="", suffix=None, editor=None):
|
||||||
:rtype: str
|
:rtype: str
|
||||||
"""
|
"""
|
||||||
filepath = write_temp_file(input_data, suffix)
|
filepath = write_temp_file(input_data, suffix)
|
||||||
command_parts = discover_editor(editor)
|
command_str = discover_editor(editor)
|
||||||
command_parts.append(filepath)
|
command_str += " " + filepath
|
||||||
command_str = " ".join(shlex.quote(part) for part in command_parts)
|
|
||||||
|
|
||||||
subprocess.call(command_str, shell=True)
|
subprocess.call(command_str, shell=True)
|
||||||
with open(filepath, "r") as f:
|
with open(filepath, "r") as f:
|
||||||
|
|
|
@ -84,10 +84,6 @@ def test_discover_editor_override():
|
||||||
assert discover_editor("code") == "code"
|
assert discover_editor("code") == "code"
|
||||||
assert discover_editor('vim -c "set noswapfile"') == 'vim -c "set noswapfile"'
|
assert discover_editor('vim -c "set noswapfile"') == 'vim -c "set noswapfile"'
|
||||||
|
|
||||||
# Test invalid editor command
|
|
||||||
with pytest.raises(RuntimeError):
|
|
||||||
discover_editor('vim "unclosed quote')
|
|
||||||
|
|
||||||
|
|
||||||
def test_pipe_editor_with_fake_editor():
|
def test_pipe_editor_with_fake_editor():
|
||||||
# Create a temporary Python script that logs its arguments
|
# Create a temporary Python script that logs its arguments
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue