forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiFileContextManager.swift
More file actions
30 lines (27 loc) · 1.14 KB
/
MultiFileContextManager.swift
File metadata and controls
30 lines (27 loc) · 1.14 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
import Foundation
import Workspace
import XcodeInspector
class MultiFileContextManager {
let workspaceProvider: WorkspaceProvider
init(workspaceProvider: WorkspaceProvider) {
self.workspaceProvider = workspaceProvider
}
/// List files within workspace recursively
/// Retrieved from: https://stackoverflow.com/a/57640445
func listFilesInWorkspace() async -> [String] {
guard let workspace: Workspace = try? await workspaceProvider.workspace()
else { return [] }
var files = [String]()
if let enumerator = FileManager.default.enumerator(at: workspace.projectRootURL, includingPropertiesForKeys: [.isRegularFileKey], options: [.skipsHiddenFiles, .skipsPackageDescendants]) {
for case let fileURL as URL in enumerator {
do {
let fileAttributes = try fileURL.resourceValues(forKeys: [.isRegularFileKey])
if fileAttributes.isRegularFile! {
files.append(fileURL.absoluteString)
}
} catch { print(error, fileURL) }
}
}
return files
}
}