@@ -17,17 +17,19 @@ public final class XcodeInspector: ObservableObject {
1717 @Published public internal( set) var activeXcode : XcodeAppInstanceInspector ?
1818 @Published public internal( set) var latestActiveXcode : XcodeAppInstanceInspector ?
1919 @Published public internal( set) var xcodes : [ XcodeAppInstanceInspector ] = [ ]
20- @Published public internal( set) var activeProjectURL = URL ( fileURLWithPath: " / " )
20+ @Published public internal( set) var activeProjectRootURL = URL ( fileURLWithPath: " / " )
2121 @Published public internal( set) var activeDocumentURL = URL ( fileURLWithPath: " / " )
22+ @Published public internal( set) var activeWorkspaceURL = URL ( fileURLWithPath: " / " )
2223 @Published public internal( set) var focusedWindow : XcodeWindowInspector ?
2324 @Published public internal( set) var focusedEditor : SourceEditor ?
2425 @Published public internal( set) var focusedElement : AXUIElement ?
2526 @Published public internal( set) var completionPanel : AXUIElement ?
2627
2728 public var focusedEditorContent : EditorInformation ? {
2829 let editorContent = XcodeInspector . shared. focusedEditor? . content
29- let documentURL = XcodeInspector . shared. activeDocumentURL
30- let projectURL = XcodeInspector . shared. activeProjectURL
30+ let documentURL = XcodeInspector . shared. realtimeActiveDocumentURL
31+ let workspaceURL = XcodeInspector . shared. realtimeActiveWorkspaceURL
32+ let projectURL = XcodeInspector . shared. activeProjectRootURL
3133 let language = languageIdentifierFromFileURL ( documentURL)
3234 let relativePath = documentURL. path
3335 . replacingOccurrences ( of: projectURL. path, with: " " )
@@ -42,7 +44,8 @@ public final class XcodeInspector: ObservableObject {
4244 selectedContent: selectedContent,
4345 selectedLines: selectedLines,
4446 documentURL: documentURL,
45- projectURL: projectURL,
47+ workspaceURL: workspaceURL,
48+ projectRootURL: projectURL,
4649 relativePath: relativePath,
4750 language: language
4851 )
@@ -53,14 +56,19 @@ public final class XcodeInspector: ObservableObject {
5356 selectedContent: " " ,
5457 selectedLines: [ ] ,
5558 documentURL: documentURL,
56- projectURL: projectURL,
59+ workspaceURL: workspaceURL,
60+ projectRootURL: projectURL,
5761 relativePath: relativePath,
5862 language: language
5963 )
6064 }
6165
6266 public var realtimeActiveDocumentURL : URL {
63- latestActiveXcode? . realtimeDocumentURL ?? URL ( fileURLWithPath: " / " )
67+ latestActiveXcode? . realtimeDocumentURL ?? activeDocumentURL
68+ }
69+
70+ public var realtimeActiveWorkspaceURL : URL {
71+ latestActiveXcode? . realtimeWorkspaceURL ?? activeWorkspaceURL
6472 }
6573
6674 init ( ) {
@@ -141,7 +149,8 @@ public final class XcodeInspector: ObservableObject {
141149 activeDocumentURL = xcode. documentURL
142150 focusedWindow = xcode. focusedWindow
143151 completionPanel = xcode. completionPanel
144- activeProjectURL = xcode. projectURL
152+ activeProjectRootURL = xcode. projectRootURL
153+ activeWorkspaceURL = xcode. workspaceURL
145154 focusedWindow = xcode. focusedWindow
146155
147156 let setFocusedElement = { [ weak self] in
@@ -178,9 +187,13 @@ public final class XcodeInspector: ObservableObject {
178187 xcode. $documentURL. sink { [ weak self] url in
179188 self ? . activeDocumentURL = url
180189 } . store ( in: & activeXcodeCancellable)
190+
191+ xcode. $workspaceURL. sink { [ weak self] url in
192+ self ? . activeWorkspaceURL = url
193+ } . store ( in: & activeXcodeCancellable)
181194
182- xcode. $projectURL . sink { [ weak self] url in
183- self ? . activeProjectURL = url
195+ xcode. $projectRootURL . sink { [ weak self] url in
196+ self ? . activeProjectRootURL = url
184197 } . store ( in: & activeXcodeCancellable)
185198
186199 xcode. $focusedWindow. sink { [ weak self] window in
@@ -207,7 +220,8 @@ public class AppInstanceInspector: ObservableObject {
207220public final class XcodeAppInstanceInspector : AppInstanceInspector {
208221 @Published public var focusedWindow : XcodeWindowInspector ?
209222 @Published public var documentURL : URL = . init( fileURLWithPath: " / " )
210- @Published public var projectURL : URL = . init( fileURLWithPath: " / " )
223+ @Published public var workspaceURL : URL = . init( fileURLWithPath: " / " )
224+ @Published public var projectRootURL : URL = . init( fileURLWithPath: " / " )
211225 @Published public var workspaces = [ WorkspaceIdentifier: Workspace] ( )
212226 public var realtimeWorkspaces : [ WorkspaceIdentifier : WorkspaceInfo ] {
213227 updateWorkspaceInfo ( )
@@ -226,6 +240,17 @@ public final class XcodeAppInstanceInspector: AppInstanceInspector {
226240 return WorkspaceXcodeWindowInspector . extractDocumentURL ( windowElement: window)
227241 ?? URL ( fileURLWithPath: " / " )
228242 }
243+
244+ public var realtimeWorkspaceURL : URL {
245+ guard let window = appElement. focusedWindow,
246+ window. identifier == " Xcode.WorkspaceWindow "
247+ else {
248+ return URL ( fileURLWithPath: " / " )
249+ }
250+
251+ return WorkspaceXcodeWindowInspector . extractWorkspaceURL ( windowElement: window)
252+ ?? URL ( fileURLWithPath: " / " )
253+ }
229254
230255 var _version : String ?
231256 public var version : String ? {
@@ -284,17 +309,23 @@ public final class XcodeAppInstanceInspector: AppInstanceInspector {
284309 focusedWindowObservations. removeAll ( )
285310
286311 documentURL = window. documentURL
287- projectURL = window. projectURL
312+ workspaceURL = window. workspaceURL
313+ projectRootURL = window. projectRootURL
288314
289315 window. $documentURL
290316 . filter { $0 != . init( fileURLWithPath: " / " ) }
291317 . sink { [ weak self] url in
292318 self ? . documentURL = url
293319 } . store ( in: & focusedWindowObservations)
294- window. $projectURL
320+ window. $workspaceURL
321+ . filter { $0 != . init( fileURLWithPath: " / " ) }
322+ . sink { [ weak self] url in
323+ self ? . workspaceURL = url
324+ } . store ( in: & focusedWindowObservations)
325+ window. $projectRootURL
295326 . filter { $0 != . init( fileURLWithPath: " / " ) }
296327 . sink { [ weak self] url in
297- self ? . projectURL = url
328+ self ? . projectRootURL = url
298329 } . store ( in: & focusedWindowObservations)
299330 }
300331 } else {
0 commit comments