File tree Expand file tree Collapse file tree 2 files changed +17
-13
lines changed
Sources/SourceKitLSP/Swift Expand file tree Collapse file tree 2 files changed +17
-13
lines changed Original file line number Diff line number Diff line change @@ -180,7 +180,9 @@ fileprivate final class DocumentSymbolsFinder: SyntaxAnyVisitor {
180
180
// If there is only one pattern binding within the variable decl, consider the entire variable decl as the
181
181
// referenced range. If there are multiple, consider each pattern binding separately since the `var` keyword doesn't
182
182
// belong to any pattern binding in particular.
183
- guard let variableDecl = node. parent? . parent? . as ( VariableDeclSyntax . self) else {
183
+ guard let variableDecl = node. parent? . parent? . as ( VariableDeclSyntax . self) ,
184
+ variableDecl. isMemberOrTopLevelDeclaration
185
+ else {
184
186
return . visitChildren
185
187
}
186
188
let rangeNode : Syntax = variableDecl. bindings. count == 1 ? Syntax ( variableDecl) : Syntax ( node)
@@ -228,6 +230,19 @@ fileprivate extension SyntaxProtocol {
228
230
var rangeWithoutTrivia : Range < AbsolutePosition > {
229
231
return positionAfterSkippingLeadingTrivia..< endPositionBeforeTrailingTrivia
230
232
}
233
+
234
+ /// Whether this is a top-level constant or a member of a type, ie. if this is not a local variable.
235
+ var isMemberOrTopLevelDeclaration : Bool {
236
+ if self . parent? . is ( MemberBlockItemSyntax . self) ?? false {
237
+ return true
238
+ } else if let codeBlockItem = self . parent? . as ( CodeBlockItemSyntax . self) ,
239
+ codeBlockItem. parent? . parent? . is ( SourceFileSyntax . self) ?? false
240
+ {
241
+ return true
242
+ } else {
243
+ return false
244
+ }
245
+ }
231
246
}
232
247
233
248
fileprivate extension TokenKind {
Original file line number Diff line number Diff line change @@ -571,7 +571,6 @@ final class DocumentSymbolTests: XCTestCase {
571
571
try await assertDocumentSymbols (
572
572
"""
573
573
1️⃣func 2️⃣f()3️⃣ {
574
- 4️⃣let 5️⃣localConstant6️⃣ = 07️⃣
575
574
}8️⃣
576
575
"""
577
576
) { positions in
@@ -583,17 +582,7 @@ final class DocumentSymbolTests: XCTestCase {
583
582
deprecated: nil ,
584
583
range: positions [ " 1️⃣ " ] ..< positions [ " 8️⃣ " ] ,
585
584
selectionRange: positions [ " 2️⃣ " ] ..< positions [ " 3️⃣ " ] ,
586
- children: [
587
- DocumentSymbol (
588
- name: " localConstant " ,
589
- detail: nil ,
590
- kind: . variable,
591
- deprecated: nil ,
592
- range: positions [ " 4️⃣ " ] ..< positions [ " 7️⃣ " ] ,
593
- selectionRange: positions [ " 5️⃣ " ] ..< positions [ " 6️⃣ " ] ,
594
- children: [ ]
595
- )
596
- ]
585
+ children: [ ]
597
586
)
598
587
]
599
588
}
You can’t perform that action at this time.
0 commit comments