-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathCustomCopilotHelper.swift
More file actions
64 lines (53 loc) · 1.73 KB
/
CustomCopilotHelper.swift
File metadata and controls
64 lines (53 loc) · 1.73 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import AppKit
import Client
import Foundation
import SwiftUI
import Toast
import XcodeInspector
import SystemUtils
import SharedUIComponents
import Workspace
import LanguageServerProtocol
// MARK: - Workspace URL Helpers
private func getCurrentWorkspaceURL() async -> URL? {
guard let service = try? getService(),
let inspectorData = try? await service.getXcodeInspectorData() else {
return nil
}
if let url = inspectorData.realtimeActiveWorkspaceURL,
let workspaceURL = URL(string: url),
workspaceURL.path != "/" {
return workspaceURL
} else if let url = inspectorData.latestNonRootWorkspaceURL {
return URL(string: url)
}
return nil
}
func getCurrentProjectURL() async -> URL? {
guard let workspaceURL = await getCurrentWorkspaceURL(),
let projectURL = WorkspaceXcodeWindowInspector.extractProjectURL(
workspaceURL: workspaceURL,
documentURL: nil
) else {
return nil
}
return projectURL
}
// MARK: - Workspace Folders
func getWorkspaceFolders() async -> [WorkspaceFolder]? {
guard let workspaceURL = await getCurrentWorkspaceURL(),
let workspaceInfo = WorkspaceFile.getWorkspaceInfo(workspaceURL: workspaceURL) else {
return nil
}
let projects = WorkspaceFile.getProjects(workspace: workspaceInfo)
return projects.map { project in
WorkspaceFolder(uri: project.uri, name: project.name)
}
}
// MARK: - File System Helpers
func ensureDirectoryExists(at url: URL) throws {
let fileManager = FileManager.default
if !fileManager.fileExists(atPath: url.path) {
try fileManager.createDirectory(at: url, withIntermediateDirectories: true, attributes: nil)
}
}