@@ -7,7 +7,6 @@ public protocol FilespacePropertyKey {
77 static func createDefaultValue( ) -> Value
88}
99
10- @WorkspaceActor
1110public final class FilespacePropertyValues {
1211 var storage : [ ObjectIdentifier : Any ] = [ : ]
1312
@@ -26,16 +25,35 @@ public final class FilespacePropertyValues {
2625 }
2726}
2827
29- @WorkspaceActor
28+ public struct FilespaceCodeMetadata : Equatable {
29+ public var uti : String ?
30+ public var tabSize : Int ?
31+ public var indentSize : Int ?
32+ public var usesTabsForIndentation : Bool ?
33+
34+ init (
35+ uti: String ? = nil ,
36+ tabSize: Int ? = nil ,
37+ indentSize: Int ? = nil ,
38+ usesTabsForIndentation: Bool ? = nil
39+ ) {
40+ self . uti = uti
41+ self . tabSize = tabSize
42+ self . indentSize = indentSize
43+ self . usesTabsForIndentation = usesTabsForIndentation
44+ }
45+ }
46+
3047@dynamicMemberLookup
3148public final class Filespace {
3249 public let fileURL : URL
3350 public private( set) lazy var language : String = languageIdentifierFromFileURL ( fileURL) . rawValue
34- public var suggestions : [ CodeSuggestion ] = [ ] {
51+ public var codeMetadata : FilespaceCodeMetadata = . init( )
52+ public private( set) var suggestions : [ CodeSuggestion ] = [ ] {
3553 didSet { refreshUpdateTime ( ) }
3654 }
3755
38- public var suggestionIndex : Int = 0
56+ public private ( set ) var suggestionIndex : Int = 0
3957
4058 public var presentingSuggestion : CodeSuggestion ? {
4159 guard suggestions. endIndex > suggestionIndex, suggestionIndex >= 0 else { return nil }
@@ -45,7 +63,7 @@ public final class Filespace {
4563 public var isExpired : Bool {
4664 Environment . now ( ) . timeIntervalSince ( lastSuggestionUpdateTime) > 60 * 3
4765 }
48-
66+
4967 private( set) var lastSuggestionUpdateTime : Date = Environment . now ( )
5068 var additionalProperties = FilespacePropertyValues ( )
5169 let fileSaveWatcher : FileSaveWatcher
@@ -68,14 +86,15 @@ public final class Filespace {
6886 onSave ( self )
6987 }
7088 }
71-
89+
7290 public subscript< K> (
7391 dynamicMember dynamicMember: WritableKeyPath < FilespacePropertyValues , K >
7492 ) -> K {
7593 get { additionalProperties [ keyPath: dynamicMember] }
7694 set { additionalProperties [ keyPath: dynamicMember] = newValue }
7795 }
7896
97+ @WorkspaceActor
7998 public func reset( ) {
8099 suggestions = [ ]
81100 suggestionIndex = 0
@@ -84,5 +103,27 @@ public final class Filespace {
84103 public func refreshUpdateTime( ) {
85104 lastSuggestionUpdateTime = Environment . now ( )
86105 }
106+
107+ @WorkspaceActor
108+ public func setSuggestions( _ suggestions: [ CodeSuggestion ] ) {
109+ self . suggestions = suggestions
110+ suggestionIndex = 0
111+ }
112+
113+ @WorkspaceActor
114+ public func nextSuggestion( ) {
115+ suggestionIndex += 1
116+ if suggestionIndex >= suggestions. endIndex {
117+ suggestionIndex = 0
118+ }
119+ }
120+
121+ @WorkspaceActor
122+ public func previousSuggestion( ) {
123+ suggestionIndex -= 1
124+ if suggestionIndex < 0 {
125+ suggestionIndex = suggestions. endIndex - 1
126+ }
127+ }
87128}
88129
0 commit comments