1+ import Dependencies
12import Environment
23import Foundation
4+ import GitIgnoreCheck
35import SuggestionModel
46
57public protocol FilespacePropertyKey {
@@ -47,20 +49,34 @@ public struct FilespaceCodeMetadata: Equatable {
4749
4850@dynamicMemberLookup
4951public final class Filespace {
52+ struct GitIgnoreStatus {
53+ var isIgnored : Bool
54+ var checkTime : Date
55+ var isExpired : Bool {
56+ Environment . now ( ) . timeIntervalSince ( checkTime) > 60 * 3
57+ }
58+ }
59+
60+ // MARK: Metadata
61+
5062 public let fileURL : URL
5163 public private( set) lazy var language : CodeLanguage = languageIdentifierFromFileURL ( fileURL)
5264 public var codeMetadata : FilespaceCodeMetadata = . init( )
65+
66+ // MARK: Suggestions
67+
68+ public private( set) var suggestionIndex : Int = 0
5369 public internal( set) var suggestions : [ CodeSuggestion ] = [ ] {
5470 didSet { refreshUpdateTime ( ) }
5571 }
5672
57- public private( set) var suggestionIndex : Int = 0
58-
5973 public var presentingSuggestion : CodeSuggestion ? {
6074 guard suggestions. endIndex > suggestionIndex, suggestionIndex >= 0 else { return nil }
6175 return suggestions [ suggestionIndex]
6276 }
6377
78+ // MARK: Life Cycle
79+
6480 public var isExpired : Bool {
6581 Environment . now ( ) . timeIntervalSince ( lastSuggestionUpdateTime) > 60 * 3
6682 }
@@ -70,6 +86,25 @@ public final class Filespace {
7086 let fileSaveWatcher : FileSaveWatcher
7187 let onClose : ( URL ) -> Void
7288
89+ // MARK: Git Ignore
90+
91+ private var gitIgnoreStatus : GitIgnoreStatus ?
92+ public var isGitIgnored : Bool {
93+ get async {
94+ @Dependency ( \. gitIgnoredChecker) var gitIgnoredChecker
95+ @Dependency ( \. date) var date
96+
97+ if let gitIgnoreStatus = gitIgnoreStatus, !gitIgnoreStatus. isExpired {
98+ return gitIgnoreStatus. isIgnored
99+ }
100+ let isIgnored = await gitIgnoredChecker. checkIfGitIgnored ( fileURL: fileURL)
101+ gitIgnoreStatus = . init( isIgnored: isIgnored, checkTime: date ( ) )
102+ return isIgnored
103+ }
104+ }
105+
106+ // MARK: Methods
107+
73108 deinit {
74109 onClose ( fileURL)
75110 }
0 commit comments