Skip to content

[SourceKit] Add typealias to doc structure - SR-4828 #11143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/swift/IDE/SyntaxModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ enum class SyntaxStructureKind : uint8_t {
ClassVariable,
EnumCase,
EnumElement,
TypeAlias,

ForEachStatement,
ForStatement,
Expand Down
10 changes: 10 additions & 0 deletions lib/IDE/SyntaxModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,16 @@ bool ModelASTWalker::walkToDeclPre(Decl *D) {
popStructureNode();
}
}
} else if (auto *TypeAliasD = dyn_cast<TypeAliasDecl>(D)) {
SyntaxStructureNode SN;
SN.Dcl = TypeAliasD;
SN.Kind = SyntaxStructureKind::TypeAlias;
SN.Range = charSourceRangeFromSourceRange(SM,
TypeAliasD->getSourceRange());
SN.NameRange = CharSourceRange(TypeAliasD->getNameLoc(),
TypeAliasD->getName().getLength());
SN.Attrs = TypeAliasD->getAttrs();
pushStructureNode(SN, TypeAliasD);
}

return true;
Expand Down
3 changes: 3 additions & 0 deletions test/IDE/structure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,6 @@ class A {
func perform() {foo(5, animations: {})}
// CHECK: <ifunc>func <name>perform()</name> {<call><name>foo</name>(<arg>5</arg>, <arg><name>animations</name>: <brace>{}</brace></arg>)</call>}</ifunc>
}

// CHECK: <typealias>typealias <name>OtherA</name> = A</typealias>
typealias OtherA = A
36 changes: 36 additions & 0 deletions test/SourceKit/DocumentStructure/access_parse.swift.response
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,42 @@
key.bodylength: 0
}
]
},
{
key.kind: source.lang.swift.decl.typealias,
key.accessibility: source.lang.swift.accessibility.internal,
key.name: "defAlias",
key.offset: 1633,
key.length: 24,
key.nameoffset: 1643,
key.namelength: 8
},
{
key.kind: source.lang.swift.decl.typealias,
key.accessibility: source.lang.swift.accessibility.public,
key.name: "pubAlias",
key.offset: 1665,
key.length: 24,
key.nameoffset: 1675,
key.namelength: 8
},
{
key.kind: source.lang.swift.decl.typealias,
key.accessibility: source.lang.swift.accessibility.private,
key.name: "privAlias",
key.offset: 1698,
key.length: 25,
key.nameoffset: 1708,
key.namelength: 9
},
{
key.kind: source.lang.swift.decl.typealias,
key.accessibility: source.lang.swift.accessibility.internal,
key.name: "intAlias",
key.offset: 1733,
key.length: 24,
key.nameoffset: 1743,
key.namelength: 8
}
]
}
36 changes: 36 additions & 0 deletions test/SourceKit/InterfaceGen/gen_clang_module.swift.response
Original file line number Diff line number Diff line change
Expand Up @@ -4632,6 +4632,15 @@ public class FooOverlayClassDerived : Foo.FooOverlayClassBase {
}
]
},
{
key.kind: source.lang.swift.decl.typealias,
key.accessibility: source.lang.swift.accessibility.public,
key.name: "FooStruct1Pointer",
key.offset: 1543,
key.length: 62,
key.nameoffset: 1553,
key.namelength: 17
},
{
key.kind: source.lang.swift.decl.struct,
key.accessibility: source.lang.swift.accessibility.public,
Expand Down Expand Up @@ -4705,6 +4714,15 @@ public class FooOverlayClassDerived : Foo.FooOverlayClassBase {
}
]
},
{
key.kind: source.lang.swift.decl.typealias,
key.accessibility: source.lang.swift.accessibility.public,
key.name: "FooStructTypedef1",
key.offset: 1751,
key.length: 40,
key.nameoffset: 1761,
key.namelength: 17
},
{
key.kind: source.lang.swift.decl.struct,
key.accessibility: source.lang.swift.accessibility.public,
Expand Down Expand Up @@ -4778,6 +4796,15 @@ public class FooOverlayClassDerived : Foo.FooOverlayClassBase {
}
]
},
{
key.kind: source.lang.swift.decl.typealias,
key.accessibility: source.lang.swift.accessibility.public,
key.name: "FooTypedef1",
key.offset: 1974,
key.length: 29,
key.nameoffset: 1984,
key.namelength: 11
},
{
key.kind: source.lang.swift.decl.var.global,
key.accessibility: source.lang.swift.accessibility.public,
Expand Down Expand Up @@ -5348,6 +5375,15 @@ public class FooOverlayClassDerived : Foo.FooOverlayClassBase {
}
]
},
{
key.kind: source.lang.swift.decl.typealias,
key.accessibility: source.lang.swift.accessibility.public,
key.name: "typedef_int_t",
key.offset: 4624,
key.length: 31,
key.nameoffset: 4634,
key.namelength: 13
},
{
key.kind: source.lang.swift.decl.var.global,
key.accessibility: source.lang.swift.accessibility.public,
Expand Down
2 changes: 2 additions & 0 deletions tools/SourceKit/lib/SwiftLang/SwiftLangSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ UIdent SwiftLangSupport::getUIDForSyntaxStructureKind(
return KindDeclEnumCase;
case SyntaxStructureKind::EnumElement:
return KindDeclEnumElement;
case SyntaxStructureKind::TypeAlias:
return KindDeclTypeAlias;
case SyntaxStructureKind::Parameter:
return KindDeclVarParam;
case SyntaxStructureKind::ForEachStatement:
Expand Down
1 change: 1 addition & 0 deletions tools/swift-ide-test/swift-ide-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,7 @@ class StructureAnnotator : public ide::SyntaxModelWalker {
case SyntaxStructureKind::ClassVariable: return "cvar";
case SyntaxStructureKind::EnumCase: return "enum-case";
case SyntaxStructureKind::EnumElement: return "enum-elem";
case SyntaxStructureKind::TypeAlias: return "typealias";
case SyntaxStructureKind::Parameter: return "param";
case SyntaxStructureKind::ForEachStatement: return "foreach";
case SyntaxStructureKind::ForStatement: return "for";
Expand Down