File tree Expand file tree Collapse file tree 5 files changed +42
-2
lines changed Expand file tree Collapse file tree 5 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,7 @@ enum class SyntaxStructureKind : uint8_t {
93
93
EnumCase,
94
94
EnumElement,
95
95
TypeAlias,
96
+ Subscript,
96
97
97
98
ForEachStatement,
98
99
ForStatement,
@@ -139,13 +140,14 @@ struct SyntaxStructureNode {
139
140
std::vector<CharSourceRange> InheritedTypeRanges;
140
141
std::vector<SyntaxStructureElement> Elements;
141
142
142
- bool isVariable () const {
143
+ bool hasSubstructure () const {
143
144
switch (Kind) {
144
145
case SyntaxStructureKind::GlobalVariable:
145
146
case SyntaxStructureKind::InstanceVariable:
146
147
case SyntaxStructureKind::StaticVariable:
147
148
case SyntaxStructureKind::ClassVariable:
148
149
case SyntaxStructureKind::Parameter:
150
+ case SyntaxStructureKind::Subscript:
149
151
return true ;
150
152
default :
151
153
return false ;
Original file line number Diff line number Diff line change @@ -964,6 +964,16 @@ bool ModelASTWalker::walkToDeclPre(Decl *D) {
964
964
TypeAliasD->getName ().getLength ());
965
965
SN.Attrs = TypeAliasD->getAttrs ();
966
966
pushStructureNode (SN, TypeAliasD);
967
+ } else if (auto *SubscriptD = dyn_cast<SubscriptDecl>(D)) {
968
+ SyntaxStructureNode SN;
969
+ SN.Dcl = SubscriptD;
970
+ SN.Kind = SyntaxStructureKind::Subscript;
971
+ SN.Range = charSourceRangeFromSourceRange (SM,
972
+ SubscriptD->getSourceRange ());
973
+ SN.BodyRange = innerCharSourceRangeFromSourceRange (SM,
974
+ SubscriptD->getBracesRange ());
975
+ SN.Attrs = SubscriptD->getAttrs ();
976
+ pushStructureNode (SN, SubscriptD);
967
977
}
968
978
969
979
return true ;
@@ -1253,7 +1263,7 @@ bool ModelASTWalker::popStructureNode() {
1253
1263
1254
1264
// VarDecls are popped before we see their TypeRepr, so if we pass the token
1255
1265
// nodes now they will not change from identifier to a type-identifier.
1256
- if (!Node.isVariable ()) {
1266
+ if (!Node.hasSubstructure ()) {
1257
1267
if (!passTokenNodesUntil (Node.Range .getEnd (), IncludeNodeAtLocation))
1258
1268
return false ;
1259
1269
}
Original file line number Diff line number Diff line change @@ -187,3 +187,28 @@ class A {
187
187
188
188
// CHECK: <typealias>typealias <name>OtherA</name> = A</typealias>
189
189
typealias OtherA = A
190
+
191
+ class SubscriptTest {
192
+ subscript ( index: Int) - > Int {
193
+ return 0
194
+ }
195
+ // CHECK: <subscript>subscript(<param>index: Int</param>) -> Int {
196
+ // CHECK: return 0
197
+ // CHECK: }</subscript>
198
+
199
+ subscript ( string: String) - > Int {
200
+ get {
201
+ return 0
202
+ }
203
+ set ( value) {
204
+ print ( value)
205
+ }
206
+ }
207
+ // CHECK: <subscript>subscript(<param>string: String</param>) -> Int {
208
+ // CHECK: get {
209
+ // CHECK: return 0
210
+ // CHECK: }
211
+ // CHECK: set(<param>value</param>) {
212
+ // CHECK: <call><name>print</name>(value)</call>
213
+ // CHECK: }</subscript>
214
+ }
Original file line number Diff line number Diff line change @@ -377,6 +377,8 @@ UIdent SwiftLangSupport::getUIDForSyntaxStructureKind(
377
377
return KindDeclEnumElement;
378
378
case SyntaxStructureKind::TypeAlias:
379
379
return KindDeclTypeAlias;
380
+ case SyntaxStructureKind::Subscript:
381
+ return KindDeclSubscript;
380
382
case SyntaxStructureKind::Parameter:
381
383
return KindDeclVarParam;
382
384
case SyntaxStructureKind::ForEachStatement:
Original file line number Diff line number Diff line change @@ -1070,6 +1070,7 @@ class StructureAnnotator : public ide::SyntaxModelWalker {
1070
1070
case SyntaxStructureKind::EnumCase: return " enum-case" ;
1071
1071
case SyntaxStructureKind::EnumElement: return " enum-elem" ;
1072
1072
case SyntaxStructureKind::TypeAlias: return " typealias" ;
1073
+ case SyntaxStructureKind::Subscript: return " subscript" ;
1073
1074
case SyntaxStructureKind::Parameter: return " param" ;
1074
1075
case SyntaxStructureKind::ForEachStatement: return " foreach" ;
1075
1076
case SyntaxStructureKind::ForStatement: return " for" ;
You can’t perform that action at this time.
0 commit comments