Skip to content

Commit cae8a8b

Browse files
committed
lint: fix formatting
1 parent 3b5d997 commit cae8a8b

File tree

2 files changed

+87
-85
lines changed

2 files changed

+87
-85
lines changed

Sources/SourceKitLSP/Swift/SemanticTokens.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extension SwiftLanguageService {
3535
guard let skTokens: SKDResponseArray = dict[keys.semanticTokens] else {
3636
return nil
3737
}
38-
38+
3939
return SyntaxHighlightingTokenParser(sourcekitd: sourcekitd).parseTokens(skTokens, in: snapshot)
4040
}
4141

@@ -60,8 +60,8 @@ extension SwiftLanguageService {
6060
} else {
6161
ByteSourceRange(offset: 0, length: await tree.totalLength.utf8Length)
6262
}
63-
64-
let tokens =
63+
64+
let tokens =
6565
await tree
6666
.classifications(in: range)
6767
.flatMap({ $0.highlightingTokens(in: snapshot) })

Sources/SourceKitLSP/Swift/SyntaxHighlightingTokens.swift

Lines changed: 84 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -16,91 +16,93 @@ import SourceKitD
1616

1717
/// A wrapper around an array of syntax highlighting tokens.
1818
public struct SyntaxHighlightingTokens {
19-
public var tokens: [SyntaxHighlightingToken]
20-
21-
public init(tokens: [SyntaxHighlightingToken]) {
22-
self.tokens = tokens
23-
}
24-
25-
/// The LSP representation of syntax highlighting tokens. Note that this
26-
/// requires the tokens in this array to be sorted.
27-
public var lspEncoded: [UInt32] {
28-
var previous = Position(line: 0, utf16index: 0)
29-
var rawTokens: [UInt32] = []
30-
rawTokens.reserveCapacity(count * 5)
31-
32-
for token in self.tokens {
33-
let lineDelta = token.start.line - previous.line
34-
let charDelta =
35-
token.start.utf16index - (
36-
// The character delta is relative to the previous token's start
37-
// only if the token is on the previous token's line.
38-
previous.line == token.start.line ? previous.utf16index : 0)
39-
40-
// We assert that the tokens are actually sorted
41-
assert(lineDelta >= 0)
42-
assert(charDelta >= 0)
43-
44-
previous = token.start
45-
rawTokens += [
46-
UInt32(lineDelta),
47-
UInt32(charDelta),
48-
UInt32(token.utf16length),
49-
token.kind.tokenType,
50-
token.modifiers.rawValue,
51-
]
52-
}
53-
54-
return rawTokens
19+
public var tokens: [SyntaxHighlightingToken]
20+
21+
public init(tokens: [SyntaxHighlightingToken]) {
22+
self.tokens = tokens
23+
}
24+
25+
/// The LSP representation of syntax highlighting tokens. Note that this
26+
/// requires the tokens in this array to be sorted.
27+
public var lspEncoded: [UInt32] {
28+
var previous = Position(line: 0, utf16index: 0)
29+
var rawTokens: [UInt32] = []
30+
rawTokens.reserveCapacity(count * 5)
31+
32+
for token in self.tokens {
33+
let lineDelta = token.start.line - previous.line
34+
let charDelta =
35+
token.start.utf16index - (
36+
// The character delta is relative to the previous token's start
37+
// only if the token is on the previous token's line.
38+
previous.line == token.start.line ? previous.utf16index : 0)
39+
40+
// We assert that the tokens are actually sorted
41+
assert(lineDelta >= 0)
42+
assert(charDelta >= 0)
43+
44+
previous = token.start
45+
rawTokens += [
46+
UInt32(lineDelta),
47+
UInt32(charDelta),
48+
UInt32(token.utf16length),
49+
token.kind.tokenType,
50+
token.modifiers.rawValue,
51+
]
5552
}
5653

57-
/// Merges the tokens in this array into a new token array,
58-
/// preferring the given array's tokens if duplicate ranges are
59-
/// found.
60-
public func mergingTokens(with other: SyntaxHighlightingTokens) -> SyntaxHighlightingTokens {
61-
let otherRanges = Set(other.tokens.map(\.range))
62-
return SyntaxHighlightingTokens(tokens: tokens.filter { !otherRanges.contains($0.range) } + other.tokens)
63-
}
64-
65-
/// Sorts the tokens in this array by their start position.
66-
public func sorted(_ areInIncreasingOrder: (SyntaxHighlightingToken, SyntaxHighlightingToken) -> Bool) -> SyntaxHighlightingTokens {
67-
SyntaxHighlightingTokens(tokens: tokens.sorted(by: areInIncreasingOrder))
68-
}
54+
return rawTokens
55+
}
56+
57+
/// Merges the tokens in this array into a new token array,
58+
/// preferring the given array's tokens if duplicate ranges are
59+
/// found.
60+
public func mergingTokens(with other: SyntaxHighlightingTokens) -> SyntaxHighlightingTokens {
61+
let otherRanges = Set(other.tokens.map(\.range))
62+
return SyntaxHighlightingTokens(tokens: tokens.filter { !otherRanges.contains($0.range) } + other.tokens)
63+
}
64+
65+
/// Sorts the tokens in this array by their start position.
66+
public func sorted(_ areInIncreasingOrder: (SyntaxHighlightingToken, SyntaxHighlightingToken) -> Bool)
67+
-> SyntaxHighlightingTokens
68+
{
69+
SyntaxHighlightingTokens(tokens: tokens.sorted(by: areInIncreasingOrder))
70+
}
6971
}
7072

7173
extension SyntaxHighlightingTokens {
72-
/// Decodes the LSP representation of syntax highlighting tokens
73-
public init(lspEncodedTokens rawTokens: [UInt32]) {
74-
self.init(tokens: [])
75-
assert(rawTokens.count.isMultiple(of: 5))
76-
reserveCapacity(rawTokens.count / 5)
77-
78-
var current = Position(line: 0, utf16index: 0)
79-
80-
for i in stride(from: 0, to: rawTokens.count, by: 5) {
81-
let lineDelta = Int(rawTokens[i])
82-
let charDelta = Int(rawTokens[i + 1])
83-
let length = Int(rawTokens[i + 2])
84-
let rawKind = rawTokens[i + 3]
85-
let rawModifiers = rawTokens[i + 4]
86-
87-
current.line += lineDelta
88-
89-
if lineDelta == 0 {
90-
current.utf16index += charDelta
91-
} else {
92-
current.utf16index = charDelta
93-
}
94-
95-
let kind = SemanticTokenTypes.all[Int(rawKind)]
96-
let modifiers = SemanticTokenModifiers(rawValue: rawModifiers)
97-
98-
self.tokens += SyntaxHighlightingToken(
99-
start: current,
100-
utf16length: length,
101-
kind: kind,
102-
modifiers: modifiers
103-
)
104-
}
74+
/// Decodes the LSP representation of syntax highlighting tokens
75+
public init(lspEncodedTokens rawTokens: [UInt32]) {
76+
self.init(tokens: [])
77+
assert(rawTokens.count.isMultiple(of: 5))
78+
reserveCapacity(rawTokens.count / 5)
79+
80+
var current = Position(line: 0, utf16index: 0)
81+
82+
for i in stride(from: 0, to: rawTokens.count, by: 5) {
83+
let lineDelta = Int(rawTokens[i])
84+
let charDelta = Int(rawTokens[i + 1])
85+
let length = Int(rawTokens[i + 2])
86+
let rawKind = rawTokens[i + 3]
87+
let rawModifiers = rawTokens[i + 4]
88+
89+
current.line += lineDelta
90+
91+
if lineDelta == 0 {
92+
current.utf16index += charDelta
93+
} else {
94+
current.utf16index = charDelta
95+
}
96+
97+
let kind = SemanticTokenTypes.all[Int(rawKind)]
98+
let modifiers = SemanticTokenModifiers(rawValue: rawModifiers)
99+
100+
self.tokens += SyntaxHighlightingToken(
101+
start: current,
102+
utf16length: length,
103+
kind: kind,
104+
modifiers: modifiers
105+
)
105106
}
106-
}
107+
}
108+
}

0 commit comments

Comments
 (0)