Skip to content

Commit

Permalink
Restore TokenApplication.Action facility
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Jan 28, 2024
1 parent b024a31 commit e27baf2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
17 changes: 9 additions & 8 deletions Sources/Neon/Token.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@ extension Token: CustomDebugStringConvertible {
}

public struct TokenApplication: Hashable, Sendable {
public enum Action: Sendable, Hashable {
case replace
case apply
}

public let tokens: [Token]
public let range: NSRange?
public let action: Action

public init(tokens: [Token], range: NSRange? = nil) {
public init(tokens: [Token], range: NSRange? = nil, action: Action = .replace) {
self.tokens = tokens
self.range = range
self.action = action
}
}

extension TokenApplication: ExpressibleByArrayLiteral {
public typealias ArrayLiteralElement = Token

public init(arrayLiteral elements: Token...) {
self.init(tokens: elements)
}
public static let noChange = TokenApplication(tokens: [], action: .apply)
}

public typealias TokenProvider = HybridValueProvider<NSRange, TokenApplication>
Expand Down
4 changes: 2 additions & 2 deletions Sources/Neon/TreeSitterClient+Neon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extension TreeSitterClient {

return TokenApplication(namedRanges: namedRanges, nameMap: nameMap, range: range)
} catch {
return []
return .noChange
}
},
mainActorAsyncValue: { [highlightsProvider] range in
Expand All @@ -38,7 +38,7 @@ extension TreeSitterClient {

return TokenApplication(namedRanges: namedRanges, nameMap: nameMap, range: range)
} catch {
return []
return .noChange
}
}
)
Expand Down

0 comments on commit e27baf2

Please sign in to comment.