@@ -43,43 +43,47 @@ public enum Environment {
4343 }
4444 }
4545
46- public static var fetchCurrentProjectRootURL : ( _ fileURL: URL ? ) async throws
47- -> URL ? = { fileURL in
48- if let xcode = ActiveApplicationMonitor . activeXcode
49- ?? ActiveApplicationMonitor . latestXcode
50- {
51- let application = AXUIElementCreateApplication ( xcode. processIdentifier)
52- let focusedWindow = application. focusedWindow
53- for child in focusedWindow? . children ?? [ ] {
54- if child. description. starts ( with: " / " ) , child. description. count > 1 {
55- let path = child. description
56- let trimmedNewLine = path. trimmingCharacters ( in: . newlines)
57- var url = URL ( fileURLWithPath: trimmedNewLine)
58- while !FileManager. default. fileIsDirectory ( atPath: url. path) ||
59- !url. pathExtension. isEmpty
60- {
61- url = url. deletingLastPathComponent ( )
62- }
63- return url
46+ public static var fetchCurrentProjectRootURLFromXcode : ( ) async throws -> URL ? = {
47+ if let xcode = ActiveApplicationMonitor . activeXcode
48+ ?? ActiveApplicationMonitor . latestXcode
49+ {
50+ let application = AXUIElementCreateApplication ( xcode. processIdentifier)
51+ let focusedWindow = application. focusedWindow
52+ for child in focusedWindow? . children ?? [ ] {
53+ if child. description. starts ( with: " / " ) , child. description. count > 1 {
54+ let path = child. description
55+ let trimmedNewLine = path. trimmingCharacters ( in: . newlines)
56+ var url = URL ( fileURLWithPath: trimmedNewLine)
57+ while !FileManager. default. fileIsDirectory ( atPath: url. path) ||
58+ !url. pathExtension. isEmpty
59+ {
60+ url = url. deletingLastPathComponent ( )
6461 }
62+ return url
6563 }
6664 }
65+ }
6766
68- guard var currentURL = fileURL else { return nil }
69- var firstDirectoryURL : URL ?
70- while currentURL. pathComponents. count > 1 {
71- defer { currentURL. deleteLastPathComponent ( ) }
72- guard FileManager . default. fileIsDirectory ( atPath: currentURL. path) else { continue }
73- if firstDirectoryURL == nil { firstDirectoryURL = currentURL }
74- let gitURL = currentURL. appendingPathComponent ( " .git " )
75- if FileManager . default. fileIsDirectory ( atPath: gitURL. path) {
76- return currentURL
77- }
78- }
67+ return nil
68+ }
7969
80- return firstDirectoryURL ?? fileURL
70+ public static var guessProjectRootURLForFile : ( _ fileURL: URL ) async throws -> URL = {
71+ fileURL in
72+ var currentURL = fileURL
73+ var firstDirectoryURL : URL ?
74+ while currentURL. pathComponents. count > 1 {
75+ defer { currentURL. deleteLastPathComponent ( ) }
76+ guard FileManager . default. fileIsDirectory ( atPath: currentURL. path) else { continue }
77+ if firstDirectoryURL == nil { firstDirectoryURL = currentURL }
78+ let gitURL = currentURL. appendingPathComponent ( " .git " )
79+ if FileManager . default. fileIsDirectory ( atPath: gitURL. path) {
80+ return currentURL
81+ }
8182 }
8283
84+ return firstDirectoryURL ?? fileURL
85+ }
86+
8387 public static var fetchCurrentFileURL : ( ) async throws -> URL = {
8488 guard let xcode = ActiveApplicationMonitor . activeXcode
8589 ?? ActiveApplicationMonitor . latestXcode
0 commit comments