https://github.com/medismailben created 
https://github.com/llvm/llvm-project/pull/209331

Add an optional `bool foreground` parameter to
`Host::OpenFileInExternalEditor` so callers can choose whether opening the file 
should bring the editor to the foreground.

The macOS implementation maps `foreground=true` to omitting 
`kLSLaunchDontSwitch` in the Launch Services flags, so the editor is brought 
forward on launch. On non-Apple platforms the stub still returns `ENOTSUP`; the 
new parameter is added to its signature so it matches the declaration.

>From 7fad574f60392673f69678ab075fc415823e7562 Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani <[email protected]>
Date: Mon, 13 Jul 2026 15:55:36 -0700
Subject: [PATCH] [lldb/Host] Add `foreground` argument to
 `Host::OpenFileInExternalEditor`

Add an optional `bool foreground` parameter to
`Host::OpenFileInExternalEditor` so callers can choose whether opening
the file should bring the editor to the foreground.

The macOS implementation maps `foreground=true` to omitting
`kLSLaunchDontSwitch` in the Launch Services flags, so the editor is
brought forward on launch. On non-Apple platforms the stub still
returns `ENOTSUP`; the new parameter is added to its signature so it
matches the declaration.

Signed-off-by: Med Ismail Bennani <[email protected]>
---
 lldb/include/lldb/Host/Host.h          | 3 ++-
 lldb/source/Host/common/Host.cpp       | 2 +-
 lldb/source/Host/macosx/objcxx/Host.mm | 7 ++++---
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/lldb/include/lldb/Host/Host.h b/lldb/include/lldb/Host/Host.h
index 632614c17d173..554be4386adc3 100644
--- a/lldb/include/lldb/Host/Host.h
+++ b/lldb/include/lldb/Host/Host.h
@@ -309,7 +309,8 @@ class Host {
 
   static llvm::Error OpenFileInExternalEditor(llvm::StringRef editor,
                                               const FileSpec &file_spec,
-                                              uint32_t line_no);
+                                              uint32_t line_no,
+                                              bool foreground = false);
 
   /// Open a URL with the host's default handler (Launch Services on macOS,
   /// xdg-open on other Unix). Returns an error if opening fails or the 
platform
diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp
index 81d45f78559ce..c4e1500fe68ab 100644
--- a/lldb/source/Host/common/Host.cpp
+++ b/lldb/source/Host/common/Host.cpp
@@ -610,7 +610,7 @@ void Host::Kill(lldb::pid_t pid, int signo) { ::kill(pid, 
signo); }
 #if !defined(__APPLE__)
 llvm::Error Host::OpenFileInExternalEditor(llvm::StringRef editor,
                                            const FileSpec &file_spec,
-                                           uint32_t line_no) {
+                                           uint32_t line_no, bool foreground) {
   return llvm::errorCodeToError(
       std::error_code(ENOTSUP, std::system_category()));
 }
diff --git a/lldb/source/Host/macosx/objcxx/Host.mm 
b/lldb/source/Host/macosx/objcxx/Host.mm
index 9aae821220939..2553c602bea2c 100644
--- a/lldb/source/Host/macosx/objcxx/Host.mm
+++ b/lldb/source/Host/macosx/objcxx/Host.mm
@@ -341,7 +341,7 @@ repeat with the_window in (get windows)\n\
 
 llvm::Error Host::OpenFileInExternalEditor(llvm::StringRef editor,
                                            const FileSpec &file_spec,
-                                           uint32_t line_no) {
+                                           uint32_t line_no, bool foreground) {
 #if !TARGET_OS_OSX
   return llvm::errorCodeToError(
       std::error_code(ENOTSUP, std::system_category()));
@@ -432,8 +432,9 @@ repeat with the_window in (get windows)\n\
   // Build app launch parameters.
   LSApplicationParameters app_params;
   ::memset(&app_params, 0, sizeof(app_params));
-  app_params.flags =
-      kLSLaunchDefaults | kLSLaunchDontAddToRecents | kLSLaunchDontSwitch;
+  app_params.flags = kLSLaunchDefaults | kLSLaunchDontAddToRecents;
+  if (!foreground)
+    app_params.flags |= kLSLaunchDontSwitch;
   if (app_fsref)
     app_params.application = &(*app_fsref);
 

_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to