Skip to content

Commit 1f94eca

Browse files
johnfairhnkcsgexi
authored andcommitted
[SourceKit] Add typealias to doc structure (#11143)
From https://bugs.swift.org/browse/SR-4828
1 parent 2f0dafb commit 1f94eca

File tree

7 files changed

+89
-0
lines changed

7 files changed

+89
-0
lines changed

include/swift/IDE/SyntaxModel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ enum class SyntaxStructureKind : uint8_t {
9292
ClassVariable,
9393
EnumCase,
9494
EnumElement,
95+
TypeAlias,
9596

9697
ForEachStatement,
9798
ForStatement,

lib/IDE/SyntaxModel.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,16 @@ bool ModelASTWalker::walkToDeclPre(Decl *D) {
954954
popStructureNode();
955955
}
956956
}
957+
} else if (auto *TypeAliasD = dyn_cast<TypeAliasDecl>(D)) {
958+
SyntaxStructureNode SN;
959+
SN.Dcl = TypeAliasD;
960+
SN.Kind = SyntaxStructureKind::TypeAlias;
961+
SN.Range = charSourceRangeFromSourceRange(SM,
962+
TypeAliasD->getSourceRange());
963+
SN.NameRange = CharSourceRange(TypeAliasD->getNameLoc(),
964+
TypeAliasD->getName().getLength());
965+
SN.Attrs = TypeAliasD->getAttrs();
966+
pushStructureNode(SN, TypeAliasD);
957967
}
958968

959969
return true;

test/IDE/structure.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,6 @@ class A {
184184
func perform() {foo(5, animations: {})}
185185
// CHECK: <ifunc>func <name>perform()</name> {<call><name>foo</name>(<arg>5</arg>, <arg><name>animations</name>: <brace>{}</brace></arg>)</call>}</ifunc>
186186
}
187+
188+
// CHECK: <typealias>typealias <name>OtherA</name> = A</typealias>
189+
typealias OtherA = A

test/SourceKit/DocumentStructure/access_parse.swift.response

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,42 @@
650650
key.bodylength: 0
651651
}
652652
]
653+
},
654+
{
655+
key.kind: source.lang.swift.decl.typealias,
656+
key.accessibility: source.lang.swift.accessibility.internal,
657+
key.name: "defAlias",
658+
key.offset: 1633,
659+
key.length: 24,
660+
key.nameoffset: 1643,
661+
key.namelength: 8
662+
},
663+
{
664+
key.kind: source.lang.swift.decl.typealias,
665+
key.accessibility: source.lang.swift.accessibility.public,
666+
key.name: "pubAlias",
667+
key.offset: 1665,
668+
key.length: 24,
669+
key.nameoffset: 1675,
670+
key.namelength: 8
671+
},
672+
{
673+
key.kind: source.lang.swift.decl.typealias,
674+
key.accessibility: source.lang.swift.accessibility.private,
675+
key.name: "privAlias",
676+
key.offset: 1698,
677+
key.length: 25,
678+
key.nameoffset: 1708,
679+
key.namelength: 9
680+
},
681+
{
682+
key.kind: source.lang.swift.decl.typealias,
683+
key.accessibility: source.lang.swift.accessibility.internal,
684+
key.name: "intAlias",
685+
key.offset: 1733,
686+
key.length: 24,
687+
key.nameoffset: 1743,
688+
key.namelength: 8
653689
}
654690
]
655691
}

test/SourceKit/InterfaceGen/gen_clang_module.swift.response

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4632,6 +4632,15 @@ public class FooOverlayClassDerived : Foo.FooOverlayClassBase {
46324632
}
46334633
]
46344634
},
4635+
{
4636+
key.kind: source.lang.swift.decl.typealias,
4637+
key.accessibility: source.lang.swift.accessibility.public,
4638+
key.name: "FooStruct1Pointer",
4639+
key.offset: 1543,
4640+
key.length: 62,
4641+
key.nameoffset: 1553,
4642+
key.namelength: 17
4643+
},
46354644
{
46364645
key.kind: source.lang.swift.decl.struct,
46374646
key.accessibility: source.lang.swift.accessibility.public,
@@ -4705,6 +4714,15 @@ public class FooOverlayClassDerived : Foo.FooOverlayClassBase {
47054714
}
47064715
]
47074716
},
4717+
{
4718+
key.kind: source.lang.swift.decl.typealias,
4719+
key.accessibility: source.lang.swift.accessibility.public,
4720+
key.name: "FooStructTypedef1",
4721+
key.offset: 1751,
4722+
key.length: 40,
4723+
key.nameoffset: 1761,
4724+
key.namelength: 17
4725+
},
47084726
{
47094727
key.kind: source.lang.swift.decl.struct,
47104728
key.accessibility: source.lang.swift.accessibility.public,
@@ -4778,6 +4796,15 @@ public class FooOverlayClassDerived : Foo.FooOverlayClassBase {
47784796
}
47794797
]
47804798
},
4799+
{
4800+
key.kind: source.lang.swift.decl.typealias,
4801+
key.accessibility: source.lang.swift.accessibility.public,
4802+
key.name: "FooTypedef1",
4803+
key.offset: 1974,
4804+
key.length: 29,
4805+
key.nameoffset: 1984,
4806+
key.namelength: 11
4807+
},
47814808
{
47824809
key.kind: source.lang.swift.decl.var.global,
47834810
key.accessibility: source.lang.swift.accessibility.public,
@@ -5348,6 +5375,15 @@ public class FooOverlayClassDerived : Foo.FooOverlayClassBase {
53485375
}
53495376
]
53505377
},
5378+
{
5379+
key.kind: source.lang.swift.decl.typealias,
5380+
key.accessibility: source.lang.swift.accessibility.public,
5381+
key.name: "typedef_int_t",
5382+
key.offset: 4624,
5383+
key.length: 31,
5384+
key.nameoffset: 4634,
5385+
key.namelength: 13
5386+
},
53515387
{
53525388
key.kind: source.lang.swift.decl.var.global,
53535389
key.accessibility: source.lang.swift.accessibility.public,

tools/SourceKit/lib/SwiftLang/SwiftLangSupport.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ UIdent SwiftLangSupport::getUIDForSyntaxStructureKind(
375375
return KindDeclEnumCase;
376376
case SyntaxStructureKind::EnumElement:
377377
return KindDeclEnumElement;
378+
case SyntaxStructureKind::TypeAlias:
379+
return KindDeclTypeAlias;
378380
case SyntaxStructureKind::Parameter:
379381
return KindDeclVarParam;
380382
case SyntaxStructureKind::ForEachStatement:

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,7 @@ class StructureAnnotator : public ide::SyntaxModelWalker {
10691069
case SyntaxStructureKind::ClassVariable: return "cvar";
10701070
case SyntaxStructureKind::EnumCase: return "enum-case";
10711071
case SyntaxStructureKind::EnumElement: return "enum-elem";
1072+
case SyntaxStructureKind::TypeAlias: return "typealias";
10721073
case SyntaxStructureKind::Parameter: return "param";
10731074
case SyntaxStructureKind::ForEachStatement: return "foreach";
10741075
case SyntaxStructureKind::ForStatement: return "for";

0 commit comments

Comments
 (0)