File tree Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -24,11 +24,7 @@ public struct DocumentSnapshot {
24
24
25
25
public var text : String { lineTable. content }
26
26
27
- public var allTokens : [ SemanticToken ] {
28
- // Only pick syntactic tokens for which no semantic token exists
29
- let semaRanges = Set ( semanticTokens. map ( \. range) )
30
- return syntacticTokens. filter { !semaRanges. contains ( $0. range) } + semanticTokens
31
- }
27
+ public var allTokens : [ SemanticToken ] { mergeSemanticTokens ( syntacticTokens, semanticTokens) }
32
28
public var sortedTokens : [ SemanticToken ] { allTokens. sorted { $0. start < $1. start } }
33
29
34
30
public init (
Original file line number Diff line number Diff line change @@ -204,6 +204,14 @@ public func decodeFromIntArray(rawSemanticTokens rawTokens: [UInt32]) -> [Semant
204
204
return tokens
205
205
}
206
206
207
+ /// Merges the given token arrays into a new token array,
208
+ /// preferring the second array's tokens if duplicate ranges are
209
+ /// found.
210
+ public func mergeSemanticTokens( _ lhs: [ SemanticToken ] , _ rhs: [ SemanticToken ] ) -> [ SemanticToken ] {
211
+ let rhsRanges = Set ( rhs. map ( \. range) )
212
+ return lhs. filter { !rhsRanges. contains ( $0. range) } + rhs
213
+ }
214
+
207
215
/// Parses semantic tokens from sourcekitd response dictionaries.
208
216
struct SemanticTokenParser {
209
217
private let sourcekitd : SourceKitD
You can’t perform that action at this time.
0 commit comments