MCPcopy
hub / github.com/marimo-team/marimo / open_in_editor

Method open_in_editor

marimo/_server/files/os_file_system.py:440–475  ·  view source on GitHub ↗
(self, path: str, line_number: int | None)

Source from the content-addressed store, hash-verified

438 return results[:limit]
439
440 def open_in_editor(self, path: str, line_number: int | None) -> bool:
441 try:
442 # First try to get editor from environment variable
443 editor = os.environ.get("EDITOR")
444
445 # If editor is a terminal-based editor, we just call `open`, because
446 # otherwise it silently opens the terminal in the same window that is
447 # running marimo.
448 if editor and not _is_terminal_editor(editor):
449 args = (
450 [path]
451 if line_number is None
452 else editor_open_file_in_line_args(
453 editor, path, line_number
454 )
455 )
456
457 try:
458 # For GUI editors
459 subprocess.run([editor, *args])
460 return True
461 except Exception as e:
462 LOGGER.error(f"Error opening with EDITOR: {e}")
463
464 # Use system default if no editor specified
465 if platform.system() == "Darwin": # macOS
466 subprocess.call(("open", path))
467 elif platform.system() == "Windows": # Windows
468 # startfile only exists on Windows
469 os.startfile(path) # type: ignore[attr-defined]
470 else: # Linux variants
471 subprocess.call(("xdg-open", path))
472 return True
473 except Exception as e:
474 LOGGER.error(f"Error opening file: {e}")
475 return False
476
477
478def editor_open_file_in_line_args(

Callers 1

open_fileFunction · 0.80

Calls 6

_is_terminal_editorFunction · 0.85
callMethod · 0.80
getMethod · 0.65
runMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected