@@ -17,22 +17,23 @@ 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 activeProjectRootURL = URL ( fileURLWithPath : " / " )
21- @Published public internal( set) var activeDocumentURL = URL ( fileURLWithPath : " / " )
22- @Published public internal( set) var activeWorkspaceURL = URL ( fileURLWithPath : " / " )
20+ @Published public internal( set) var activeProjectRootURL : URL ? = nil
21+ @Published public internal( set) var activeDocumentURL : URL ? = nil
22+ @Published public internal( set) var activeWorkspaceURL : URL ? = nil
2323 @Published public internal( set) var focusedWindow : XcodeWindowInspector ?
2424 @Published public internal( set) var focusedEditor : SourceEditor ?
2525 @Published public internal( set) var focusedElement : AXUIElement ?
2626 @Published public internal( set) var completionPanel : AXUIElement ?
2727
2828 public var focusedEditorContent : EditorInformation ? {
29+ guard let documentURL = XcodeInspector . shared. realtimeActiveDocumentURL,
30+ let workspaceURL = XcodeInspector . shared. realtimeActiveWorkspaceURL,
31+ let projectURL = XcodeInspector . shared. activeProjectRootURL
32+ else { return nil }
33+
2934 let editorContent = XcodeInspector . shared. focusedEditor? . content
30- let documentURL = XcodeInspector . shared. realtimeActiveDocumentURL
31- let workspaceURL = XcodeInspector . shared. realtimeActiveWorkspaceURL
32- let projectURL = XcodeInspector . shared. activeProjectRootURL
3335 let language = languageIdentifierFromFileURL ( documentURL)
34- let relativePath = documentURL. path
35- . replacingOccurrences ( of: projectURL. path, with: " " )
36+ let relativePath = documentURL. path. replacingOccurrences ( of: projectURL. path, with: " " )
3637
3738 if let editorContent, let range = editorContent. selections. first {
3839 let ( selectedContent, selectedLines) = EditorInformation . code (
@@ -63,15 +64,15 @@ public final class XcodeInspector: ObservableObject {
6364 )
6465 }
6566
66- public var realtimeActiveDocumentURL : URL {
67+ public var realtimeActiveDocumentURL : URL ? {
6768 latestActiveXcode? . realtimeDocumentURL ?? activeDocumentURL
6869 }
69-
70- public var realtimeActiveWorkspaceURL : URL {
70+
71+ public var realtimeActiveWorkspaceURL : URL ? {
7172 latestActiveXcode? . realtimeWorkspaceURL ?? activeWorkspaceURL
7273 }
73-
74- public var realtimeActiveProjectURL : URL {
74+
75+ public var realtimeActiveProjectURL : URL ? {
7576 latestActiveXcode? . realtimeProjectURL ?? activeWorkspaceURL
7677 }
7778
@@ -192,7 +193,7 @@ public final class XcodeInspector: ObservableObject {
192193 xcode. $documentURL. sink { [ weak self] url in
193194 self ? . activeDocumentURL = url
194195 } . store ( in: & activeXcodeCancellable)
195-
196+
196197 xcode. $workspaceURL. sink { [ weak self] url in
197198 self ? . activeWorkspaceURL = url
198199 } . store ( in: & activeXcodeCancellable)
@@ -224,9 +225,9 @@ public class AppInstanceInspector: ObservableObject {
224225
225226public final class XcodeAppInstanceInspector : AppInstanceInspector {
226227 @Published public var focusedWindow : XcodeWindowInspector ?
227- @Published public var documentURL : URL = . init ( fileURLWithPath : " / " )
228- @Published public var workspaceURL : URL = . init ( fileURLWithPath : " / " )
229- @Published public var projectRootURL : URL = . init ( fileURLWithPath : " / " )
228+ @Published public var documentURL : URL ? = nil
229+ @Published public var workspaceURL : URL ? = nil
230+ @Published public var projectRootURL : URL ? = nil
230231 @Published public var workspaces = [ WorkspaceIdentifier: Workspace] ( )
231232 public var realtimeWorkspaces : [ WorkspaceIdentifier : WorkspaceInfo ] {
232233 updateWorkspaceInfo ( )
@@ -238,25 +239,21 @@ public final class XcodeAppInstanceInspector: AppInstanceInspector {
238239 public var realtimeDocumentURL : URL ? {
239240 guard let window = appElement. focusedWindow,
240241 window. identifier == " Xcode.WorkspaceWindow "
241- else {
242- return nil
243- }
242+ else { return nil }
244243
245244 return WorkspaceXcodeWindowInspector . extractDocumentURL ( windowElement: window)
246245 }
247-
246+
248247 public var realtimeWorkspaceURL : URL ? {
249248 guard let window = appElement. focusedWindow,
250249 window. identifier == " Xcode.WorkspaceWindow "
251- else {
252- return nil
253- }
250+ else { return nil }
254251
255252 return WorkspaceXcodeWindowInspector . extractWorkspaceURL ( windowElement: window)
256253 }
257-
254+
258255 public var realtimeProjectURL : URL ? {
259- guard let window = appElement. focusedWindow else { return URL ( fileURLWithPath : " / " ) }
256+ guard let window = appElement. focusedWindow else { return nil }
260257 let workspaceURL = realtimeWorkspaceURL
261258 let documentURL = realtimeDocumentURL
262259 return WorkspaceXcodeWindowInspector . extractProjectURL (
0 commit comments