This patch refactors the macOS implementation of OpenFileInExternalEditor:
- Fix AppleEvent memory leak
- Fix caching of LLDB_EXTERNAL_EDITOR
- Fix (speculatively) crash when CFURL is NULL.
- Improve readability
- Improve documentation
- Improve logging
rdar://108633464
PS: A bunch of the Launch Services APIs have been deprecated (LSFindApplicationForInfo, LSOpenURLsWithRole). The preferred API is LSOpenCFURLRef but it doesn't allow you to specify the "location" Apple Event which is used to highlight the current line. Interestingly enough, both Xcode (the default) and TextEdit both ignore that. Sublime Text on the other hand does honor it. Since the old APIs are deprecated but still available, I prefer not to regress the current functionality.
I guess this doesn't need to be a const std::string, a llvm::StringRef would have been nice but looking at SBFileSpec::GetPath, there is unfortunately no overload for that.