File tree 2 files changed +46
-2
lines changed
Sources/SourceKitLSP/Swift 2 files changed +46
-2
lines changed Original file line number Diff line number Diff line change @@ -247,7 +247,7 @@ fileprivate final class DocumentSymbolsFinder: SyntaxAnyVisitor {
247
247
override func visit( _ node: InitializerDeclSyntax ) -> SyntaxVisitorContinueKind {
248
248
return record (
249
249
node: node,
250
- name: node. initKeyword . text ,
250
+ name: node. declName ,
251
251
symbolKind: . constructor,
252
252
range: node. rangeWithoutTrivia,
253
253
selection: node. initKeyword
@@ -304,6 +304,18 @@ fileprivate extension FunctionDeclSyntax {
304
304
}
305
305
}
306
306
307
+ fileprivate extension InitializerDeclSyntax {
308
+ var declName : String {
309
+ var result = self . initKeyword. text
310
+ result += " ( "
311
+ for parameter in self . signature. parameterClause. parameters {
312
+ result += " \( parameter. firstName. text) : "
313
+ }
314
+ result += " ) "
315
+ return result
316
+ }
317
+ }
318
+
307
319
fileprivate extension SyntaxProtocol {
308
320
/// The position range of this node without its leading and trailing trivia.
309
321
var rangeWithoutTrivia : Range < AbsolutePosition > {
Original file line number Diff line number Diff line change @@ -552,7 +552,39 @@ final class DocumentSymbolTests: XCTestCase {
552
552
selectionRange: positions [ " 2️⃣ " ] ..< positions [ " 3️⃣ " ] ,
553
553
children: [
554
554
DocumentSymbol (
555
- name: " init " ,
555
+ name: " init() " ,
556
+ detail: nil ,
557
+ kind: . constructor,
558
+ deprecated: nil ,
559
+ range: positions [ " 4️⃣ " ] ..< positions [ " 6️⃣ " ] ,
560
+ selectionRange: positions [ " 4️⃣ " ] ..< positions [ " 5️⃣ " ] ,
561
+ children: [ ]
562
+ )
563
+ ]
564
+ )
565
+ ]
566
+ }
567
+ }
568
+
569
+ func testInitializerWithParameters( ) async throws {
570
+ try await assertDocumentSymbols (
571
+ """
572
+ 1️⃣class 2️⃣Foo3️⃣ {
573
+ 4️⃣init(_ first: Int, second: Int)5️⃣ { }6️⃣
574
+ }7️⃣
575
+ """
576
+ ) { positions in
577
+ [
578
+ DocumentSymbol (
579
+ name: " Foo " ,
580
+ detail: nil ,
581
+ kind: . class,
582
+ deprecated: nil ,
583
+ range: positions [ " 1️⃣ " ] ..< positions [ " 7️⃣ " ] ,
584
+ selectionRange: positions [ " 2️⃣ " ] ..< positions [ " 3️⃣ " ] ,
585
+ children: [
586
+ DocumentSymbol (
587
+ name: " init(_:second:) " ,
556
588
detail: nil ,
557
589
kind: . constructor,
558
590
deprecated: nil ,
You can’t perform that action at this time.
0 commit comments