forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.swift
More file actions
42 lines (38 loc) · 1.25 KB
/
Utils.swift
File metadata and controls
42 lines (38 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import AppKit
import AppKitExtension
import Foundation
import Logger
import XcodeInspector
class Utils {
public static func openFileInXcode(
fileURL: URL,
completion: ((NSRunningApplication?, Error?) -> Void)? = nil
) {
guard let xcodeBundleURL = NSWorkspace.getXcodeBundleURL()
else {
if let completion = completion {
completion(nil, NSError(domain: "The Xcode app is not found.", code: 0))
}
return
}
let configuration = NSWorkspace.OpenConfiguration()
configuration.activates = true
NSWorkspace.shared.open(
[fileURL],
withApplicationAt: xcodeBundleURL,
configuration: configuration
) { app, error in
if let completion = completion {
completion(app, error)
} else if let error = error {
Logger.client.error("Failed to open file \(String(describing: error))")
}
}
}
public static func getXcode(by workspacePath: String) -> XcodeAppInstanceInspector? {
return XcodeInspector.shared.xcodes.first(
where: {
$0.workspaceURL?.path == workspacePath
})
}
}