fix(external_editor): rewrite corrupted file, proper function ordering

This commit is contained in:
2026-05-07 21:04:55 -04:00
parent ca4719687a
commit fa0026371d
+9 -22
View File
@@ -1,6 +1,7 @@
"""External Editor Launcher - Opens files in external text editors for diff viewing."""
from __future__ import annotations
import os
import subprocess
import tempfile
from pathlib import Path
@@ -49,22 +50,7 @@ class ExternalEditorLauncher:
_cached_vscode_config: Optional[TextEditorConfig] = None
def auto_detect_vscode() -> Optional[TextEditorConfig]:
global _cached_vscode_config
if _cached_vscode_config is not None:
return _cached_vscode_config
vscode_path = _find_vscode_in_registry() or _find_vscode_common_paths()
if vscode_path:
_cached_vscode_config = TextEditorConfig(
name="vscode",
path=vscode_path,
diff_args=["--new-window", "--diff"]
)
return _cached_vscode_config
def get_default_launcher() -> ExternalEditorLauncher:
import subprocess
def _find_vscode_in_registry() -> Optional[str]:
paths = []
reg_keys = [
r"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*",
@@ -81,7 +67,7 @@ def get_default_launcher() -> ExternalEditorLauncher:
line = line.strip()
if line and line != "":
exe_path = line.strip() + "\\Code.exe"
if subprocess.run(["test", "-f", exe_path], check=False).returncode == 0:
if os.path.exists(exe_path):
paths.append(exe_path)
except Exception:
pass
@@ -91,7 +77,6 @@ def get_default_launcher() -> ExternalEditorLauncher:
def _find_vscode_common_paths() -> Optional[str]:
import os
candidates = [
r"C:\apps\Microsoft VS Code\Code.exe",
r"C:\Program Files\Microsoft VS Code\Code.exe",
@@ -105,14 +90,17 @@ def _find_vscode_common_paths() -> Optional[str]:
def auto_detect_vscode() -> Optional[TextEditorConfig]:
global _cached_vscode_config
if _cached_vscode_config is not None:
return _cached_vscode_config
vscode_path = _find_vscode_in_registry() or _find_vscode_common_paths()
if vscode_path:
return TextEditorConfig(
_cached_vscode_config = TextEditorConfig(
name="vscode",
path=vscode_path,
diff_args=["--new-window", "--diff"]
)
return None
return _cached_vscode_config
def get_default_launcher() -> ExternalEditorLauncher:
@@ -151,5 +139,4 @@ def resolve_project_editor_override(project_path: Optional[str]) -> Optional[str
def create_temp_modified_file(content: str) -> str:
with tempfile.NamedTemporaryFile(mode="w", suffix="_modified", delete=False, encoding="utf-8") as f:
f.write(content)
return f.name
pass
return f.name